[ruby on rails] ruby ​​uses vscode for development

ruby LSP implementation

The ruby ​​plug-in recommends using this to implement it, but now it is very slow when loading file indexes, sometimes good or bad, so now it is recommended to use Solargraph to implement it.

  • ruby LSP requires ruby ​​version 3 or above. If used in an old version, you need to specify the bundleGemfile path.
    Tutorial on using ruby ​​LSP with old versions of ruby
$ mkdir ruby-extensions
$ cd ruby-extensions
$ touch Gemfile
$ touch .ruby-version

# Gemfile
source 'https://rubygems.org'

ruby '3.1.4'

# Ruby LSP
gem 'rubocop'
gem 'ruby-lsp'

# .ruby-version
3.1.4 
  • Configure in setting
 "rubyLsp.enableExperimentalFeatures": false,
    "rubyLsp.rubyVersionManager": "rbenv",
    "rubyLsp.bundleGemfile": "/Users/pagorn/ruby-extensions/Gemfile",
    "rubyLsp.enabledFeatures": {
        "codeActions": true,
        "diagnostics": true,
        "documentHighlights": true,
        "documentLink": true,
        "documentSymbols": true,
        "foldingRanges": true,
        "formatting": true,
        "hover": false,
        "inlayHint": true,
        "onTypeFormatting": true,
        "selectionRanges": true,
        "semanticHighlighting": true,
        "completion": false,
        "codeLens": true,
        "definition": true,
        "workspaceSymbol": true,
        "signatureHelp": true
    }, 

Solargraph implements method jump

  • Install ruby ​​plug-in 0.27.0. If the higher version is started in the new version of vscode, an error will be reported.
    Download 0.27.0rebornix.Ruby-0.27.0.vsix from the plug-in market, put it in the /Applications/Visual Studio Code.app/Contents/Resources/app/bin directory, and then code --install-extension rebornix .Ruby-0.27.0.vsix --force
    Insert image description here

  • Install Ruby Solargraph
    Insert image description here

  • vscode setting setting

 "solargraph.diagnostics": true,
    "solargraph.definitions": true,
    "solargraph.formatting": true,
    "solargraph.completion": true,
    "solargraph.hover": true,
    "solargraph.commandPath": "/Users/rushboy/.rbenv/shims/solargraph",
    "ruby.useLanguageServer": true,
    "ruby.intellisense": "rubyLocate", 
  • Remember to turn off automatic updates for extensions