Solargraph not working with WSL

EDIT - I got Solargraph working with WSL / VS Code, but I couldn’t get SketchUp debugging working. So I switched to a Windows environment, and everything’s working fine.

The Solargraph issue: It seems that solargraph was scanning across directories in my VSCode workspace, and getting an error from a non-ASCII character - � . Specifically this character was in a comment within a ruby snippet included with Alex Schreyer’s ruby editor, version 4.3. I’ll message him.

as_rubyeditor\snippets\08 - Transform selection.rb

=====================

Trying to set up for development & debugging in VSCode – following the guides here, and I’m having a problem with Solargraph:

Upon starting VSCode and loading a ruby file, I got:
Solargraph gem not found. Run gem install solargraph or update your Gemfile.

The gem was already installed. But I did some re-installing things and fiddling around and now I’m getting a new error:
Failed to start Solargraph: Error: [ArgumentError] invalid byte sequence in UTF-8

I do all my coding in WSL2 (Ubuntu 20.04 LTS), and I’ve never been able to get Solargraph working. Otherwise, WSL has been great. I’m using VSCode & Windows Terminal (bash). Ruby 2.7.1 is installed to the Ubuntu WSL, via ruby-install / ch-ruby.

I installed gems to WSL (via Windows Terminal bash): solargraph, yarn, rubocop, sketchup-api-stubs.

which solargraph returns /home/bubba/.gem/ruby/2.7.1/bin/solargraph
I tried changing Solargraph: Command Path to that path – same error.

I also tried starting vscode via WSL bash code .

I can set up for development in Windows if I need to, but WSL has worked so nicely up until now. I hear that Ruby on Windows can be troublesome, but I’ve never tried it.

edit- I tried reinstalling everything ( WSL Ubuntu / Ruby / VSCode ) – this time installing ruby as user instead of root – same error. Upon reinstallation of VS Code I noticed it kept all my old settings and my local extensions – WSL extensions were wiped.

Encountered an unrelated issue of etc 1.2 having problems with ruby 2.7.1 – solved by deleting etc gem files and reinstalling gem install etc -v 1.1.0

Here is the print from gem env

(click to expand)
bubba@BubbaBox:/mnt/c/Users/bubba$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 3.1.2
  - RUBY VERSION: 2.7.1 (2020-03-31 patchlevel 83) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/bubba/.gem/ruby/2.7.1
  - USER INSTALLATION DIRECTORY: /home/bubba/.gem/ruby/2.7.0
  - RUBY EXECUTABLE: /home/bubba/.rubies/ruby-2.7.1/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /home/bubba/.gem/ruby/2.7.1/bin
  - SPEC CACHE DIRECTORY: /home/bubba/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/bubba/.rubies/ruby-2.7.1/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/bubba/.gem/ruby/2.7.1
     - /home/bubba/.rubies/ruby-2.7.1/lib/ruby/gems/2.7.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/bubba/.gem/ruby/2.7.1/bin
     - /home/bubba/.rubies/ruby-2.7.1/lib/ruby/gems/2.7.0/bin
     - /home/bubba/.rubies/ruby-2.7.1/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games
     - /usr/local/games
     - /mnt/c/Program Files/Oculus/Support/oculus-runtime
     - /mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath
     - /mnt/c/WINDOWS/system32
     - /mnt/c/WINDOWS
     - /mnt/c/WINDOWS/System32/Wbem
     - /mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/
     - /mnt/c/WINDOWS/System32/OpenSSH/
     - /mnt/c/Program Files/PowerShell/7/
     - /mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common
     - /mnt/c/Program Files/Git/cmd
     - /mnt/d/progs/ffmpeg/bin/
     - /mnt/c/Users/bubba/AppData/Local/Microsoft/WindowsApps
     - /mnt/c/Users/bubba/AppData/Local/GitHubDesktop/bin
     - /mnt/d/OneDrive/_work/hugo/bin
     - /mnt/c/Users/bubba/AppData/Local/Programs/Microsoft VS Code/bin
     - /snap/bin

FYI

SketchUp comes with it’s own Ruby interpreter and stdlib. (The library is in SketchUp’s “Tools” folder.)
SketchUp also uses gems (that are compatible, meaning mostly pure Ruby gems, or those that are precompiled for the particular platform,) and they are installed in a special GEMHOME folder path. You can find this path from within SketchUp’s Ruby console and type …

ENV["GEMHOME"]

To install gems into SketchUp’s Ruby, you need to use the Gem.install Ruby method from within SketchUp.

2 Likes

Thanks Dan, that is good to know.

I made a little progress with troubleshooting Solargraph – the error…

Failed to start Solargraph: Error: [ArgumentError] invalid byte sequence in UTF-8

…seems to be triggered only when I open certain large folders in VSCode (e.g. my SU_code folder). If I open a simple clean directory, like one of Eneroth’s repos, Solargraph loads fine.

Solargraph seems to be doing some kind of scan across directories and finding something that it doesn’t like. I wonder if it has something to do with some weird metadata files, from Microsoft OneDrive or something… all my code was previously stored in OneDrive.

I don’t know how to see what file is giving Solargraph a problem. But I guess in the meantime I can just load one project folder at a time.

1 Like

It seems that solargraph was scanning across directories in my VSCode workspace, and getting an error from a non-ASCII character � . It didn’t matter whether the problem file was open – just that its folder was loaded in VSCode’s folder browser.

Specifically this character was in a comment within a ruby snippet included with Alex Schreyer’s ruby editor, version 4.3. I’ll message him.

as_rubyeditor\snippets\08 - Transform selection.rb

relevant Solargraph guide

All rb files need to be UTF-8 encoded.

Update:
I got Solargraph working in WSL VS Code, but I then I had another problem: I was unable to get SketchUp Ruby debugger in VS Code to connect with SketchUp (I suppose because the debugger files are written for Mac or Windows?). So I’ve switched to developing in Windows (no WSL) and everything has been working fine so far. Time to play with this debugger!

Windows 10, Sketchup 2021.0.1, VS Code, Ruby 2.7.2 via RubyInstaller