Skip to content

Support 'go to def' and interacting with inlay hint components #47693

Closed
@mjbvz

Description

@mjbvz

TypeScript Version: 4.6

Search Terms

  • inlay hints
  • provideInlayHints

VS Code recently updated our inlay hints to support tagging ranges within each hint with a location (file + position). This lets us perform operations such as go to definition on individual symbols within an inlay hint

You can see the VS Code side of this API here: https://github.com/microsoft/vscode/blob/516bef8deca4a3dc8544de536eb16d5e88ad8a83/src/vscode-dts/vscode.proposed.inlayHints.d.ts#L40

Proposal

I propose that TS also starts returning symbol locations in its inlay hint response. This would let users hover and click on parts of an inlay hint to interact with it

Here's what the protocol change would look like:

interface InlayHintItem {
     // Today this is just a string
     text: string | readonly InlayHintDisplayPart[]:
  
     ....
}

interface InlayHintDisplayPart {
   // Displayed text in the ui
   text: string;

    // Definition of the symbol. 
    // TODO: Does this need to be an array or do we always have a single primary location we can use?
    span?: FileSpan;
}

As an example, consider the TS:

class A { }
class B { }

declare const Foo: A | [B];

const a = Foo;

With variable type inlay hints enabled, we currently see:

Screen Shot 2022-02-01 at 6 02 10 PM

With the new proposal, we would want to return unique InlayHintDisplayPart elements for A and B. The response would look something like:

[Trace  - 02:03:33.592] <semantic> Response received: provideInlayHints (3969). Request took 2 ms. Success: true 
Result: [
    {
        "text": [
            {
                "text": ": "
            }, {
                "text": "A",
                "span": {
                    "file": "main.ts",
                    "start": { line: 1, column: 1 }, // made up location
                    "end": { line: 1, column: 99 },
                }
            }, {
                "text": " | ["
            }, {
                "text": "B",
                "span": {
                    "file": "main.ts",
                    "start": { line: 2, column: 1 },
                    "end": { line: 2, column: 99 },
                }
            }, {
                "text": "]"
            },
        ],
        "position": {
            "line": 6,
            "offset": 8
        },
        "kind": "Type",
        "whitespaceBefore": true
    }
]

/cc @jrieken

Metadata

Metadata

Assignees

Labels

Domain: Inlay HintsDomain: Symbol NavigationRelates to go-to-definition, find-all-references, highlighting/occurrences.Domain: Type DisplayBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion InfoExperience EnhancementNoncontroversial enhancementsSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions