fix: improve typescript server path search for ts dependents lsp #3795
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
LSPs like
volar
(for VueJS),astro
ormdx_analyzer
rely on a path for the Typescript server they should use. But this path is wrongly assumed to be insidenode_modules/typescript/lib
starting from the nearestpackage.json
file.In fact, in case of monorepos / workspaces, with all package managers like
npm
,yarn
orpnpm
, some hoisting can take place. This means that thetypescript
node module will get move higher up in the tree to be shared between all projects and avoid duplication. The NodeJS module resolution works like this, by trying to find the module upward in the tree, one directory after another.Therefore, it can happen a case like this:
I therefore adapted the Lua algorithm to match the one of NodeJS (and the one of the
ts_ls
server, that does it natively).I've also mutualized this logic at one place to avoid de-duplication, but feel free to correct me on that. I've created a simple
typescript.lua
file, imagining that we could have language specific utils for LSPs that need it.