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

Suggest: auto-import often not working #109439

Closed
bpasero opened this issue Oct 27, 2020 · 12 comments
Closed

Suggest: auto-import often not working #109439

bpasero opened this issue Oct 27, 2020 · 12 comments
Assignees
Labels
author-verification-requested Issues potentially verifiable by issue author bug Issue identified by VS Code Team member as probable bug papercut 🩸 A particularly annoying issue impacting someone on the team typescript Typescript support issues verified Verification succeeded web Issues related to running VSCode in the web
Milestone

Comments

@bpasero
Copy link
Member

bpasero commented Oct 27, 2020

I very often have to manually import a type because suggest was not fast enough to do the auto import. I feel this happens more for me in web than in desktop:

recording (1)

I am always picking the suggestion fast enough that I end up just with the word but not the auto import.

@bpasero bpasero added typescript Typescript support issues web Issues related to running VSCode in the web labels Oct 27, 2020
@bpasero
Copy link
Member Author

bpasero commented Oct 27, 2020

Slightly related: I often see something similar when I invoke quick fix on a missing type. At first I get no help and then trying again I get the advice to add the import.

@mjbvz mjbvz added the bug Issue identified by VS Code Team member as probable bug label Nov 3, 2020
@bpasero bpasero added the papercut 🩸 A particularly annoying issue impacting someone on the team label Jan 29, 2021
@mjbvz mjbvz added this to the February 2021 milestone Feb 2, 2021
@mjbvz
Copy link
Collaborator

mjbvz commented Feb 2, 2021

@jrieken The root cause of this issue is that resolveCompletionItem may not complete before VS Code applies the completion. We've discussed this in the past but here are some of the issues I ran into while working around this item:

  • It is difficult to tell whether VS Code has applied the full completion item or not.

    If VS Code has fully resolved the completion, the provider does not need to do anything. However there are cases like the one Ben was hitting where VS Code applies a completion before it has been fully resolved. In those cases, need to do extra work to manually apply the rest of the completion once it resolves.

    However I cannot simply to see if resolveCompletionItem has been called since VS Code may accept the completion and apply it before resolveCompletionItem returns. You also cannot check at the end of resolveCompletionItem, because VS Code may apply the completion before the results get back to the main thread.

  • resolveCompletionItem is canceled in cases where the suggestion is accepted but resolve has not completed.

    This makes sense, but it meant that I had to use my own cancellation token when making the request to TypeScript. I need to do because the following can happen:

    1. start resolveCompletionItem()
    2. resolveCompletionItem awaits TS server
    3. The completion is accepted and resolveCompletionItem is canceled (along with the call to TS Server)
    4. But to make sure we properly apply the completion, I have custom TS completion items that apply additional edits for auto imports in a command. This command needs the results of the call to the TypeScript server from resolveCompletionItem to apply auto import.

    My workaround was to implement a custom cancellation token source that counts the number of callers who may need the response from TS server (it also uses a short timeout before actually cancelling the request).

I think my solution works, but it's quite ugly. Ideally TypeScript could eagerly returns all of the information we need to implement auto-imports, although they had concerns about how long that would take to compute and send over

@jrieken
Copy link
Member

jrieken commented Feb 2, 2021

The completion is accepted and resolveCompletionItem is canceled (along with the call to TS Server)

This is arguably a bug. We shouldn't do that when we have explicitly called resolve during insert.

It is difficult to tell whether VS Code has applied the full completion item or not.

I am not quite sure why you need to know that. There should be an editor guarantee that resolve is only called once and the provider should resolve the item independent of the editor state. Tho, that's the ideal view but IDK how the reality of a provider is. What am I missing?

plainerman pushed a commit to plainerman/vscode that referenced this issue Feb 2, 2021
…e completion before it has been resolved

Fixes microsoft#109439

This introduces a new `ApplyCompletionCommand` that is included on all JS/TS completions, which  applies additional parts of the completion (such as auto imports).

This is needed since VS Code will not always wait until `resolveCompletionItem` completes before appling the completion. This causes auto imports to sometimes not work when typing quickly
MarcoZehe pushed a commit to MarcoZehe/vscode that referenced this issue Feb 3, 2021
…e completion before it has been resolved

Fixes microsoft#109439

This introduces a new `ApplyCompletionCommand` that is included on all JS/TS completions, which  applies additional parts of the completion (such as auto imports).

This is needed since VS Code will not always wait until `resolveCompletionItem` completes before appling the completion. This causes auto imports to sometimes not work when typing quickly
@bpasero bpasero reopened this Feb 23, 2021
@bpasero
Copy link
Member Author

bpasero commented Feb 23, 2021

Still unpleasant in web selfhost, I type and even though I get the auto import suggested, doing quick fix does not work until I press it 3 times:

recording

@bpasero bpasero added the verification-found Issue verification failed label Feb 23, 2021
@mjbvz mjbvz modified the milestones: February 2021, March 2021 Feb 25, 2021
@mjbvz
Copy link
Collaborator

mjbvz commented Feb 26, 2021

