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

Method override completions #45670

Closed
mjbvz opened this issue Sep 1, 2021 · 5 comments Β· Fixed by #46370 or microsoft/vscode#136045
Closed

Method override completions #45670

mjbvz opened this issue Sep 1, 2021 · 5 comments Β· Fixed by #46370 or microsoft/vscode#136045
Assignees
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Experience Enhancement Noncontroversial enhancements Fix Available A PR has been opened for this issue Suggestion An idea for TypeScript

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Sep 1, 2021

Suggestion

πŸ” Search Terms

  • suggest / suggestion
  • IntelliSense
  • Snippet / snippets
  • Tooling
  • VS Code / vscode

⭐ Suggestion

For the code:

abstract class Base {
    abstract foo(param1: string, param2: boolean): Promise<void>;
}

class Sub extends Base {
    
}

I should be able to type f inside the body of Sub and get a suggestion for foo that fills in the entire signature of the method when accepted:

class Sub extends Base {
    foo(param1: string, param2: boolean): Promise<void> {
        | // cursor ends up here
    }
}

Right now, accepting the suggestion for foo only inserts the text foo. I have to fill out the entire body of the method myself, typically by copy and pasting from the base class

@mjbvz
Copy link
Contributor Author

mjbvz commented Sep 1, 2021

We should be able to use VS Code's snippet syntax for this style of completion. I originally proposed snippet style completions in #25207. It sounds like we have already have adopted a subset of VS Code's snippet string syntax

This would need to be an opt-in feature for editors and we would likely need to add a user facing setting to disable these too

@andrewbranch
Copy link
Member

A general question I have about these snippet completions that may insert quite a bit of text is how we want to display them. Xcode has these kinds of method signature completions and it looks like they just truncate, which isn’t too bad:

image

It’s somewhat less clear how #40700 should display, for example, which is another use case I’m interested in exploring.

@andrewbranch andrewbranch added Domain: Completion Lists The issue relates to showing completion lists in an editor Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript labels Sep 1, 2021
@andrewbranch andrewbranch added this to the TypeScript 4.5.0 milestone Sep 1, 2021
@andrewbranch
Copy link
Member

I think we can start by using the full method signature text as the label like Xcode does here and see how we like it. @mjbvz pointed out that the Editor > Suggest: Preview setting is particularly useful for longer snippet completions, and we may want to explore enabling it by default, at least for snippet-text completions.

@ChiriVulpes
Copy link

I've wanted this one for so long and assumed it was already suggested, but didn't know what to search for. I'm surprised it only got added to the tracker last month β€” this would be such a huge usability enhancement for implementing abstract classes! It's honestly one of the only reasons why I sometimes miss working on Java projects 😜

Will this completion automatically propagate visibility modifiers? IE, if the superclass has public/protected, will the completion add the same visibility to the override? Also, will it add the override modifier if the user has the noImplicitOverride flag enabled? Both of those kinds of modifiers being included with these completions would be great.

@gabritto
Copy link
Member

Will this completion automatically propagate visibility modifiers? IE, if the superclass has public/protected, will the completion add the same visibility to the override? Also, will it add the override modifier if the user has the noImplicitOverride flag enabled? Both of those kinds of modifiers being included with these completions would be great.

I've been working on implementing this feature, and the override modifier is going to be added if noImplicitOverride is set (modulo possible bugs, of course πŸ˜…). About visibility modifiers, I think the suggested method should have them too, but I have yet to test that behavior.
Glad to hear feedback about this feature 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Experience Enhancement Noncontroversial enhancements Fix Available A PR has been opened for this issue Suggestion An idea for TypeScript
Projects
None yet
5 participants