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

Failed to activate custom environment: Command failed... #1175

Closed
SaidRasinlic opened this issue Nov 10, 2023 · 10 comments · Fixed by Shopify/vscode-ruby-lsp#904
Closed

Failed to activate custom environment: Command failed... #1175

SaidRasinlic opened this issue Nov 10, 2023 · 10 comments · Fixed by Shopify/vscode-ruby-lsp#904
Labels
bug Something isn't working

Comments

@SaidRasinlic
Copy link

SaidRasinlic commented Nov 10, 2023

Ruby version

3.2.2

Code snippet

No response

Description

OS: Windows 10
Code editor: VSCode
Ruby version: 3.2.2
Ruby version manager: custom (I got none, so I put it as a custom, like the documentation suggests.)


I wanted to ensure that the issues were not exclusive to my computer but were widespread. I contacted a buddy who also uses Windows 10 to configure Ruby LSP, and he confirmed (with screenshots 😄) that he receives the same issues.

First approach:

With these two lines of code in JSON configuration settings:

  • "rubyLsp.rubyVersionManager": "custom",
  • "rubyLsp.customRubyCommand": "cmd /C PATH=C:\Ruby32-x64\bin;%PATH%"

I receive the following error:

Syntax-Error


Second approach:

Now, with these two lines of code:

  • "rubyLsp.rubyVersionManager": "custom",
  • "rubyLsp.customRubyCommand": "PATH=C:\Ruby32-x64\bin;%PATH% && ruby -rjson -e "STDERR.printf('%s', JSON.dump({ 'RUBY_ENV_ACTIVATE' => { 'env' => ENV.to_h, 'ruby_version' => RUBY_VERSION, 'yjit' => defined?(RubyVM::YJIT) } }))"",

I get the following error (it seems like it successfully extracts the data of ruby/bin in JSON format but still doesn't start LSP):

Ruby-LSP-Error

What can I do to make this work? Thank you in advance.

Expected output

I expect Ruby LSP to operate and start properly.

@SaidRasinlic SaidRasinlic added the bug Something isn't working label Nov 10, 2023
@vinistock
Copy link
Member

Thank you for the bug report! The second option is the right approach, just pushing something into the PATH.

It looks like the output was a bit too long for the VS Code dialogue box. I can't see what the actual error was, just parts of the JSON.

If you look at the Ruby LSP channel in VS Code's Output tab, is there any information about what error occurred? Did it fail to parse the JSON?

@SaidRasinlic
Copy link
Author

Thank you for the bug report! The second option is the right approach, just pushing something into the PATH.

It looks like the output was a bit too long for the VS Code dialogue box. I can't see what the actual error was, just parts of the JSON.

If you look at the Ruby LSP channel in VS Code's Output tab, is there any information about what error occurred? Did it fail to parse the JSON?

Not really, it only outputs this:

2023-11-10 18:29:13.455 [info] Trying to activate Ruby environment with command: PATH=C:\Ruby32-x64\bin;%PATH% && ruby -rjson -e "STDERR.printf('%s', JSON.dump({ 'RUBY_ENV_ACTIVATE' => { 'env' => ENV.to_h, 'ruby_version' => RUBY_VERSION, 'yjit' => defined?(RubyVM::YJIT) } }))" && ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE},
JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))" inside directory: c:\Users\Said\Documents\VSCodeProjects\student_registration_system

I also tried to reinstall Ruby LSP but it's not working still..

Interesting: If I manually run this command _ruby -rjson -e "STDERR.printf('%s', JSON.dump({ 'RUBY_ENV_ACTIVATE' => { 'env' => ENV.to_h, 'ruby_version' => RUBY_VERSION, 'yjit' => defined?(RubyVM::YJIT) } }))"_ inside of C:\Ruby32-x64\bin\ruby.exe I get an error that closes the prompt so fast that I had to record it on my phone and then find out what it is, and it says this:
Screenshot_20231110_184131_com huawei himovie overseas

@W4RH4WK
Copy link

W4RH4WK commented Nov 12, 2023

Currently encountering the same issue. Is there a workaround, or a way to provide more information on the issue?

OS: Windows 10
Code editor: VSCode
Ruby version: 3.2.2
Version manager: none (Ruby installed via RubyInstaller)

@sandrosilveira
Copy link

sandrosilveira commented Nov 13, 2023

Same error here, seems to be started after update VsCode from 1.83 to 1.84.

I tried to create a Custom batch file to configure the PATH to my customized ruby wrapper, but seems that isn't running it.

the output is:

Failed to activate custom environment: Command failed: s:\bat\CustomRubyPath.bat && ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE},
JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))"
-e:1: syntax error, unexpected end-of-input, expecting ')'
...V_ACTIVATE%sRUBY_ENV_ACTIVATE},
... ^
-e: compile error (SyntaxError)

@W4RH4WK
Copy link

W4RH4WK commented Nov 15, 2023

Note: extension version 0.4.13 does not have this error.

@lukehowlett97
Copy link

I am struggling too:

Everytime I boot up vscode I get this error:

Failed to activate custom environment: Command failed: && ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))" && was unexpected at this time.

Spent hours troubleshooting with chatgpt and still no success. Any help appreciated

@vinistock
Copy link
Member

The changes in Shopify/vscode-ruby-lsp#904 should fix this issue. Thank for reporting.

@vinistock
Copy link
Member

Version v0.4.18 should fix this. Please let us know if you find any other issues.

@sandrosilveira
Copy link

works fine!!!!

2023-11-20 13:28:02.521 [info] Trying to activate Ruby environment with command: s:\bat\CustomRubyPath.bat && ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))" inside directory: s:\BAT
2023-11-20 13:28:16.445 [info] Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: (bundle check || bundle install) 1>&2
2023-11-20 13:28:18.105 [info] Resolving dependencies...
2023-11-20 13:28:18.322 [info] The Gemfile's dependencies are satisfied
2023-11-20 13:28:24.916 [info] Starting Ruby LSP v0.12.3...
2023-11-20 13:28:25.014 [info] Ruby LSP is ready

@SaidRasinlic
Copy link
Author

SaidRasinlic commented Nov 20, 2023

The changes in Shopify/vscode-ruby-lsp#904 should fix this issue. Thank for reporting.

Yay!!! It works 💯 🔥

A small note but important: If anyone receives error like "Failed to activate custom environment: Unexpected non-whitespace character after JSON at position 4" please make sure to fix your customRubyCommand in settings.json to this:

"rubyLsp.rubyVersionManager": "custom", "rubyLsp.customRubyCommand": "PATH=C:\\Ruby32-x64\\bin;%PATH%",

So customRubyCommand goes without STDERR.printf('%s', JSON.dump(...)) error stream...

And if that doesn't work, use this approach and it should work fine:
"rubyLsp.customRubyCommand": "PATH=C:\\Ruby32-x64\\bin;%PATH% && ruby -rjson -e \"puts({ 'RUBY_ENV_ACTIVATE' => { 'env' => ENV.to_h, 'ruby_version' => RUBY_VERSION, 'yjit' => defined?(RubyVM::YJIT) } }.to_json)\""

In this case we used puts({ ... }.to_json) approach instead of STDERR.printf('%s', JSON.dump(...))
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants