dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.23k stars 1.57k forks source link

[Analyzer] Missing type information for record members in Intellij #55730

Open julemand101 opened 5 months ago

julemand101 commented 5 months ago

I am not entirely sure if this issue are for Intellij or Dart Analyzer since the core issue seems to be a question about API protocol usage. But let's start here and I will move the question in case it is actually a matter for JetBrains.

Problem description

When using Intellij, we are missing type information when doing auto-completion on record members as seen in the following screenshot:

If we instead uses VSCode we can see it does provide type information about the two members of the record:

Theory of root cause

When looking at the Analysis Server API and looking at the traffic going on between Intellij and Analysis serve, I can see a difference between normal members and then record members.

If I try auto-complete a local int variable, I get something like:

      {
        "kind": "IDENTIFIER",
        "relevance": 569,
        "completion": "cow",
        "selectionOffset": 3,
        "selectionLength": 0,
        "isDeprecated": false,
        "isPotential": false,
        "element": {
          "kind": "LOCAL_VARIABLE",
          "name": "cow",
          "location": {
            "file": "C:\\examples\\bin\\example3.dart",
            "offset": 21,
            "length": 3,
            "startLine": 2,
            "startColumn": 7,
            "endLine": 2,
            "endColumn": 10
          },
          "flags": 0,
          "returnType": "int"
        },
        "returnType": "int"
      },

While if I try autocomplete against the record, the result are quite more simple:

      {
        "kind": "IDENTIFIER",
        "relevance": 500,
        "completion": "name",
        "selectionOffset": 4,
        "selectionLength": 0,
        "isDeprecated": false,
        "isPotential": false,
        "returnType": "String"
      },
      {
        "kind": "IDENTIFIER",
        "relevance": 500,
        "completion": "number",
        "selectionOffset": 6,
        "selectionLength": 0,
        "isDeprecated": false,
        "isPotential": false,
        "returnType": "int"
      },

I have looked at the Intellij plugin code and can't see any reference to actually usage of the returnType value on CompletionSuggestion (which are the overall type of these completions) but they do refer to returnType on the Element (which are the type of the element member on the local variable example).

I think Intellij never have considered the returnType on CompletionSuggestion for some reason but the VSCode plugin does look at this value (not checked their implementation).

Question here are then if the CompletionSuggestion for record members should contain an Element value, or should Intellij start making use of the returnType field on CompletionSuggestion.

Version information

Tested both with:

Intellij Dart plugin version: 241.15989.9

scheglov commented 5 months ago

@jwren