sourcegraph / javascript-typescript-langserver

JavaScript and TypeScript code intelligence through the Language Server Protocol
https://sourcegraph.com
Apache License 2.0
793 stars 72 forks source link

TypeScript optional chaining causes parse error #687

Open raxod502 opened 4 years ago

raxod502 commented 4 years ago

Please refer to this minimal project, which contains a file src/main.ts with the following code:

const val = null;
console.log(val?.prop);

javascript-typescript-langserver produces the following diagnostic on line 2:

ts: Expression expected. [1109]

This symptom suggests that perhaps somehow the language server is using a version or configuration of TypeScript which does not have support for optional chaining, added in TypeScript 3.7. However, every version of TypeScript on my machine is 3.9 or later.

As far as I can tell, no other syntax features are broken. I will note that optional chaining was previously working, but something changed when I migrated to a new machine. I have not been able to identify what could have caused the difference.

Environment information

Language server path: /usr/bin/javascript-typescript-stdio

$ javascript-typescript-stdio --version
2.11.3

$ npx which -a tsc
/home/raxod502/files/temp/example-project/node_modules/.bin/tsc
/usr/bin/tsc

$ ./node_modules/.bin/tsc --version
Version 3.9.6

$ tsc --version
Version 3.9.5

$ uname -a
Linux shallan 5.6.16-1-MANJARO #1 SMP PREEMPT Wed Jun 3 14:26:28 UTC 2020 x86_64 GNU/Linux

Language server installed from AUR

LSP client: Emacs lsp-mode revision 5c9959fdf0a7ea12031e6798a330beccbc55a771

LSP message log: available on GitHub Gist

BryceLohr commented 4 years ago

Rather than using the TypeScript installed in your project, the language server appears to use its own bundled TypeScript. The version it uses is outdated; see this PR: See https://github.com/sourcegraph/javascript-typescript-langserver/pull/526.

Two other language servers I looked at also embed their own TypeScript. The official Microsoft TypeScript plugin for SublimeText does the same thing, too. Not sure why they chose that route; seems like it would be better to use the project's own TypeScript.

raxod502 commented 4 years ago

The version of TypeScript bundled in this project (according to package.json) was released in August 2018. Is this language server maintained any longer by Sourcegraph?

I may be looking into theia-ide language server to see if it is a suitable replacement.

BryceLohr commented 4 years ago

IIRC, the Theia language server project was looking for maintainers since they switched to using VS Code’s extension directly. I don’t have the links handy, but there were a couple issues in the TypeScript repo to make TSServer implement the language server protocol directly, that had good background discussion.

-Bryce

On Aug 9, 2020, at 10:23 AM, Radon Rosborough notifications@github.com wrote:

 The version of TypeScript bundled in this project (according to package.json) was released in August 2018. Is this language server maintained any longer by Sourcegraph?

I may be looking into theia-ide language server to see if it is a suitable replacement.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.