appdev-projects / rails-7-template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add ruby lsp

heratyian opened this issue · comments

Any thoughts on including the Shopify ruby-lsp by default?

It helps with showing documentation and command click to go to files.

https://marketplace.visualstudio.com/items?itemName=Shopify.ruby-lsp

While working on #34, I had a lot of trouble trying to get ruby-lsp installed and working in codespaces.

I finally tracked down the issue I'm having exactly as described here: Shopify/ruby-lsp#1714, i.e. here's my output from trying to manually start the ruby-lsp server:

rails-7-template bp-audit-extensions-and-settings % ruby-lsp
/home/student/.rvm/ruby-3.2.1/bin/ruby-lsp: 6: exec: /home/student/.rvm/ruby-3.2.1/bin/ruby: not found

Rather than actually resolving anything on that issue, after some painful looking debugging attempts, it looks like they just did a clean install and solved some unknown configuration problem without fixing the original bug 😑. I fear this might be rabbit hole so I'm going to keep this addition in the backlog unless it's something vital.

It helps with showing documentation and command click to go to files.

Maybe I misunderstand, but doesn't command clicking already open a file? (I just tested e.g. ls then command clicking at the terminal).

This same problem has been giving me headaches since at least February, with and without this template. I came back to investigate after seeing this Issue yesterday.

I think I have found at least a workaround to get Ruby LSP working with this template in a codespace. These are the steps I took:

  1. Open codespace of rails-7-template
  2. Add gem "ruby-lsp" to Gemfile
  3. Run rvm install 3.3.4
  4. Make sure /workspaces/rails-7-template/.ruby-version now says 3.3.4 or ruby-3.3.4
  5. Run gem update bundler
  6. Run bundle install
  7. Install Ruby LSP VSCode extension
  8. CMD + shift + P -> > Ruby LSP Start

The reason I tried updating the Ruby version is because I kept getting this error whenever running rvm list in the bash terminal:

rails-7-template main % rvm list
Warning! PATH is not properly set up, /home/student/.rvm/gems/ruby-3.2.1/bin is not at first place.
         Usually this is caused by shell initialization files. Search for PATH=... entries.
         You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles
         To fix it temporarily in this shell session run: rvm use ruby-3.2.1
         To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.
=* ruby-3.2.1 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

After installing 3.3.4, rvm list stops returning errors.

Thanks for digging into this! So it seems like simply updating Ruby to the latest stable version fixed things. Interesting. I will look into this when I have time, but for now it sounds like your write up here provides a work around for installation for interested students.

Perhaps we can fix this at the repo, or even Docker image level. On my TODO list 😄 .

I just tried it with a different version, since some gems might not work with 3.3.4 yet.
rvm reinstall 3.2.1 resulted in the same Ruby LSP errors but rvm install 3.2.2 and rvm install 3.2.5 both seem to have worked (in addition to the other steps I mentioned).
However, rvm reinstall 3.2.1 did get rid of the PATH is not properly set up warning. Seems like it's either an issue specifically with 3.2.1 or maybe the way it's installed through the Dockerfile?

I suspect it is the Docker image causing the problem. Thanks again for some more notes, very helpful.