Skip to content

Method override completions  #45670

Closed
microsoft/vscode
#136045

Description

@mjbvz

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

Activity

  1. mjbvz commented on Sep 1, 2021

    @mjbvz
    Author

    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

  2. andrewbranch commented on Sep 1, 2021

    @andrewbranch
    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.

  3. andrewbranch commented on Sep 1, 2021

    @andrewbranch
    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. Matt Bierner (@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.

  4. ChiriVulpes commented on Oct 11, 2021

    @ChiriVulpes
    Contributor

    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.

  5. gabritto commented on Oct 12, 2021

    @gabritto
    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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions