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

Cannot use local typescript version #136

Closed
rsimp opened this issue Sep 25, 2017 · 7 comments
Closed

Cannot use local typescript version #136

rsimp opened this issue Sep 25, 2017 · 7 comments

Comments

@rsimp
Copy link

rsimp commented Sep 25, 2017

With multiple typescript projects there is a need to use a typescript server version that corresponds with what's installed in the project.json. Is there a configuration to use a project tsserver and not a global one?

@DeltaEvo
Copy link
Contributor

You can use
LanguageClient_registerServerCommands function to add or update server commands once the project is loaded
https://github.com/autozimu/LanguageClient-neovim/blob/master/rplugin/python3/LanguageClient/LanguageClient.py#L294

@autozimu
Copy link
Owner

This project have no idea of typescript specific knowledge.

Beside the approach mentioned by DeltaEvo, you can use local vimrc in each project dir, or specify the language server programmatically in your vimrc.

(From a user's perspective, I don't think you will need to have different versions of typescript. The javascript-typescript-langserver will use typescript, but it's not 1-on-1 mapping. The newer versions of javascript-typescript-langserver will have better support and should be compatible with older versions of typescript files.)

@rsimp
Copy link
Author

rsimp commented Sep 29, 2017

@autozimu that is definitely not the case. Differing versions of typescript (even by a minor version) give different errors with the same source code. Perhaps you didn't know but typescript does not follow semver (microsoft/TypeScript#14116). An older version of typescript may miss complex errors that newer versions catch, and code that compiles successfully with newer versions of typescript may throw errors in an older version due to weaker type inference in the older versions. Ultimately you want your language server to correspond with the typescript version listed in your package.json.

@autozimu @DeltaEvo This may be something you want to think about putting into LanguageClient-neovim. It's a feature built into VS Code, the tide tsserver plugin for emacs, the built-in typescript layer for spacemacs, and the tsuquyomi tsserver plugin for vim. It's not critical but it means that the errors inside vim will not match those output by your build when your typescript versions are off.

Really what you need is a way to specify a relative path from project root, whether that's finding the project.json, tsconfig, or even a new file of your choosing. I think even using a method like @DeltaEvo mentioned would be fine, but expecting users to figure that out is asking a bit much. I'd expect an example repo or just a blurb on the readme.md or wiki. Another option would be to make separate language server plugins for LanguageClient-neovim instead of a simple configuration path to handle things like this.

Spawning a new .vimrc for every typescript project is also way too cumbersome, its easier to just live with the false errors, or use a more specialized tsserver plugin.

@rsimp
Copy link
Author

rsimp commented Sep 29, 2017

I guess the main issue is that tsserver is included in every npm typescript package but the sourcegraph wrapper that implements the language server protocol does not. Now that I'm thinking it over, I think this would have to be implemented by sourcegraph.

@autozimu
Copy link
Owner

I understand the situation.

The problem is that is this project doesn't use tsc directly. There is javascript-typescript-langserver sit in between, i.e.,

tsc <=> javascript-typescript-langserver <=> LanguageClient-neovim

There is no direct connection between LanguageClient-neovim with tsc, which means even if LanguageClient-neovim can detect the correct tsc version, there is no way to tell javascript-typescript-server which version of tsc it should use.

In my opinion, this issue should/could be addressed gracefullly in javascript-typescript-langserver side. Filing an issue there would be the best option.

@DeltaEvo approach could be an alternative, while I don't know if it is possible to map the versions of javascript-typescript-langserver to tsc versions.

@autozimu
Copy link
Owner

Yes, you got it.

@DeltaEvo
Copy link
Contributor

@rsimp you can use https://www.npmjs.com/package/ts-language-server and these settings

let g:LanguageClient_serverCommands = {
        \ 'typescript': ['~/.vim/langservers/typescript-language-server', '--stdio', '--tsserver-path', 'node_modules/.bin/tsserver'] 
        \ }

ts-language-server act as a proxy for tsserver but it dosen't suport much requests https://github.com/prabirshrestha/typescript-language-server/issues

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

No branches or pull requests

3 participants