Sdk: Code completion includes extension methods from other types

Created on 10 Jan 2020  路  4Comments  路  Source: dart-lang/sdk

Raised by @BendixMa at https://github.com/Dart-Code/Dart-Code/issues/2208. I can repro this on v2.8.0-dev, it seems like a server issue.


Hey,

when I declare a dart extension like so:

extension StringExtensions on String {
  bool get definitelyNotAnInt => false;

  void dontShowThisFunctionOnAnInt() {}
}

and use it subsequently in code like so:

main(List<String> args) {
  int integer = 0;
  integer. // and let vs-code show autocompletions here
}

then the suggestion list will include the extensions declared on the String class as shown below.

dart-code-issue

Especially when you have multiple extensions declared on multiple types than this will quickly make autocompletion almost useless as there are so many unrelated suggestions and you cannot find the functions/fields in the list that the class actually defines.

analyzer-completion area-analyzer type-bug

Most helpful comment

All 4 comments

@bwilkerson the unwanted methods come back in the completion results:

{
    "event": "completion.results",
    "params": {
        "id": "2",
        "replacementOffset": 178,
        "replacementLength": 0,
        "results": [
            {
                "kind": "INVOCATION",
                "relevance": 1000,
                "completion": "dontShowThisFunctionOnAnInt",
                "selectionOffset": 27,
                "selectionLength": 0,
                "isDeprecated": false,
                "isPotential": false,
                // ...
                "returnType": "void",
                "parameterNames": [],
                "parameterTypes": [],
                "requiredParameterCount": 0,
                "hasNamedParameters": false
            },
            {
                "kind": "INVOCATION",
                "relevance": 1000,
                "completion": "definitelyNotAnInt",
                "selectionOffset": 18,
                "selectionLength": 0,
                "isDeprecated": false,
                "isPotential": false,
                // ...
                "returnType": "bool"
            },
            // ...

@pq @jwren

Thanks for the quick fix!

Was this page helpful?
0 / 5 - 0 ratings