Completion details can’t distinguish between a default export and a named export matching the filename #42871
Labels
Bug
A bug in TypeScript
Domain: Completion Lists
The issue relates to showing completion lists in an editor
Fix Available
A PR has been opened for this issue
Milestone
Bug Report
🔎 Search Terms
auto import default
🕗 Version & Regression Information
This has probably been a bug since auto-imports were invented
💻 Code
🙁 Actual behavior
Two auto-import completions, but both details resolve to the named export.
🖼 GIF demonstrating problem
🙂 Expected behavior
Two auto-import completions that correctly differentiate between the named export and the default export.
Discussion
The reason this happens is that the info we have to go on in
getCompletionDetails
is a really poor starting point for trying to figure out what completion entry we’re talking about. All we have is aname
andsource
, wherename
is the identifier text you want to insert with the completion, andsource
is the symbol name of the module. Notable information we don’t have, because we threw it away at the end ofgetCompletionsAtPosition
, includesThrowing all of this away has two main consequences:
source
. Then we loop through every member/property of its exports seeing if the names we come up with there matchname
.name
is not always the actual name from the exports symbol table;default
andexport=
get converted into a valid identifier for the import, which can be the file name (camel-cased). In the example above, the file name substitution for thedefault
gets “shadowed” by the named export.Fixing this is a near-prerequisite for #31658—it gets extra ugly trying to work around this.
Proposal
Add a new opaquely-typed
data
property (named to match the LSPCompletionItem
field that has the same purpose) toprotocol.CompletionEntry
to replacesource
in what gets sent back to TS Server forgetCompletionDetails
. (To transition, editors can continue to sendsource
as well, and TS Server can continue to use it as a fallback for a while.) Then, TypeScript can add whatever properties we need to that new property./cc @mjbvz @uniqueiniquity any concerns about compatibility issues? @DanielRosenwasser will we need to update any other editors?
The text was updated successfully, but these errors were encountered: