Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change snippet in class member completions #46593

Closed
wants to merge 1 commit into from

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
3 participants