castwide / vscode-solargraph

A Visual Studio Code extension for Solargraph.
Other
424 stars 25 forks source link

Can't start solargraph gem through WSL #80

Closed pablox-cl closed 5 years ago

pablox-cl commented 5 years ago

I can ran solargraph when installed trough rubyinstaller, but I can't run it trough the wsl. Through the terminal (wsl) I'm using rbenv:

❯ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

❯ which solargraph
/home/pablo/.rbenv/shims/solargraph

❯ solargraph -v
0.28.1

If just let solargraph as the command path inside VSCode, it ran inside the "rubyinstaller" version:

C:\Users\pablo>ruby -v
ruby 2.4.4p296 (2018-03-28 revision 63013) [x64-mingw32]

C:\Users\pablo>solargraph -v
0.28.1

If I try to set the:

solargraph.commandPath": "~/.rbenv/versions/2.5.1/bin/solargraph"

I get:

[Extension Host] The system cannot find the path specified.

notificationsAlerts.ts:41 Solargraph gem not found. Run `gem install solargraph` or update your Gemfile.
t.onDidNotificationChange @ notificationsAlerts.ts:41

[Extension Host] Failed to start language server: {"code":"ENOENT","errno":"ENOENT","syscall":"spawn ~/.rbenv/versions/2.5.1/bin/solargraph","path":"~/.rbenv/versions/2.5.1/bin/solargraph","spawnargs":["socket","--port","0"]}

Which, kind of makes sense since VSCode doesn't run from inside wsl.

Trough the windows command prompt is possible to run file from the wsl:

C:\Users\pablo>bash -c '~/.rbenv/versions/2.5.1/bin/solargraph -v'
0.28.1  

or...

C:\Users\pablo>wsl ~/.rbenv/versions/2.5.1/bin/solargraph -v
0.28.1

Though, trying both commandPath, results in strange errors:

# wsl ~/.rbenv/versions/2.5.1/bin/solargraph
[Extension Host] /bin/bash: ~.rbenvversions2.5.1binsolargraph: command not found

[Extension Host] Failed to start language server: "/bin/bash: ~.rbenvversions2.5.1binsolargraph: command not found\n"

# bash -c '~/.rbenv/versions/2.5.1/bin/solargraph'

[Extension Host] socket: ~.rbenvversions2.5.1binsolargraph: command not found

[Extension Host] Failed to start language server: "socket: ~.rbenvversions2.5.1binsolargraph: command not found\n"

Maybe it's possible to run solargraph trough bash trough the plugin internals?

pablox-cl commented 5 years ago

After diving into the code (I have basic understanding of js/ts), it seems that the problem is cross-spawn, that doesn't recognize wsl paths.

Nevertheless I found a workaround (use a .bat wrapper):

@echo off
bash -c "~/.rbenv/shims/solargraph %*"

I still have problems solargraph not being able to follow correctly requires (and almost everyone outside the stdlib says it doesn't exist; but that's a different problem)

castwide commented 5 years ago

Thanks for figuring that out. That's the most success I've heard from anyone trying to connect VS Code in Windows to Solargraph in WSL.

If the unfound requires are gems, you might be missing YARD documentation. There's an option to Build new gem documentation in the VS Code command palette, or you can run yard gems from a terminal.

mtam2 commented 4 years ago

For anyone who's looking for clearer instructions for the work around by @pablox-cl https://github.com/castwide/vscode-solargraph/issues/80#issuecomment-423748289 using rvm and WSL1:

  1. Run which solargraph in bash and copy the path
  2. Create a solargraph.bat file and paste the following snippet. Use the the path from which solargraph to replace {{SOLARGRAPH_PATH}}
    @echo off
    bash -c "{{SOLARGRAPH_PATH}} %*"
  3. IMPORTANT: Replace bin with wrapper in the path. (e.g. /home/mtamdev/.rvm/gems/ruby-2.6.0@dev-project/bin/solargraph %* -> /home/mtamdev/.rvm/gems/ruby-2.6.0@dev-project/wrappers/solargraph %*
  4. Save the solargraph.bat file and copy it's full filepath
  5. Add the following to the VSCode settings.json. Replace the path with the copied bat filepath. "solargraph.commandPath": "C:\\Max\\solargraph.bat"
  6. Restart VSCode
  7. Solargraph should work
OrkunSA commented 4 years ago

@mtam2 Where do you run which solargraph on? On ubuntu or command prompt?

mtam2 commented 4 years ago

@OrkunSA Run which solargraph in ubuntu bash.

OrkunSA commented 4 years ago

@mtam2 I just did and I got /home/dikilikid/.rvm/gems/ruby-2.6.1/bin/solargraph I am sorry man I am really new to this world and if I am asking stupid questions please don't mind me. I am gonna create a bat file but not sure how to do that. Should i do touch solargraph.bat ?

mtam2 commented 4 years ago

Yes, create a file like normal and paste

@echo off
bash -c "/home/dikilikid/.rvm/gems/ruby-2.6.1/wrapper/solargraph %*"

Save the file somewhere simple and copy the file's location. Now open VSCode and open the command palette (ctrl+shift+p) and search "preferences: open settings (JSON)" At the end of the settings.json file, add your bat file's path "solargraph.commandPath": "C:\\solargraph.bat" And restart VSCode afterwards.

OrkunSA commented 4 years ago

It's giving me the error below. @mtam2 Capture

mtam2 commented 4 years ago
  1. Create a new file in VSCode
  2. Paste the snippet
  3. Save the file
  4. Open the command palette (ctrl+shift+p)
  5. Search: "preferences: open settings (JSON)" and hit enter
  6. Add the following line to the bottom of the settings.json file: "solargraph.commandPath": "C:\\solargraph.bat"
  7. Change C:\\solargraph.bat to where you save the solargraph.bat file
  8. Restart VSCode
jmrsnt commented 4 years ago

Thanks so much @mtam2 u saved me a lot of time! 😄 But on Ubuntu, solargraph is in /usr/local/bin/solargraph and when I change bin to wrapper at solargraph.bat like this

REM solargraph.bat
@echo off
bash -c "/usr/local/wrapper/solargraph %*"

vscode says

[Error - 21:53:56] Starting client failed
/bin/bash: /usr/local/wrapper/solargraph: No such file or directory

And when i leave bin it works perfectly.

jonatasvieira commented 4 years ago

In your case using asdf, you must reshim your ruby.

asdf reshim ruby

After this, asdf will provide link to gem, then restart vscode.

liciniomendes commented 2 years ago

There is a simpler solution than creating batch files that may not work depending on your setup.

Install Remote - WSL extension and start VS Code from your WSL with code . inside the folder you have your project.

Set27 commented 1 year ago

There is a simpler solution than creating batch files that may not work depending on your setup.

Install Remote - WSL extension and start VS Code from your WSL with code . inside the folder you have your project.

not working for me

CoderJayUK commented 1 year ago

@liciniomendes method works fine. Make sure you check your extensions because they will need to be installed again. You will see errors like below. Just press the "Install in WSL" button next to each extension you want to install. I had to do this for my Ruby plugins.

image

And here's an image showing it working:

image