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

Can't start solargraph gem through WSL #80

Closed
pablox-cl opened this issue Sep 22, 2018 · 14 comments
Closed

Can't start solargraph gem through WSL #80

pablox-cl opened this issue Sep 22, 2018 · 14 comments

Comments

@pablox-cl
Copy link

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

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

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.

@castwide castwide changed the title Can't start solargraph gem trough WSL Can't start solargraph gem through WSL Jul 28, 2019
@mtam2
Copy link

mtam2 commented Jan 20, 2020

For anyone who's looking for clearer instructions for the work around by @pablox-cl #80 (comment) 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}} %*"
  1. 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 %*
  2. Save the solargraph.bat file and copy it's full filepath
  3. Add the following to the VSCode settings.json. Replace the path with the copied bat filepath. "solargraph.commandPath": "C:\\Max\\solargraph.bat"
  4. Restart VSCode
  5. Solargraph should work

@OrkunSA
Copy link

OrkunSA commented Apr 17, 2020

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

@mtam2
Copy link

mtam2 commented Apr 17, 2020

@OrkunSA Run which solargraph in ubuntu bash.

@OrkunSA
Copy link

OrkunSA commented Apr 17, 2020

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

mtam2 commented Apr 17, 2020

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

OrkunSA commented Apr 17, 2020

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

@mtam2
Copy link

mtam2 commented Apr 17, 2020

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

jmrsnt commented Jun 8, 2020

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

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

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

Set27 commented Oct 25, 2022

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

CoderJayUK commented Nov 6, 2022

@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

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

9 participants