Skip to content

Conversation

@gabritto
Copy link
Member

Partially fixes #46568.

Whenever completions offer a method snippet, the parameter names and types, and the return type are snippet placeholders, as described in #46370. And, if the method has a body, there is a tabstop in the empty body.

We are assuming that, in most cases, the person using the method snippet won't want to change the method signature, and will instead just want to fill in the body with the implementation of the method.
For that reason, the tabstop in the body is the first one, so when the method snippet is inserted, the cursor is in the body, like so:

class Bar implements Foo {
    bar(a: string, b: number, c: string, d: number, e: string): void {
        | // cursor starts here
    }
}

This PR adds a second tabstop, namely $0, right next to the first tabstop, in the body of the method. $0 is special, in that it is the last tabstop. This means that the following flow is possible:

class Bar implements Foo {
    bar(a: string, b: number, c: string, d: number, e: string): void {
        | // cursor starts here
    }
}

after pressing tab a few times, navigating through the method signature:

class Bar implements Foo {
    bar(a: string, b: number, c: string|, d: number, e: string): void {
        
    }
}

after pressing tab one last time, after going through (and possibly editing) the parameters and return type:

class Bar implements Foo {
    bar(a: string, b: number, c: |string, d: number, e: string): void {
        | // cursor ends here
    }
}

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Oct 29, 2021
@andrewbranch
Copy link
Member

Looks good—have you tested in VS Code to make sure it works like we expect?

Related: #46588

@gabritto gabritto changed the title Change snippet Change snippet in class member completions Oct 29, 2021
@gabritto
Copy link
Member Author

Looks good—have you tested in VS Code to make sure it works like we expect?

Related: #46588

Yes, I tested it locally. To test this in VSCode, I had to change the code in completions that checks for preferences.includeCompletionsWithClassMemberSnippets to no longer check that.

@andrewbranch
Copy link
Member

Use Insiders 😉

@gabritto
Copy link
Member Author

I guess we can wait until after the 4.5 RC and discuss this and other alternatives in the editor meeting?

@gabritto gabritto closed this Oct 29, 2021
@gabritto
Copy link
Member Author

gabritto commented Oct 29, 2021

It seems we won't need this anymore: #46588

@gabritto gabritto deleted the gabritto/snippetorder branch March 2, 2024 01:45
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Milestone Bug PRs that fix a bug with a specific milestone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Method snippet follow-up

4 participants