@bpasero Looks like you are using the add missing import quick fix after typing out toDisposable. If you accept the suggestion instead, do you see auto imports working?

@mjbvz
Copy link
Collaborator

mjbvz commented Feb 26, 2021

I'd prefer splitting any problem with quick fixes to their own issue as they are a separate feature

@bpasero
Copy link
Member Author

bpasero commented Feb 26, 2021

Yes I press Cmd+. and need to do that multiple times until I get a suggestion. I would rather delay it until we can show a fix.

@mjbvz
Copy link
Collaborator

mjbvz commented Feb 27, 2021

Ok, I've extracted the quick fix issue to #117812.

Let's track auto imports suggestions in this issue. I believe auto import suggestion should be much more reliable now so please let me know if there are cases where you still see this

@mjbvz mjbvz closed this as completed Feb 27, 2021
@olegKusov
Copy link

olegKusov commented Mar 9, 2021

I'm having same issue . Big Sur. Vs code Version: 1.54.1. I can wait 5 minutes and it doesnt work.

2021-03-09.17.00.24.mov

@mjbvz
Copy link
Collaborator

mjbvz commented Mar 9, 2021

@olegKusov Please open a separate issue with an example project that demonstrates the problem

@connor4312 connor4312 added the author-verification-requested Issues potentially verifiable by issue author label Mar 26, 2021
@rzhao271 rzhao271 removed verification-found Issue verification failed author-verification-requested Issues potentially verifiable by issue author labels Mar 29, 2021
@mjbvz mjbvz added the author-verification-requested Issues potentially verifiable by issue author label Mar 29, 2021
@bpasero bpasero added the verified Verification succeeded label Mar 30, 2021
@soanvig
Copy link

soanvig commented Apr 12, 2021

For Typescript I have similar issue, which happens completely random. Restarting VSC fixes behavior. Somehow it fixes itself

  1. If the issue occurs it cannot go away.
  2. Moreover, the import path is detected, but still it doesn't work.
  3. This is somehow related to the place in code, where I want to auto-import, as seen in gif below (no import works for some reason)

issue

I've scanned through logs and found this in Log (Remote Extension Host), and it occured almost at the same moment I tried to auto-import. Log was anonymized

[2021-04-12 13:14:41.808] [exthost] [error] [vscode.typescript-language-features] provider FAILED
[2021-04-12 13:14:41.808] [exthost] [error] Error: <semantic> TypeScript Server Error (3.9.2)
Debug Failure. False expression.
Error: Debug Failure. False expression.
    at Object.first (path-to-project/node_modules/typescript/lib/tsserver.js:1023:18)
    at Object.getImportCompletionAction (path-to-project/node_modules/typescript/lib/tsserver.js:129669:38)
    at getCompletionEntryCodeActionsAndSourceDisplay (path-to-project/node_modules/typescript/lib/tsserver.js:112507:33)
    at Object.getCompletionEntryDetails (path-to-project/node_modules/typescript/lib/tsserver.js:112471:30)
    at Proxy.getCompletionEntryDetails (path-to-project/node_modules/typescript/lib/tsserver.js:138863:35)
    at Proxy.<anonymous> (path-to-users-home/.vscode-server/extensions/jpoissonnier.vscode-styled-components-1.5.0/node_modules/typescript-template-language-service-decorator/lib/template-language-service-decorator.js:96:24)
    at path-to-project/node_modules/typescript/lib/tsserver.js:148965:57
    at Object.mapDefined (path-to-project/node_modules/typescript/lib/tsserver.js:562:30)
    at IOSession.Session.getCompletionEntryDetails (path-to-project/node_modules/typescript/lib/tsserver.js:148963:33)
    at Session.handlers.ts.createMapFromTemplate._a.<computed> (path-to-project/node_modules/typescript/lib/tsserver.js:147881:61)
    at path-to-project/node_modules/typescript/lib/tsserver.js:149512:88
    at IOSession.Session.executeWithRequestId (path-to-project/node_modules/typescript/lib/tsserver.js:149503:28)
    at IOSession.Session.executeCommand (path-to-project/node_modules/typescript/lib/tsserver.js:149512:33)
    at IOSession.Session.onMessage (path-to-project/node_modules/typescript/lib/tsserver.js:149536:35)
    at Interface.<anonymous> (path-to-project/node_modules/typescript/lib/tsserver.js:150852:27)
    at Interface.emit (events.js:315:20)
    at Interface._onLine (readline.js:329:10)
    at Interface._normalWrite (readline.js:474:12)
    at Socket.ondata (readline.js:186:10)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:186:23)
	at Function.create (path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/extensions/typescript-language-features/dist/extension.js:1:70073)
	at dispatchResponse (path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/extensions/typescript-language-features/dist/extension.js:1:63948)
	at dispatchMessage (path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/extensions/typescript-language-features/dist/extension.js:1:62807)
	at path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/extensions/typescript-language-features/dist/extension.js:1:62317
	at b.fire (path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/out/vs/server/remoteExtensionHostProcess.js:57:1836)
	at g.onLengthData (path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/extensions/typescript-language-features/dist/extension.js:1:431280)
	at Socket.<anonymous> (path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/extensions/typescript-language-features/dist/extension.js:1:430928)
	at Socket.emit (events.js:315:20)
	at addChunk (_stream_readable.js:295:12)
	at readableAddChunk (_stream_readable.js:271:9)
	at Socket.Readable.push (_stream_readable.js:212:10)
	at Pipe.onStreamRead (internal/stream_base_commons.js:186:23)
