microsoft / microsoft/TypeScript

Distinguishing suggestions from global scope from local suggestions

Open
#27,487 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Experience Enhancement Suggestion VS Code Tracked
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

From https://github.com/Microsoft/vscode/issues/59437

Search Terms:

  • TSServer
  • completions
  • suggestions

Code
For the example ts file:

class FooClass {
    toString(): void {
        |
    }
}

Trigger suggestions at the | inside the toString method

Problem
We get back two completions from completionInfo:

     {
            "name": "toString",
            "kind": "function",
            "kindModifiers": "declare",
            "sortText": "0"
        },
        {
            "name": "toString",
            "kind": "method",
            "kindModifiers": "",
            "sortText": "0",
            "insertText": "this.toString"
        },

However when we then make the completionEntryDetails request, we can only pass the identifier name: "toString". This makes it unclear which completion entry we are actually requesting completion details for.

Proposal
completionEntryDetails already has a source field that is used to identify when a suggestion is an auto import. I believe that this field could also be used for global symbols, such as when a symbol name comes from a global lib.d.ts file. In this case, the first toString suggestion comes from a global in dom.d.ts

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the FooClass example to reproduce the duplicate toString completions returned by completionInfo. Read how completionEntryDetails currently uses source for auto imports, then evaluate the proposed global-symbol case from dom.d.ts; done means callers can distinguish the entries and request the matching details.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.