language-tools
language-tools copied to clipboard
"Go To Definition" in VS Code does not work for Typescript projects using Yarn 2 PnP
Describe the bug When you're using Yarn 2 PnP with a typescript project, an error occurs when using "Go To Definition" on an imported symbol.
To Reproduce
- Take the template app,
npx degit sveltejs/template svelte-typescript-app - Install typescript support
node scripts/setupTypeScript.js - Install Yarn 2
yarn set version berry - Make sure
ZipFSextension is installed in VS Code - Follow svelte-language-tools yarn pnp setup steps
- (Maybe some steps I'm forgetting to get things working normally)
- Import anything in the
App.sveltefile - Control-click your import
Error:
Unable to open 'index.d.ts': Unable to read file '.../.yarn/cache/svelte-npm-3.37.0-87abf2d623-fc7a1e9b64.zip/node_modules/svelte/types/runtime/index.d.ts' (EntryNotADirectory (FileSystemError): Error: ENOTDIR: not a directory, stat '.../.yarn/cache/svelte-npm-3.37.0-87abf2d623-fc7a1e9b64.zip/node_modules/svelte/types/runtime/index.d.ts').
Note that this works when control-clicking a file in a .ts file in the same project. That makes me think that there's something going on in the transition between VS Code and tsserver, which would be svelte-language-server I think. I've looked around but haven't seen any discussion on this yet, but lots of discussions which enabled this support in the Typescript language server - something about passing file paths around that aren't literal paths on the system.
Expected behavior
Same behavior as in a .ts file.
System (please complete the following information):
- OS: Mac OS
- Plugin/Package:
svelete-language-server
Have you tried following this doc for yarn 2 pnp ?
Yeah I was the one that noticed they didn't work any more with a recent change. Forgot to add that step into this issue description.
You can try setting logging the message between language-server and the extension:
- add this config
"svelte.trace.server": "verbose" - open the output channel near the integrated terminal, chose
svelte, and clear it - reproduce and post the output.
Hey there, I am experiencing a similar issue on vscode v1.61.2, with a clean SvelteKit project. For me, it only affects go to definition for HTML elements. See below for the error I get and relevant verbose log output.
This may be related to https://github.com/yarnpkg/berry/issues/3539. Happy to provide any further details that could help :).

Logs
[Trace - 3:59:02 AM] Received response 'textDocument/definition - (133)' in 6ms.
Result: [
{
"targetUri": "file:///home/hmnd/dev/redacted/redacted-project/.yarn/__virtual__/svelte2tsx-virtual-0efbfe4338/0/cache/svelte2tsx-npm-0.4.8-c7d7e3a3e4-af29b3db62.zip/node_modules/svelte2tsx/svelte-jsx.d.ts",
"targetRange": {
"start": {
"line": 1018,
"character": 6
},
"end": {
"line": 1018,
"character": 8
}
},
"targetSelectionRange": {
"start": {
"line": 1018,
"character": 6
},
"end": {
"line": 1018,
"character": 8
}
},
"originSelectionRange": {
"start": {
"line": 13,
"character": 2
},
"end": {
"line": 13,
"character": 4
}
}
}
]
It does not work with anything as it's Yarn 2 related. All modules are zipped, not in dirs. Installing zipfs does not help :(