Vscode: Typescript no longer auto importing suggestions

Created on 13 Nov 2018  路  20Comments  路  Source: microsoft/vscode

When picking a suggestion from another module, TS no longer auto imports that suggestion. I have to trigger suggest once again, accept the only change and then it gets imported.

peek 2018-11-13 11-05

bug javascript suggest verified

Most helpful comment

Can confirm this behavior. I never get auto import suggestions anymore unless I trigger the auto-complete hints a second time.

All 20 comments

Can you please check the TypeScript Server trace:

  1. Set "typescript.tsserver.trace": "verbose"
  2. Reproduce the problem
  3. Open the output panel and view the TypeScript section

Are there any errors or stack traces printed near the end?

Had the same problem, even with cases where autoimport completely died for me for the whole project. (have mapped alias paths)

Reverting to typescript 3.0.3 solved my issue for now.

Can confirm this behavior. I never get auto import suggestions anymore unless I trigger the auto-complete hints a second time.

I too need to trigger the intellisense twice, in order to see the import path in the hint, and then trigger the auto-import.

Code 1.29 & Code-insiders 1.30

Same here, I have to trigger it two or three times in order for the auto-import to show up. This is on Typescript 3.2.0-rc

With vscode 1.29.1
TS 3.0.3 works

OR

  • sudo npm install -g [email protected] to install globally for all projects, and then add this in your vscode settings "typescript.tsdk": "/usr/local/lib/node_modules/typescript/lib/".

Same here

There are two cases to try for this:

  1. Type quickly to trigger suggest but do not hit enter. In this case, the suggest list item does not contain any details (indicating that auto imports have not been resolved properly). Scrolling through the list or waiting does not help; the details are never resolved

  2. Type quickly to trigger suggest and then press enter quickly. Auto imports are also not resolved here.

@jrieken The root cause seems to be our internal handling of cancelation while resolving completion items. The sequence of events:

  • Trigger suggest
  • The suggestWidget starts trying to resolve a suggestion item in a promise. We cache the promise value here.
  • Before this can complete, type some more but make sure that the same suggestion item will still be active. This cancels the ongoing resolution.
  • We then try to resolve the same suggestion item again. This just gets the cached promise result so we never properly resolve the suggestion item

There are a few potential things that need fixing:

@jrieken I submitted a PR that fixes case 1: https://github.com/Microsoft/vscode/pull/64093

Case 2 is still broken. I think we need to make sure that the completion item is resolved when we call _onDidSelectItem in SuggestController

Is there a workaround for this? It's killing productivity

Is there a workaround for this? It's killing productivity

Can't use TS 3.2.1 now cause of this, sticking to 3.0.3.

----------------- 6/12/2018
Testing the latest insiders build with (builtin) TS 3.2.1 - Windows 10.
No extensions, fresh install, still broken (no autoimport suggestion):
no-autoimport-suggestion

Is there a workaround for this? It's killing productivity

Can't use TS 3.2.1 now cause of this, sticking to 3.0.3.

Sweet that worked. Thanks k-knyazev.

Case 2 is still broken. I think we need to make sure that the completion item is resolved when we call _onDidSelectItem in SuggestController

Thanks. I will push a change that ensures we always that we always call resolve. This will help all different insertions, like insert on trigger character.

We should just continue on with the current resolution. The cancellation that seems to cause this is [...]

The problem is that resolving details also updates the UI and that pending, but outdated, detail-calls would reveal the wrong items. See https://github.com/Microsoft/vscode/issues/60753 for more details.

@mjbvz I merged the PR and I made a tweak on top of it - the IPC layer might reject a promise with a cancellation error if it's canceled before dispatched.

What wonders me is why this only happens with certain version of TypeScript? Was the extra edit not a detail before or what has changed so that these issues are now exposed?

Thanks @jrieken! I believe this started happening after the resolve call in the TS extension went from being a single async operation to two. Previously, if cancellation occurred after the single operation had been dispatched but before resolve returned, we'd still return the fully resolved completion item. After the change in TS, on cancellation we bail early and return the unresolved completion item.

Closing this as the causes of this specific issue have been addressed

I am also having this issue.

VS Code details:

Version: 1.29.1 (user setup)
Commit: bc24f98b5f70467bc689abf41cc5550ca637088e
Date: 2018-11-15T19:13:36.375Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

Due to legacy code reasons, I am stuck on TypeScript 2.5.3

Any idea when this fix will be available?

Thanks @jrieken! I believe this started happening after the resolve call in the TS extension went from being a single async operation to two. Previously, if cancellation occurred after the single operation had been dispatched but before resolve returned, we'd still return the fully resolved completion item. After the change in TS, on cancellation we bail early and return the unresolved completion item.

Closing this as the causes of this specific issue have been addressed

"allowSyntheticDefaultImports: true" breaks auto import, the module resolution is not returned but the suggestion is.
Finally tracked the cause of this in my particular case.

Issue do not exist in TS 3.0.3 and still present even until TS@next. Must I open a new issue? Is this TS problem more than vscode?

@k-knyazev Yes please open a new issue

Was this page helpful?
0 / 5 - 0 ratings