Shopify / ruby-lsp

An opinionated language server for Ruby
https://shopify.github.io/ruby-lsp/
MIT License
1.62k stars 167 forks source link

Cannot start ruby-lsp with sublime text 4 #2842

Open leewaa opened 2 weeks ago

leewaa commented 2 weeks ago

Description

Reproduction steps

I cannot get ruby-lsp to work. IT fails to start, and judging from the trouble shoot output, there is something wrong with the environment it is running in, even though it seems to have the correct ENV with the paths set correctly. From the paths alone it looks like it uses the correct ruby, however the stack trace indicates is is trying to use ruby 2.6 somehow šŸ˜µā€šŸ’«??

Main points:


Troubleshooting: ruby-lsp

Version

Active view

Project / Workspace

LSP configuration

{
  "clients": {
    "ruby": {
      "command": [
        "solargraph",
        "stdio"
      ],
      "initializationOptions": {
        "diagnostics": true
      },
      "selector": "source.ruby | text.html.ruby"
    },
    "ruby-lsp": {
      "command": [
        "ruby-lsp"
      ],
      "enabled": true,
      "initializationOptions": {
        "enabledFeatures": {
          "diagnostics": true
        },
        "experimentalFeaturesEnabled": true
      },
      "lsp_debug": true,
      "selector": "source.ruby"
    }
  },
  "log_debug": true
}

System PATH

vinistock commented 1 week ago

Thank you for the bug report! I believe the issue is that the chruby environment is not activated inside the process that runs Sublime Text, which is documented here under the important tip.

Essentially, chruby mutates a few environment variables to allow ruby and gem executables to properly find things. That happens in your terminal, but it does not happen inside the process running Sublime Text. The fact that it's trying to use Ruby 2.6 gives it away, because that's the system Ruby - the one available when no environment variables have been mutated.

Ensure that chruby is activating the environment before invoking ruby-lsp in your command configuration. Instead of using simply ruby-lsp, you need to either switch the version and then call the gem executable or use something like chruby-exec. Something along the lines of

chruby $(cat .ruby-version) && ruby-lsp

Please report back if it works or if you encounter any issues. We will also gladly accept improvements to our editors documentation for better Sublime instructions.