-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Description
Bug Report
Auto imports within vscode suggestions fail if there's an existing valid import path, that doesn't appear to TypeScript's first preference as to where to import from. However, imports do still work via quick actions -> add to existing import declaration.
This appears to be coming from an assertion in the language server rather than from vscode behaviour.
🔎 Search Terms
vscode, auto, import, suggestions,
🕗 Version & Regression Information
- Based on my testing, this changed between versions 4.3.5 and 4.4.2
⏯ Playground Link
Minimal reproduction repository
Linking to a repo instead of playground as it may involve usage of npm dependencies via file urls in package.json, not sure if workbench supports that.
Reproduction steps:
- Clone repro repository
npm install- Open in vs code
- Open src/index.ts
- Place cursor here:
const a = new MyClass|(); - CTRL+Space to bring up auto complete suggestions, enter to accept
- vscode imports MyClass from "../packages/mylib" (as it's a dependency, from "mylib" would probably be better, but this is a separate issue, related to Auto-import prefers parent index.ts which leads to circular reference #45953 maybe?)
- Now place cursor here:
const b = new MyClass2|(); - Do auto complete from suggestion as in step 6
- MyClass2 is added to import - correct
- CTRL+Z to undo the import
- Change import path from "../packages/mylib", to just "mylib" to use as an npm dependency.
- Attempt to import MyClass2 from suggestions again
- No import is added
- If you check extension host output in vscode, there appears to be a failing debug assertion from tsserver - getCompletionEntryCodeActionsAndSourceDisplay. A copy of this error is included in error.log in the repo for convenience.
- Interestingly, if instead of trying to tab complete, you hover over MyClass2, and use the quick actions from the tooltip and pick "Add MyClass2 to existing import declaration from mylib", this does work correctly. Perhaps a different code path?
If you change the version of typescript installed via npm to 4.3.5, reload the vscode window and follow the steps again, this seems to stop reproducing.
💻 Code
Not really applicable as it seems to be related to import functionality from language server.
🙁 Actual behavior
Auto completing while there is an existing an import that isn't TypeScript's first preference for where to import it, fails and nothing is imported.
🙂 Expected behavior
TypeScript should see that the target class can also be imported from the existing import, and add to it.