microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
160.53k stars 28.11k forks source link

auto-imports (import suggestions) randomly stopped working #214807

Open runfaj opened 4 weeks ago

runfaj commented 4 weeks ago

Type: Bug

A little while ago (like over a week now), I was working as I always do, and all of the auto-import suggestions for typescript just stopped working completely. I hadn't updated anything manually (my os, vscode, extensions, node modules, etc). It is possible something auto-updated somewhere behind the scenes, but I haven't been able to track it down.

Essentially no auto-imports work at all in my project anymore. I can't import from relative pathed files, workspace files, or node modules. All typescript imports, once imported work fine and are recognized, but any of the "quick fix" suggestions just don't work at all, both as I type or hovering over a missing reference. The quick fix popup does show, but the only option is my tabnine extension.

What is strange is the imports have worked once since they stopped. I did nothing out of the ordinary and they just randomly started working again. But then as quickly as they appeared, they disappeared.

I've tried all of the following:

The only other piece of information I have is this error in the ts logs, but I've tried tracking it down, even manually modifying the ts server code and logging things out for a couple hours, with no obvious things that stand out on why it is failing. This error appears when I try to hover over a known missing reference to have it show the imports, but then it just doesn't show them, presumably due to this error (some path parts redacted for privacy reasons).

Info 4708 [11:56:52.468] request:
    {
      "seq": 19,
      "type": "request",
      "command": "quickinfo",
      "arguments": {
        "file": "/<projectPath>/apps/main-app/src/client/components/MyComponent.tsx",,
        "line": 42,
        "offset": 22
      }
    }
Info 4712 [11:56:52.468] request:
    {
      "seq": 20,
      "type": "request",
      "command": "getCodeFixes",
      "arguments": {
        "file": "/<projectPath>/apps/main-app/src/client/components/MyComponent.tsx",
        "startLine": 42,
        "startOffset": 18,
        "endLine": 42,
        "endOffset": 25,
        "errorCodes": [
          2304
        ]
      }
    }
Err 4713  [11:56:52.550] Exception on executing command {
  "seq": 20,
  "type": "request",
  "command": "getCodeFixes",
  "arguments": {
    "file": "/<projectPath>/apps/main-app/src/client/components/MyComponent.tsx",
    "startLine": 42,
    "startOffset": 18,
    "endLine": 42,
    "endOffset": 25,
    "errorCodes": [
      2304
    ],
    "startPosition": 1103,
    "endPosition": 1110
  }
}:

    Debug Failure.

    Error: Debug Failure.
        at Object.getImmediateAliasedSymbol (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:74339:22)
        at getDefaultExportInfoWorker (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:135913:29)
        at getDefaultExportInfoWorker (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:135915:14)
        at getDefaultLikeExportInfo (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:135891:16)
        at /<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:152437:25
        at /<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:135751:119
        at forEachExternalModule (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:135812:7)
        at forEachExternalModuleToImportFrom (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:135751:3)
        at getExportInfos (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:152433:3)
        at /<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:152366:24
        at flatMap (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:2609:17)
        at getFixesInfoForNonUMDImport (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:152360:10)
        at getFixInfos (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:152206:12)
        at Object.getCodeActions (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:151577:18)
        at /<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:148588:46
        at flatMap (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:2609:17)
        at Object.getFixes (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:148588:10)
        at /<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:146859:33
        at flatMap (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:2609:17)
        at Object.getCodeFixesAtPosition (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:146857:12)
        at IpcIOSession.getCodeFixes (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:187265:50)
        at getCodeFixes (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:185371:43)
        at /<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:187569:69
        at IpcIOSession.executeWithRequestId (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:187561:14)
        at IpcIOSession.executeCommand (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:187569:29)
        at IpcIOSession.onMessage (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:187611:51)
        at process.<anonymous> (/<projectPath>/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/tsserver.js:189220:14)
        at process.emit (node:events:518:28)
        at emit (node:internal/child_process:951:14)
        at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

From what I can conclude, this seems like either a timing issue withing vscode starting things up, or some internal vscode or extension thing somewhere broke behind the scenes. I'm on a wsl docker setup, so there is a lot of linking going on behind the scenes, but given I hadn't changed anything when this started happening, I'm at a complete loss on what to even look for further at this point.

Oh, and unfortunately, I haven't been able to reproduce this on any other machine, so I'm a bit stuck on that front. I'm happy to try modifying any settings suggested, I just have no idea what else to look for at this point.