[2021-04-12 13:14:42.130] [exthost] [error] Error: <semantic> TypeScript Server Error (3.9.2)
Debug Failure. False expression.
Error: Debug Failure. False expression.
    at Object.first (path-to-project/node_modules/typescript/lib/tsserver.js:1023:18)
    at Object.getImportCompletionAction (path-to-project/node_modules/typescript/lib/tsserver.js:129669:38)
    at getCompletionEntryCodeActionsAndSourceDisplay (path-to-project/node_modules/typescript/lib/tsserver.js:112507:33)
    at Object.getCompletionEntryDetails (path-to-project/node_modules/typescript/lib/tsserver.js:112471:30)
    at Proxy.getCompletionEntryDetails (path-to-project/node_modules/typescript/lib/tsserver.js:138863:35)
    at Proxy.<anonymous> (path-to-users-home/.vscode-server/extensions/jpoissonnier.vscode-styled-components-1.5.0/node_modules/typescript-template-language-service-decorator/lib/template-language-service-decorator.js:96:24)
    at path-to-project/node_modules/typescript/lib/tsserver.js:148965:57
    at Object.mapDefined (path-to-project/node_modules/typescript/lib/tsserver.js:562:30)
    at IOSession.Session.getCompletionEntryDetails (path-to-project/node_modules/typescript/lib/tsserver.js:148963:33)
    at Session.handlers.ts.createMapFromTemplate._a.<computed> (path-to-project/node_modules/typescript/lib/tsserver.js:147881:61)
    at path-to-project/node_modules/typescript/lib/tsserver.js:149512:88
    at IOSession.Session.executeWithRequestId (path-to-project/node_modules/typescript/lib/tsserver.js:149503:28)
    at IOSession.Session.executeCommand (path-to-project/node_modules/typescript/lib/tsserver.js:149512:33)
    at IOSession.Session.onMessage (path-to-project/node_modules/typescript/lib/tsserver.js:149536:35)
    at Interface.<anonymous> (path-to-project/node_modules/typescript/lib/tsserver.js:150852:27)
    at Interface.emit (events.js:315:20)
    at Interface._onLine (readline.js:329:10)
    at Interface._normalWrite (readline.js:474:12)
    at Socket.ondata (readline.js:186:10)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:186:23)
	at Function.create (path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/extensions/typescript-language-features/dist/extension.js:1:70073)
	at dispatchResponse (path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/extensions/typescript-language-features/dist/extension.js:1:63948)
	at dispatchMessage (path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/extensions/typescript-language-features/dist/extension.js:1:62807)
	at path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/extensions/typescript-language-features/dist/extension.js:1:62317
	at b.fire (path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/out/vs/server/remoteExtensionHostProcess.js:57:1836)
	at g.onLengthData (path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/extensions/typescript-language-features/dist/extension.js:1:431280)
	at Socket.<anonymous> (path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/extensions/typescript-language-features/dist/extension.js:1:430928)
	at Socket.emit (events.js:315:20)
	at addChunk (_stream_readable.js:295:12)
	at readableAddChunk (_stream_readable.js:271:9)
	at Socket.Readable.push (_stream_readable.js:212:10)
	at Pipe.onStreamRead (internal/stream_base_commons.js:186:23) _typescript.applyCompletionCommand
[2021-04-12 13:14:42.130] [exthost] [error] Error: Running the contributed command: '_typescript.applyCompletionCommand' failed.
	at S._executeContributedCommand (path-to-users-home/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/out/vs/server/remoteExtensionHostProcess.js:86:106930)
	at runMicrotasks (<anonymous>)
	at processTicksAndRejections (internal/process/task_queues.js:97:5) _typescript.applyCompletionCommand

I noticed something important: for whatever reason in path-to-project I had path to another project in workspace. I worked in projectA, and tried to import there, yet got this errors with path to projectB

@microsoft microsoft locked as resolved and limited conversation to collaborators Apr 12, 2021
@mjbvz
Copy link
Collaborator

mjbvz commented Apr 12, 2021

@soanvig Please don't post on generic, already resolved issues

You are using an old TS version so first check if you see this using TS 4.2+. If you do, open a new issue with a project that demonstrates the problem

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
author-verification-requested Issues potentially verifiable by issue author bug Issue identified by VS Code Team member as probable bug papercut 🩸 A particularly annoying issue impacting someone on the team typescript Typescript support issues verified Verification succeeded web Issues related to running VSCode in the web
Projects
None yet
Development

No branches or pull requests

8 participants
@bpasero @jrieken @connor4312 @rzhao271 @soanvig @mjbvz @olegKusov and others