Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Switch to Theia typescript language server #139

Merged
merged 11 commits into from
Nov 27, 2018
Merged

Conversation

damieng
Copy link
Contributor

@damieng damieng commented Nov 8, 2018

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.

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"
Copy link
Contributor

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).

Copy link
Contributor Author

@damieng damieng Nov 8, 2018

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.

Copy link
Contributor

@mattlyons0 mattlyons0 Nov 8, 2018

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'
Copy link
Contributor

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...

Copy link
Contributor

@mattlyons0 mattlyons0 Nov 19, 2018

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).

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly

@akosyakov
Copy link

0.3.7 was released with typescript-language-server/typescript-language-server#88, please try

@damieng
Copy link
Contributor Author

damieng commented Nov 19, 2018

Thanks @akosyakov seems to be working great.

@damieng
Copy link
Contributor Author

damieng commented Nov 19, 2018

Hey @mattlyons0 can you give this PR a try/look over?

@mattlyons0
Copy link
Contributor

See https://github.com/atom/ide-typescript/pull/139/files#r234747489
Current behavior is basically it doesn't work out of the box for 2 reasons. Node needs to be installed and its path set in the configuration of this plugin and the typescript package needs to be installed. Both of these can be fixed with my comments.

@mattlyons0
Copy link
Contributor

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
Copy link

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!

Copy link
Contributor Author

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.

@damieng damieng merged commit 3ecece9 into master Nov 27, 2018
@damieng damieng deleted the theia-language-server branch November 27, 2018 17:40
@mattlyons0
Copy link
Contributor

Thanks for being so awesome and willing to look through this (rather large) change @damieng
Also thanks to @akosyakov for your work on Theia and being so receptive to PRs to support this effort. This is a huge improvement to Atom JS workflow and I hope to convert more people to Atom because of it

@Aerijo
Copy link
Contributor

Aerijo commented Nov 28, 2018

@damieng FYI the atom-languageclient readme refers to the old LS

@damieng
Copy link
Contributor Author

damieng commented Nov 28, 2018

Thanks for the reminder, I'll bump that once we publish the new version of ide-typescript.

yami-beta added a commit to yami-beta/dotfiles that referenced this pull request Dec 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants