imba / vscode-imba

Imba language support for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=scrimba.vsimba
10 stars 5 forks source link

language server crashes immediately on launch #86

Open gumtu opened 3 years ago

gumtu commented 3 years ago

i followed the instructions at imba.io/language/getting-started to install imba locally and start the test app; the test app works and the splash screen appears at localhost:3000.

then installed the imba2 vscode plugin from the vscode plugin marketplace; then launched vscode on the test app directory; then the imba language server crashes immediately and emits:

/home/<user>/.vscode-server/extensions/scrimba.vsimba-2.5.3/server/src/index.imba:31

<long line of minified javascript taken from .vscode-server/extensions/scrimba.vsimba-2.5.3/server/dist/src/index.js line 31>

SyntaxError: Unexpected token '?'
    at wrapSafe (internal/modules/cjs/loader.js:1053:16)
    at Module._compile (internal/modules/cjs/loader.js:1101:27)
    at Object.import_module.Module._extensions.<computed> (/home/<user>/.vscode-server/extensions/scrimba.vsimba-2.5.3/server/dist/src/index.loader.js:319:16)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/home/<user>/.vscode-server/extensions/scrimba.vsimba-2.5.3/server/dist/src/index.loader.js:344:5)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
[Info  - 11:11:20 AM] Connection to server got closed. Server will restart.

line 31 of .vscode-server/extensions/scrimba.vsimba-2.5.3/server/src/index.imba is blank but line 32 is apparently a comment starting with "//" (and ending with "?"). i changed the "//" to "#" but the error re-occurred unchanged.

however the long line of minified javascript that appears in the error message is from line 31 of .vscode-server/extensions/scrimba.vsimba-2.5.3/server/dist/src/index.js (i suspect this is a clue).

here are the versions: ubunutu 20.04.1 LTS vscode 1.55.0 node 14.8.0 imba 2.0.0-alpha.129

braunse commented 3 years ago

This happens to me, too. I'm trying to use it on WSL 2 on Windows, if that helps.

The language server does not crash on the native Windows (but the compiler refused to run there with a rejected promise that I can't reproduce anymore, so taking WSL out of the picture wasn't an option either). In both cases, the version of the extension I installed was 2.5.3 from the VS Code Marketplace.

VS Code 1.55.1 (Edit: same behaviour also in 1.55.2) (Edit, again: also in VS Code Insiders 1.56.0) Node (in WSL) 14.16.0 vscode-imba 2.5.3

gumtu commented 3 years ago

i have the same scenario: i'm running ubuntu on wsl2 and the imba plugin does not crash when i run vscode from a windows shell vs. a linux shell.

vscode is a windows binary whether launched from a windows shell or a linux shell. the most salient difference is that, when run from a linux shell, vscode uses the remote wsl extension to run commands, extensions, a terminal, etc. on the linux distro.

i wonder if there is some interaction between the imba extension and the remote wsl extension?

whatever it is, it appears to have caused a syntax error in the index.js file that's part of the imba extension.

braunse commented 3 years ago

For me it happens both when starting VS Code from the Windows start menu, and from the WSL shell. When I connect to the WSL remote, open the WSL folder and open an imba file, VS code complains that the language server crashed 5 times.

The syntax error seems to be related to the Node version, as the file only throws the error when I execute it with the node binary bundled in the VS Code server:

# With system Node.JS (14.16.1)
~/dev/repro$ /usr/bin/node ~/.vscode-server/extensions/scrimba.vsimba-2.5.3/server/index.js
# Throws an error related to a missing file, but not a syntax error
# Probably because I didn't give it the right arguments or environment from the command line

~/dev/repro$ ~/.vscode-server/bin/08a217c4d27a02a5bcde898fd7981bda5b49391b/node ~/.vscode-server/extensions/scrimba.vsimba-2.5.3/server/index.js
# ...snip...
SyntaxError: Unexpected token '?'
    at wrapSafe (internal/modules/cjs/loader.js:1053:16)
    at Module._compile (internal/modules/cjs/loader.js:1101:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/home/seb/.vscode-server/extensions/scrimba.vsimba-2.5.3/server/index.js:1:1)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)

As the node version bundled with the server should be the same that is bundled in the desktop VS Code, I now wonder why I don't see a syntax error on Windows? 🤔

braunse commented 3 years ago

I dug deeper and found that the language server runs after running the server/dist/src/index.js file through babel to eliminate the ?? and ?. operators, using @babel/plugin-proposal-nullish-coalescing-operator and @babel/plugin-proposal-optional-chaining.

I ran the following in the server/dist/src/ directory and reloaded the VS code window afterwards:

~/.vscode-server-insiders/extensions/scrimba.vsimba-2.5.3/server/dist/src$ mv index.js index.js.orig && babel --plugins "@babel/plugin-proposal-nullish-coalescing-operator,@babel/plugin-proposal-optional-chaining" --filename index.js < index.js.orig > index.js
gumtu commented 3 years ago

good work braunse! is it feasible for me to make manual changes on my local machine to fix this problem? i assume i would be making these changes to files that are part of the imba extension?