-
Notifications
You must be signed in to change notification settings - Fork 63
Switch to Theia typescript language server #139
Conversation
package.json
Outdated
@@ -50,7 +56,7 @@ | |||
}, | |||
"dependencies": { | |||
"atom-languageclient": "0.9.7", | |||
"javascript-typescript-langserver": "^2.7.0" | |||
"typescript-language-server": "0.3.6" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v0.3.6 doesn't have the hierarchical support fixes merged (the latest few 0.4.0-dev versions have it). Additionally none of these versions have the child_process forking implemented, its only implemented in PRs right now. Without the forking changes the shebang at the top of tsserver
will be used which requires users have node installed locally and that PATH happens to resolve correctly (which it doesn't on osx using homebrew to install node).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather we move on without waiting for 0.4.0 for now as we actually already have a hierarchy anyway using the old api.
I did try using your fork but the yarn dependency was making things just plain not install for myself on Windows and another team member on macOS. I think we're better off either putting something in the README or some detection logic about node being required on the path until they merge the logic in upstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be best to deploy a built fork of the package to npm then with the forking logic in. Note some very interesting hacks I needed to get it working without: mattlyons0@f218f1d#diff-16b7d75b70953cbf4755508170f2f24cL34
The node binary wasn't resolving on startup (on OSX with node installed via homebrew, worked fine on Linux) which caused the plugin to crash, after ~10sec when startup had completed then I could disable and enable the plugin to restart everything and it would resolve. I put this hack in to get it to resolve on startup by having the user specify the folder which node
binary was in.
I've built a version of typescript-language-server
from https://github.com/mattlyons0/typescript-language-server/tree/release and published it to npm under @mattlyons/typescript-language-server
. Feel free to give that a shot and grab the tarball if you wish to publish it under a package you own.
lib/main.js
Outdated
getTypescriptServerPath() { | ||
const tsServerPath = atom.config.get('ide-typescript.typescriptServerPath') | ||
if (tsServerPath) return tsServerPath | ||
return process.platform === 'win32' ? 'tsserver.cmd' : 'tsserver' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since tsserver
has a shebang at the top the electron built in version of node is not used with tsserver
. None of this is merged in yet but a interesting detail of the PR most likely to be merged: typescript-language-server/typescript-language-server#88 is that it will only fork on files ending with .js
, otherwise it will use child_process.exec
on them (which will use the globally installed node version if it can correctly find it). Implementation wise I think this would mean to just use the lib/tsserver.js
file that tsserver
links to but for user configuration it might get interesting...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See: typescript-language-server/typescript-language-server#88 (comment)
Since this PR got merged in the config option for typescriptServerPath
can be removed and it can always be `node_modules/typescript/lib/tsserver.js as long as the typescript package is a dependency.
Since a .js
file is being invoked theia will start tsserver
by forking the current node process (and will use the node version built into electron). Additionally I don't think there needs to be anything special done on windows anymore since hashbang isn't being relied on after this change (but haven't tested this).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By keeping this there though they can optionally use a different version of typescript from the one the Theia language server ships with? Is that even supported that end tho?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is, but it will only be opened "properly" (with forking logic) if the file ends with .js
What's interesting is since the bundled version of typescript
is in the top level of the repository and they actually publish the /server
folder, the published version of typescript-language-server
on npm does not include the typescript
package so it would need to be included by ide-typescript
. See https://github.com/theia-ide/typescript-language-server/blob/master/server/package.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see, they don't include typescript with their language server so we have to include it and specify path to it. We could still let them override the path via a config setting but would need to change the default path to point to the one we bundle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly
0.3.7 was released with typescript-language-server/typescript-language-server#88, please try |
Thanks @akosyakov seems to be working great. |
Hey @mattlyons0 can you give this PR a try/look over? |
See https://github.com/atom/ide-typescript/pull/139/files#r234747489 |
Just confirmed 7dd7854 works on windows without node installed 🎉 |
lib/main.js
Outdated
return super.shouldStartForEditor(editor); | ||
} | ||
|
||
validateTypeScriptServerPath() { | ||
const tsServerPath = atom.config.get('ide-typescript.typeScriptServer.path') | ||
if (fs.existsSync(tsServerPath)) return true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! I'm not involved here or familiar with this code at all (sorry to just drop in like this), but I was playing around with this branch and noticed that on my machine this doesn't work because process.cwd()
here is /
. No matter what, I get the warning. It looks like this needs a path.join
like shouldStartForEditor
above.
But other than that this is working great for me! Thanks for your hard work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem just dropping in :) I'll get that fixed before merging - it interestingly works here simply because I'm working on ide-typescript and so had launched atom from that folder :D
Most of the work was by @mattlyons0 so my hat is tipped to him.
Thanks for being so awesome and willing to look through this (rather large) change @damieng |
@damieng FYI the |
Thanks for the reminder, I'll bump that once we publish the new version of ide-typescript. |
Fixes #127 and subsequently probably many others.
Thanks to @mattlyons0 for investigating the suitability of the Theia language server in conjunction with Atom's LSP support and IDE features.