VS Code version: Code 1.90.0 (89de5a8d4d6205e5b11647eb6a74844ca23d2573, 2024-06-04T19:33:54.889Z) OS version: Windows_NT x64 10.0.22635 Modes: Remote OS version: Linux x64 5.15.133.1-microsoft-standard-WSL2

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 x 2808)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|31.89GB (6.29GB free)| |Process Argv|--crash-reporter-id 10d747f9-1beb-40be-859f-a1379ddf2d04| |Screen Reader|no| |VM|0%| |Item|Value| |---|---| |Remote|WSL: Ubuntu| |OS|Linux x64 5.15.133.1-microsoft-standard-WSL2| |CPUs|Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 x 0)| |Memory (System)|17.57GB (11.70GB free)| |VM|0%|
Extensions (32) Extension|Author (truncated)|Version ---|---|--- remote-containers|ms-|0.369.0 remote-ssh|ms-|0.110.1 remote-ssh-edit|ms-|0.86.0 remote-wsl|ms-|0.88.2 vscode-remote-extensionpack|ms-|0.25.0 atom-keybindings|ms-|3.3.0 remote-explorer|ms-|0.4.3 remote-server|ms-|1.5.1 reopenclosedtab|uyi|1.1.0 material-theme|zhu|3.17.2 vscode-zipfs|arc|3.0.0 vscode-tailwindcss|bra|0.10.5 vscode-better-align|cho|1.4.2 npm-intellisense|chr|1.4.5 path-intellisense|chr|2.9.0 vscode-css-modules|cli|0.5.1 vscode-eslint|dba|2.4.4 githistory|don|0.6.20 gitlens|eam|15.1.0 vscode-search-open-all-results|fab|2.0.2 vscode-pull-request-github|Git|0.88.1 vscode-duplicate|mrm|1.2.1 vscode-docker|ms-|1.29.1 atom-keybindings|ms-|3.3.0 vsliveshare|ms-|1.0.5918 color-highlight|nau|2.8.0 gremlins|nho|0.26.0 vscode-stylelint|sty|1.4.0 tabnine-vscode|Tab|3.108.0 reopenclosedtab|uyi|1.1.0 vscode-fold-level|vik|0.0.14 vscode-svg-previewer|vit|0.7.0
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vswsl492cf:30256860 vscod805cf:30301675 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:31024239 vscaac:30438847 c4g48928:30535728 azure-dev_surveyone:30548225 2i9eh265:30646982 962ge761:30959799 9b8hh234:30694863 pythongtdpath:30769146 welcomedialog:30910333 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pythonmypyd1:30879173 pythoncet0:30885854 h48ei257:31000450 pythontbext0:30879054 accentitlementst:30995554 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 jchc7451:31067544 chatpanelc:31048052 dsvsc021:30996838 9c06g630:31013171 pythoncenvpt:31062603 a69g1124:31058053 dvdeprecation:31068756 pythonprt:31056678 dwnewjupyter:31046869 26j00206:31048877 ```
runfaj commented 3 weeks ago

Today was one of the days where this actually booted up correctly, so I think I have some more info that might help debug this!

I started my computer normally and it definitely chalks up to a timing issue somewhere, I'm thinking between docker and wsl and vscode working together. My startup process is always the same steps:

  1. open a terminal
  2. do wsl shutdown to make sure there isn't some lingering process
  3. start docker desktop (which has the wsl integration and such)
  4. start vscode

The times where this seems to work, I've noticed a couple things happen:

When it doesn't work, the above all fail and I have to manually run all commands in a docker context. So it seems like there's some timing issue where vscode doesn't initialize the order between wsl, docker, and other vscode setups in the correct order every time. This then seems to cause something like the typescript imports to fail with aliasing issues or something (given the error log shown above).

Is there some way to a) see the initialization flow for the entirety of vscode as a whole, and b) force it to always initialize in the same correct order each time?

EDIT: I might be mistaken on the above comment, but it seems related. After working through today, I had some lulls between meetings where I wasn't actively touching vscode at all for an hour or so at a time. And...now we're back to all the import stuff broken again. So just not touching it at all just broke it 😞

runfaj commented 3 weeks ago

After further testing, it seems that something internally broke with vscode where it isn't connecting the dots anymore unless the project is fully built. Previously, everything would work based on files in the project, but as I've been working, I've noticed connections do work right after a full build. I have a pnpm workspace where each package is its own thing with its own modules. If I build all packages, then links do appear correctly. However, if any file is modified/added between that build, then only things in the previous build are found. As soon as something is not found, it seems to more or less crash the ts server in the fact that references just stop working (even though the server might still be running behind the scenes).

runfaj commented 1 week ago

I really don't know what in the world to do here. I've all but completely reset vscode down to the bare essentials and it still seems to crash on all the imports. It is incredibly frustrating, especially if I have to manually type import paths across dozens of files when adding/updating some feature in a project.

I've also attempted on the latest TS version. At this point, when some issue happens, now it seems to even be crashing the tsserver completely somewhat. The options to restart the ts server in the vscode command menu completely disappear and everything.

Any debugging help would be appreciated. @mjbvz any suggestions?

runfaj commented 1 week ago

Additional update: it seems that upgrading to TS 5.5 fixed import suggestions during typing partially. Sometimes things are not found still, but other times they are. However, the quick fix popup is still entirely broken and never shows any suggestions. The logged ts error remains the same as the description.

mjbvz commented 4 days ago

Please provide an example project and steps to reproduce this so we can take a look

runfaj commented 1 day ago

@mjbvz I've tried to reproduce this on 2 different machines from the one that has the issue and I haven't been able to unfortunately. It seems to be something in conjunction with docker, wsl, vscode, and typescript altogether and possibly not loading in the correct order somewhere. I'd be happy to give a reproducible example, but I haven't been able to get anything other than the current machine with the provided error log. Is there anything in addition to the description/comments above I can help provide to at least potentially narrow things down?