Skip to content

Conversation

@jmarolf
Copy link
Contributor

@jmarolf jmarolf commented Oct 24, 2021

@akhera99 and @mikadumont here is a draft of the formal spec. Please call out sections that aren't clear :)

releated to #56541

@ghost ghost added the Area-IDE label Oct 24, 2021

- We should change the commit behavior of these new snippets to only require a single tab to complete
- If the user types `Tab ↹` twice (due to muscle memory) we will eat the second key press (similar to how automatic brace matching works)
- Two undo stacks will be created for each snippet that is commited (`Console.WriteLine()` -> `cw` -> ``)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure this is consistent with IntelliCode Inline Completion. At least validate that theirs also requires at least 2 undo stacks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will leave that to you @mikadumont


|Name |Descriptive Text in Completion List | Valid synonyms |
|-----|------------|----------------------------------|
|`#if` | Create a #if directive and a #endif directive. | directive, pound, hashtag, #if
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure generate and add are also captured in this list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not married to this wording. My only argument in its favor is that is is similar to the docs descriptions here.

- We may do this someday but for now we want to ensure that we can meet customers’ needs for the narrow case
- We are not changing the VB experience for snippets (yet)
- VB has a very different design than C#.
- We are not changing "Surround With" behavior
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we dont want to handle snippets that handles surround with behavior? This needs an update as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Surround With" could be its own spec so I left it out for now :)

I think we have enough work here already that we should re-visit "Surround With" separate from this.

We can still discuss it though to make sure we are on the right page. My assumption is that we would not mess with the VS platforms surround with but instead offer a post-statement option.

So if the user types this if at the end of a statement (after a ; essentially)

FileStream stream = File.OpenRead(@"C:\Users\Public\TestFolder\WriteText.txt");
StreamReader streamReader = new(stream);
string text = streamReader.ReadToEnd();[|if|] // Offered 'surround with if block'

They are offered to surround the current line with one of the block snippets.

FileStream stream = File.OpenRead(@"C:\Users\Public\TestFolder\WriteText.txt");
StreamReader streamReader = new(stream);
if (true) // User is put in a special UI mode (!?) where they can choose to expand the selection
{
    string text = streamReader.ReadToEnd();
}

We would then need to offer some custom UI in the editor to allow the user to select what statements should be included in the block.

We may also want a short/dedicated snippet for placing everything in the current block in the new block so if the developer types this:

void M()
{
    FileStream stream = File.OpenRead(@"C:\Users\Public\TestFolder\WriteText.txt");
    StreamReader streamReader = new(stream);
    string text = streamReader.ReadToEnd();|try|] // Offered 'surround with try/catch statement'
                                                  // and     'surround all with try/catch statement'
}

If the developer chooses 'surround all with try/catch statement' then they get:

void M()
{
    try
    {
        FileStream stream = File.OpenRead(@"C:\Users\Public\TestFolder\WriteText.txt");
        StreamReader streamReader = new(stream);
        string text = streamReader.ReadToEnd();
    }
    catch (Exception)
    {
        throw;
    }
}

Unanswered questions with this design:

  1. How does the user dynamically expand the set of things they want to include in the block?
  2. Should these only be offered at the end of semicolons (;) or are there expression contexts where these should offered?

@jmarolf
Copy link
Contributor Author

jmarolf commented Nov 2, 2021

@CyrusNajmabadi I believe you missed the design meeting where we discussed this but I would appreciate your opinion here

@jmarolf jmarolf merged commit b1b703a into dotnet:feature/semantic-snippets Nov 9, 2021
@jmarolf jmarolf deleted the feature/semantic-snippets branch November 9, 2021 17:38
@jmarolf jmarolf mentioned this pull request Dec 3, 2021
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants