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

Error uninitialized constant RUBY_LSP_ACTIVATION_SEPARATOR with PowerShell (Windows) #2769

Open
ynty opened this issue Oct 24, 2024 · 8 comments
Labels
bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes

Comments

@ynty
Copy link

ynty commented Oct 24, 2024

Description

Ruby LSP Information

Ruby LSP Information

VS Code Version

1.94.2

Ruby LSP Extension Version

0.8.8

Ruby LSP Server Version

Unknown

Ruby LSP Addons

Ruby Version

Unknown

Ruby Version Manager

none

Installed Extensions

Click to expand
  • latex-workshop (10.5.5)
  • vscode-clangd (0.1.29)
  • vscode-language-pack-zh-hans (1.94.2024101609)
  • black-formatter (2024.4.0)
  • debugpy (2024.12.0)
  • pylint (2024.0.0)
  • python (2024.16.1)
  • vscode-pylance (2024.10.1)
  • jupyter (2024.9.1)
  • jupyter-keymap (1.1.2)
  • jupyter-renderers (1.0.19)
  • remote-ssh (0.115.0)
  • remote-ssh-edit (0.87.0)
  • cmake-tools (1.19.52)
  • hexeditor (1.10.0)
  • powershell (2024.2.2)
  • remote-explorer (0.4.3)
  • material-icon-theme (5.12.0)
  • vscode-xml (0.27.1)
  • vscode-yaml (1.15.0)
  • ruby-extensions-pack (0.1.12)
  • ruby-lsp (0.8.8)
  • sorbet-vscode-extension (0.3.37)
  • even-better-toml (0.19.2)
  • cmake (0.0.17)
  • markdown-all-in-one (3.6.2)

Ruby LSP Settings

Click to expand
Workspace
{
  "rubyVersionManager": {
    "identifier": "none"
  }
}
User
{
  "enableExperimentalFeatures": false,
  "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": "none"
  },
  "customRubyCommand": "",
  "formatter": "auto",
  "linters": null,
  "bundleGemfile": "",
  "testTimeout": 30,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true
}

Reproduction steps

  1. Start the Ruby LSP using a certain editor on Windows.
  2. Open a Ruby file.
  3. Command 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")' failed and the LSP won't start.

When trying to run this command on PowerShell 7, I get the Error Message:

 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")'
-e:1:in `<main>': uninitialized constant RUBY_LSP_ACTIVATION_SEPARATOR (NameError)

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)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ynty ynty added bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes labels Oct 24, 2024
@andyw8 andyw8 changed the title The Closed Issue #2592 Can Still be Reproduced Error uninitialized constant RUBY_LSP_ACTIVATION_SEPARATOR with PowerShell (Windows) Oct 24, 2024
@andyw8
Copy link
Contributor

andyw8 commented Oct 24, 2024

I've renamed the issue for easier identification (was previously "The Closed Issue #2592 Can Still be Reproduced").

@vinistock
Copy link
Member

Thank you for the bug report. We never run anything on PowerShell for activation exactly because of escaping issues, so the fact that running the command manually fails on it is expected (we always run on cmd.exe).

Can you share which errors you see in the Ruby LSP channel under the Output tab? Also, which version manager are you using (RubyInstaller or something else)?

@ynty
Copy link
Author

ynty commented Oct 25, 2024

@vinistock

which version manager are you using (RubyInstaller or something else)?

I'm using rbenv for Windows. It is similar to the rbenv on Unix-like systems but there are still differences, for example it has no rbenv exec command, which will be run to activate LSP when rubyVersionManager.identifier is set to "rbenv", so I set it to "none".


Can you share which errors you see in the Ruby LSP channel under the Output tab?

I can only get this under Output tab:

2024-10-25 20:37:02.347 [info] (hello-ruby) Running command: `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 d:\Code\hello-ruby using shell: undefined

And I receive an error notification:

Automatic Ruby environment activation with none failed: Command failed: 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")'
-e:1:in `<main>': uninitialized constant RUBY_LSP_ACTIVATION_SEPARATOR (NameError)
 
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)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Image

@ynty

This comment has been minimized.

@vinistock
Copy link
Member

So, there are two issues here:

The first one is that the Windows version of rbenv doesn't provide the same commands as the Unix version. This aspect, you can probably get around by using our custom activation.

Essentially, you need to define what shell script has to be invoked to ensure that the right Ruby environment is activated.

{
  // Set the manager to custom
  "rubyLsp.rubyVersionManager": {
    "identifier": "custom",
  },

  // A shell script that will be executed before trying to invoke Ruby.
  // Invoke the Windows version of rbenv here to set the correct environment variables
  // for the Ruby version. For example, something like this
  "rubyLsp.customRubyCommand": "rbenv activate"
}

The second part, which I frankly don't understand as of right now, is the escaping issue. Based on the output you shared, we are not setting any shells to invoke the Ruby command, which should default to using cmd.exe and the escaping should work properly. It's as if, despite not setting the shell, we're somehow still invoking PowerShell under the hood.

@vinistock
Copy link
Member

I published a pre-release version of the extension v0.8.11 which includes the fix in #2785.

@tn-072 can you give it a try and report back if it fixes the issue?

@ynty
Copy link
Author

ynty commented Oct 26, 2024

I published a pre-release version of the extension v0.8.11 which includes the fix in #2785.

@tn-072 can you give it a try and report back if it fixes the issue?

@vinistock

Seems that the command was run under cmd.exe, but it still failed.

Automatic Ruby environment activation with none failed: Command failed: 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")'
-e:1:in `<main>': uninitialized constant RUBY_LSP_ACTIVATION_SEPARATOR (NameError)

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)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Image
Image

@vinistock
Copy link
Member

I think setting it to cmd.exe didn't actually make exec use it under the hood, given that you're hitting the same PowerShell escaping issue. We may need to full path for it to work properly.

I'm not sure how to detect what is the default shell configured in Windows or how to find the exact location of cmd.exe. Any help from Windows users here is greatly appreciated.

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

Successfully merging a pull request may close this issue.

3 participants