Skip to content

Suggest: auto-import often not working #109439

Closed

Description

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.

Activity

  1. added
    typescript
    web
    on Oct 27, 2020
  2. bpasero commented on Oct 27, 2020

    @bpasero
    ContributorAuthor

    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.

  3. added
    bug
    on Nov 3, 2020
  4. added
    papercut 🩸
    on Jan 29, 2021
  5. mjbvz commented on Feb 2, 2021

    @mjbvz
    Contributor

    Johannes Rieken (@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

  6. added
    unreleased
    on Feb 2, 2021
  7. jrieken commented on Feb 2, 2021

    @jrieken
    Contributor

    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?

  8. added a commit that references this issue on Feb 2, 2021
    30a6960
  9. added
    insiders-released
    and removed
    unreleased
    on Feb 5, 2021
  10. 5 remaining items

  11. mjbvz commented on Feb 26, 2021

    @mjbvz
    Contributor

    Benjamin Pasero (@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?

  12. mjbvz commented on Feb 26, 2021

    @mjbvz
    Contributor

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

  13. bpasero commented on Feb 26, 2021

    @bpasero
    ContributorAuthor

    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.

  14. mjbvz commented on Feb 27, 2021

    @mjbvz
    Contributor

    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

  15. olegKusov commented on Mar 9, 2021

    @olegKusov

    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
  16. mjbvz commented on Mar 9, 2021

    @mjbvz
    Contributor

    Oleg Kusov (@olegKusov) Please open a separate issue with an example project that demonstrates the problem

  17. added
    author-verification-requested
    on Mar 26, 2021
  18. removed
    verification-found
    author-verification-requested
    on Mar 29, 2021
  19. added
    author-verification-requested
    on Mar 29, 2021
  20. soanvig commented on Apr 12, 2021

    @soanvig

    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

  21. locked as resolved and limited conversation to collaborators on Apr 12, 2021
  22. mjbvz commented on Apr 12, 2021

    @mjbvz
    Contributor

    Mateusz Koteja (@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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

author-verification-requestedbugpapercut 🩸typescriptverifiedweb

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions