DEV Community

r7kamura
r7kamura

Posted on

5

Use ruby-lsp plugins without modifying the project's Gemfile

First, avoid including editor-specific configuration files in the project.

# .gitignore OR .git/info/exclude
.vscode
Enter fullscreen mode Exit fullscreen mode

Next, prepare a Gemfile for ruby-lsp in the gitignored directory. If .ruby-lsp/Gemfile already exists, you can copy and paste and edit it. In this example, I will introduce a new plugin called ruby-lsp-rspec.

# .vscode/Gemfile
eval_gemfile(
  File.expand_path(
    '../Gemfile',
    __dir__
  )
)

group :development do
  gem "ruby-lsp", require: false
  gem "ruby-lsp-rails", require: false
  gem "ruby-lsp-rspec", require: false
end
Enter fullscreen mode Exit fullscreen mode

Finally, change the configuration of ruby-lsp to specify the path to the Gemfile. This may be set from the GUI.

// .vscode/settings.json
{
  "rubyLsp.bundleGemfile": ".vscode/Gemfile"
}
Enter fullscreen mode Exit fullscreen mode

Reloading the workspace will reflect the settings; you can also use VSCode's reloadWindow command. Currently, ruby-lsp seems to have a bug that an error occurs if this setting is changed at startup, in which case you can reload it twice.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay