Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS system Ruby version (2.6) being used and prevents the extension from working #2921

Open
pprotas opened this issue Nov 27, 2024 · 9 comments
Labels
bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes

Comments

@pprotas
Copy link

pprotas commented Nov 27, 2024

Description

Ruby LSP Information

Ruby LSP Information

VS Code Version

1.95.3

Ruby LSP Extension Version

0.8.14

Ruby LSP Server Version

0.21.3

Ruby LSP Addons

  • Ruby LSP RSpec
  • Reek: Code smell detector for Ruby
  • Ruby LSP Rails

Ruby Version

3.2.5

Ruby Version Manager

mise

Installed Extensions

Click to expand
  • auto-rename-tag (0.1.10)
  • copilot (1.246.0)
  • copilot-chat (0.22.4)
  • debugpy (2024.12.0)
  • gitlab-workflow (5.19.0)
  • gitlens (16.0.4)
  • prettier-vscode (11.0.0)
  • python (2024.20.0)
  • remote-containers (0.391.0)
  • ruby-lsp (0.8.14)
  • sqltools (0.28.3)
  • sqltools-driver-pg (0.5.4)
  • vim (1.28.1)
  • vscode-docker (1.29.3)
  • vscode-eslint (3.0.10)
  • vscode-html-css (2.0.11)
  • vscode-pull-request-github (0.101.2024111810)
  • vscode-pylance (2024.11.3)
  • vscode-tailwindcss (0.12.15)

Ruby LSP Settings

Click to expand
Workspace
{}
User
{
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": true,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": true,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "mise"
  },
  "customRubyCommand": "",
  "formatter": "auto",
  "linters": null,
  "bundleGemfile": "",
  "testTimeout": 30,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true,
  "useLauncher": false,
  "featureFlags": {}
}

Reproduction steps

  1. Open VSC on MacOS using Finder/Spotlight with the Ruby LSP extension
  2. Open a Ruby file
  3. Notice it does not work and tries to use the MacOS 2.6 ruby version:
Failed to setup the bundle: Command failed: gem list ruby-lsp language_server-protocol prism rbs sorbet-runtime /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby: invalid option --yjit (-h will show valid options) (RuntimeError) . See [Troubleshooting](https://shopify.github.io/ruby-lsp/troubleshooting.html) for help
  1. Run VSC on MacOS using code . from your terminal
  2. Notice it works fine and doesn't try to use the 2.6 ruby version, but correctly uses 3.2.5 from Mise version manager

Basically it looks like asyncExec in vscode/src/workspace.ts:271 uses the MacOS built-in 2.6 Ruby version by default to run gem list. But when I run VSC from my terminal, it correctly loads the 3.2.5 Ruby version from Mise.

@pprotas pprotas added bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes labels Nov 27, 2024
@andyw8
Copy link
Contributor

andyw8 commented Nov 27, 2024

Was Mise installed via Homebrew? #2878

@pprotas
Copy link
Author

pprotas commented Nov 27, 2024

Yes it was, I will try your suggestion

@andyw8
Copy link
Contributor

andyw8 commented Nov 27, 2024

Let's centralize the discussion in that other issue.

@andyw8 andyw8 closed this as completed Nov 27, 2024
@pprotas
Copy link
Author

pprotas commented Nov 27, 2024

@andyw8 Looks like Mise is detected fine if I use custom
Image

{
  "rubyLsp.rubyVersionManager": {
    "identifier": "custom"
  },
  "rubyLsp.customRubyCommand": "/opt/homebrew/bin/mise"
}

And even auto-detection with mise works fine

{
  "rubyLsp.rubyVersionManager": {
    "identifier": "mise"
  }
}

Image

But in both instances, actually running the LSP fails with the error

Failed to setup the bundle: Command failed: gem list ruby-lsp language_server-protocol prism rbs sorbet-runtime /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby: invalid option --yjit (-h will show valid options) (RuntimeError) . See [Troubleshooting](https://shopify.github.io/ruby-lsp/troubleshooting.html) for help

which probably refers to asyncExec in vscode/src/workspace.ts:271

@vinistock
Copy link
Member

We currently only support the default installation path for Mise advertise on their documentation, which is ~/.local/bin/mise. The issue #2878 is exactly to start allowing for more install locations to be detected automatically, like the Homebrew version.

To workaround that issue for now you need to point to your Mise installation through the settings. Do not use custom.

{
  "rubyLsp.rubyVersionManager": {
    "identifier": "mise",
    "miseExecutablePath": "/opt/homebrew/bin/mise" // I think this is the path, but double check
  }
}

@pprotas
Copy link
Author

pprotas commented Nov 27, 2024

Alright, I used your settings:

{
  "rubyLsp.rubyVersionManager": {
    "identifier": "mise",
    "miseExecutablePath": "/opt/homebrew/bin/mise" // Obtained with `which mise`
  }
}

Looks like that is working fine and detecting Ruby 3.2.5 with mise:
Image

And yet, when I try to start the LSP it errors out:
Image

To me it looks like there is no problem with the version manager. It looks like it's detecting mise and ruby 3.2.5 just fine. The problem seems to be in asyncExec in src/workspace.ts:271, where gem list is being executed using the default macos 2.6 version instead of using the version obtained from the version manager.

@vinistock
Copy link
Member

Yes, but we call asyncExec passing to it ruby.env, which is the environment activated by the version manager - which indicates to me that something is not working.

If you check your Output tab under the Ruby LSP channel, are there any logs available?

@pprotas
Copy link
Author

pprotas commented Nov 28, 2024

Output tab:

2024-11-27 16:45:54.492 [info] (core) Running command: `/Users/pawel/.local/share/mise/installs/ruby/3.2.5/bin/ruby -W0 -rjson -e 'STDERR.print("RUBY_LSP_ACTIVATION_SEPARATOR" + { env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION, gemPath: Gem.path }.to_json + "RUBY_LSP_ACTIVATION_SEPARATOR")'` in /Users/pawel/Projects/h1/core using shell: /opt/homebrew/bin/zsh

That's it, no other output.

@vinistock vinistock reopened this Nov 29, 2024
@vinistock
Copy link
Member

I'm going to re-open this issue. You are surely impacted by #2878, but it seems there's something else happening here, which is quite odd.

If you take these steps

  1. Switch to a directory where the Mise environment is not activated. This is essential, otherwise you're just going to be printing the environment that is already working in your shell
  2. Invoke the activation command manually:
/Users/pawel/.local/share/mise/installs/ruby/3.2.5/bin/ruby -W0 -rjson -e 'STDERR.print("RUBY_LSP_ACTIVATION_SEPARATOR" + { env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION, gemPath: Gem.path }.to_json + "RUBY_LSP_ACTIVATION_SEPARATOR")'
  1. Check the PATH variable printed as part of the env key. It should have the bin directory for your Ruby installation in front of the system Ruby. For example, it might look something like this:
PATH = /Users/pawel/.local/share/mise/installs/ruby/3.2.5/bin:...

My suspicion is that something is failing during activation and, even though we find the correct Ruby version to run the activation script, the exported environment has the wrong PATH, which leads to us not running the right Ruby. We need to figure out why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes
Projects
None yet
Development

No branches or pull requests

3 participants