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

Include both symbol span and whole definition span for tsserver definitions #30849

Closed
mjbvz opened this issue Apr 10, 2019 · 6 comments · Fixed by #31587
Closed

Include both symbol span and whole definition span for tsserver definitions #30849

mjbvz opened this issue Apr 10, 2019 · 6 comments · Fixed by #31587
Assignees
Labels
Domain: TSServer Issues related to the TSServer Experience Enhancement Noncontroversial enhancements Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Apr 10, 2019

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

  • definition
  • definitionandboundspan

Problem
VS Code uses typescript's definition requests to render small previews of a declaration when you hover over a symbol and hold cmd. However because TS currently only returns the symbol span with definitions, we cannot always guess the range to preview correctly (see microsoft/vscode#72017)

For example, for the code:

function foo() {
	// noop
}

foo()

the definitionAndBoundSpan result for the invocation of foo is:

[Trace  - 11:35:52 AM] Sending request: definitionAndBoundSpan (12). Response expected: yes. Current queue length: 0
Arguments: {
    "file": "untitled:^Untitled-1",
    "line": 5,
    "offset": 3
}
[Trace  - 11:35:52 AM] Response received: definitionAndBoundSpan (12). Request took 25 ms. Success: true 
Result: {
    "definitions": [
        {
            "file": "untitled:^Untitled-1",
            "start": {
                "line": 1,
                "offset": 10
            },
            "end": {
                "line": 1,
                "offset": 13
            }
        }
    ],
    "textSpan": {
        "start": {
            "line": 5,
            "offset": 1
        },
        "end": {
            "line": 5,
            "offset": 4
        }
    }
}

To make our UI more reliable, we need both the symbol span (covering just foo in the line function foo() {) as well as entire declaration span (covering all of the function declaration)

Proposed api
Keep the existing behavior of definitionAndBoundSpan, but tack on additional definition start/end information to each returned span:

    interface DefinitionInfoAndBoundSpan {
        definitions: ReadonlyArray<FileSpan & { definitionStart?: Location, definitionEnd?: Location }>;
        textSpan: TextSpan;
    }

This should be a backwards compatible change

Related Issues:

@mjbvz mjbvz changed the title Include both symbol span and whole span for tsserver definitions Include both symbol span and whole definition span for tsserver definitions Apr 10, 2019
@DanielRosenwasser
Copy link
Member

Which one is which in this API? Does the original FileSpan stay the same?

@mjbvz
Copy link
Contributor Author

mjbvz commented Apr 10, 2019

Yes, the existing FileSpan data would remain unchanced and track the symbol range. The added definitionStart and definitionEnd properties would track the range of the whole definition

@RyanCavanaugh RyanCavanaugh added the Domain: TSServer Issues related to the TSServer label Apr 10, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.5.0 milestone Apr 10, 2019
@RyanCavanaugh RyanCavanaugh added Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript labels Apr 10, 2019
@sheetalkamat
Copy link
Member

@mjbvz Does this mean we need to add this to everything related to defintions.
Eg.

Definition = "definition",
        /* @internal */
        DefinitionFull = "definition-full",
        DefinitionAndBoundSpan = "definitionAndBoundSpan",
        /* @internal */
        DefinitionAndBoundSpanFull = "definitionAndBoundSpan-full",
        Implementation = "implementation",
        /* @internal */
        ImplementationFull = "implementation-full",
       TypeDefinition = "typeDefinition",
        References = "references",
        /* @internal */
        ReferencesFull = "references-full",

@mjbvz
Copy link
Contributor Author

mjbvz commented May 23, 2019

Ideally yes. I believe that VS Code can use this information in our UI for implementations and type definitions as well.

The definition one is the most important to us since it is the most noticeable in the UI

@sheetalkamat
Copy link
Member

@mjbvz Few more question.
Do we want this only for funciton or any declaration name?
Do we want to call this contextSpan instead of definitionSpan?
Eg. for import { x as B } from "a" I think the whole declaration makes sense rather than sending you span for complete import declaration rather than just the span for x as B.

sheetalkamat added a commit that referenced this issue May 24, 2019
@mjbvz
Copy link
Contributor Author

mjbvz commented May 24, 2019

  1. Yes, we would like this for all declarations including: variables, classes, and interfaces.
  2. I agree that definitionSpan may not be the clearest name. I find contextSpan is a little vague too but would be fine with that. Maybe declarationSpan?

Your proposal about the handling of the import also makes sense to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: TSServer Issues related to the TSServer Experience Enhancement Noncontroversial enhancements Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
4 participants