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

fix: ensure that the tsserver subprocess uses same node instance #292

Merged
merged 3 commits into from
Nov 17, 2021

Conversation

rchl
Copy link
Member

@rchl rchl commented Nov 13, 2021

The server has always supported two ways of starting the tsserver
sub-process - either forking the current process or spawning a new
Node process. The latter was problematic in some cases and this PR
is removing support for that.

Forking the process was used when we had a path to the tsserver.js
script while spawning was used when we had either just a binary
name like tsserver or a full path to the the tsserver shell
script. Since a shell script can't be started directly by Node, we
had to let the shell handle it and start the Node process that way.

That was an issue since it sometimes resulted in starting a completely
different instance of Node found on the PATH, that was potentially not
compatible or, more likely, sandboxed as is the case with Snap packages.

This PR removes support for spawning a process but also adds logic
that will try to find the path to the corresponding tsserver.js
script if we've only been passed tsserver or path to the shell
script through --tsserver-path. This should ensure that the server
stays backward-compatible with the previous approach as much as
possible (even if not 100%).

Fixes #191

The support for passing path to a `tsserver` shell script or just
a `tsserver` string to `--tsserver-path`, and relying it to be found
on the PATH, is removed.

The provided path must point to the `typescript/lib` directory (or
`typescript/lib/tsserver.js` script for backward compatibility) and the
server will run it through the `tsserver.js` path that it will look up.

Starting `tsserver` through a shell script is wrong and in some cases
even causes server to not work at all. That's because spawning
a node process for `tsserver` instead of forking the current one can
result in running a completely different node version or even a node
version that is sandboxed and can't communicate with this LSP server.

Fixes #191
@rchl rchl changed the title fix: remove support for spawning the tsserver through shell script fix: ensure that the tsserver subprocess uses same node instance Nov 17, 2021
@rchl rchl merged commit d9e07a1 into master Nov 17, 2021
@rchl rchl deleted the fix/remove-spawn branch November 17, 2021 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

doRequestDiagnostics of LspServer looks did not handle err? no 'catch'?
1 participant