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 none environment: Command failed: ruby -rjson -e ... compile error (SyntaxError) #1708

Closed
1 task done
PaulScorthorne opened this issue Nov 10, 2023 · 8 comments · Fixed by Shopify/vscode-ruby-lsp#904
Labels
bug Something isn't working transferred This issue was transferred from vscode-ruby-lsp

Comments

@PaulScorthorne
Copy link

Operating System

Windows 10

Ruby version

3.2.2

Project has a bundle

  • Has bundle

Ruby version manager being used

no manager

Description

I have been running Ruby LSP in VS Code for a short while (after the deprecation of the previous Ruby extension), but when I came back to it this morning upon opening my first .rb file I was greeted with:

Failed to activate none 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) }))" -e:1: syntax error, unexpected end-of-input, expecting ')' ...V_ACTIVATE%sRUBY_ENV_ACTIVATE}, ... ^ -e: compile error (SyntaxError)

I've run through all the steps on https://github.com/Shopify/vscode-ruby-lsp#troubleshooting without success.

I also noted #1711, but my Path does not contain any spaces. It is simply C:\Ruby32-x64\bin

Running 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) }))" in a terminal returns the JSON block it appears to be after quite happily, including the appropriate "ruby_version":"3.2.2"

The rest of my system knows where Ruby is, what version it is, installs and runs gems, etc. I am fundamentally stumped on what the issue is or where it might have come from.

I have the latest version of the ruby-lsp gem installed, 0.21.3, and the above is the same on the VSCode Release 0.4.17 and Pre-Release 0.5.0 versions.

I also attempted to define a custom activation as suggested in that ticket anyway, following the instructions at https://github.com/Shopify/vscode-ruby-lsp/blob/main/VERSION_MANAGERS.md#custom-activation, but that just led to a different error:

Failed to activate custom environment: Command failed: PATH=C:\Ruby32-x64\bin:$PATH && 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) }))" 'ruby' is not recognized as an internal or external command, operable program or batch file.

I tried every variation of "C:\Ruby32-x64\bin" I could think of (double slashed, reverse slashed, trailing slashes, relative paths, etc) all to the same result.

Happy to provide any additional info or try other potential troubleshooting steps.

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

Thank you for the bug report! I suspect that the extension is not finding the right Ruby version. Since you have no version manager, you'll indeed need to use the custom activation to insert the path to Ruby in the PATH.

That said, this configuration PATH=C:\Ruby32-x64\bin:$PATH looks like Unix, which I don't believe will work on Windows.

I have no experience using Windows, but based on this StackOverlow answer it seems that you need to use set, wrap the current PATH in % and use ; as a separator.

@siesharp
Copy link

siesharp commented Nov 10, 2023

I have this error as well on Windows 11, and adding a custom activation didn't seem to fix it. I was able to fix the bug by opening the extension folder, navigating to out/extension.js, and removing the line break at the end of line 44.

EDIT: After a few minutes of running after this patch, the server begins to crash frequently; so this isn't the solution I thought.

Just to add more info in case it helps the original issue -- Ruby is in my path in Windows, and the only installed Ruby version is 3.1. I tried adding a custom activation as suggested, but the error was the exact same as if I had just used a "none" manager instead.

@melt-adzuki
Copy link

I leave this comment just to express that I have the same error. I use Ruby 3.2.2 installed via RubyInstaller2 on Windows 11 (no extra managers installed), getting the same error:

Failed to activate none 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) }))" -e:1: syntax error, unexpected end-of-input, expecting ')' ...V_ACTIVATE%sRUBY_ENV_ACTIVATE}, ... ^ -e: compile error (SyntaxError)

Did recent update or something like that make this error appear?

@thumbtax
Copy link

thumbtax commented Nov 11, 2023

@vinistock, for what it's worth I ran into the same issue as well (Win10/VSCode/RubyInstaller).

When I took the command out of the error log and ran it in cmd to check against the baseline ruby install, the command failed with the same "unexpected end-of-input" syntax error @PaulScorthorne reported.
Running the same command in VS Code terminal parses and executes properly, however I noticed VS Code placed half the copied command on a second line.

Checking the command in notepad++ showed Windows newline characters (\r\n) in the command following RUBY_ENV_ACTIVATE}, .
Removing the newline characters and pasting the command into cmd then allowed the command to execute successfully.

I see the command is coming from the ruby.ts test file in this method:
activate

Is it possible the line break between RUBY_ENV_ACTIVATE}, and JSON.dump({ is being stored in the command variable as part of the string?

Just a thought.

@zhaowenquan131
Copy link

@vinistock, for what it's worth I ran into the same issue as well (Win10/VSCode/RubyInstaller).

When I took the command out of the error log and ran it in cmd to check against the baseline ruby install, the command failed with the same "unexpected end-of-input" syntax error @PaulScorthorne reported. Running the same command in VS Code terminal parses and executes properly, however I noticed VS Code placed half the copied command on a second line.

Checking the command in notepad++ showed Windows newline characters (\r\n) in the command following RUBY_ENV_ACTIVATE}, . Removing the newline characters and pasting the command into cmd then allowed the command to execute successfully.

I see the command is coming from the ruby.ts test file in this method: activate

Is it possible the line break between RUBY_ENV_ACTIVATE}, and JSON.dump({ is being stored in the command variable as part of the string?

Just a thought.

Just deleted this newline and the error didn't appear anymore
image

@vinistock
Copy link
Member

Folks, thank you so much for debugging and pointing us to the right direction. The changes in Shopify/vscode-ruby-lsp#904 should fix the issue 🙏.

@Ben-Garcia-DB-Solutions
Copy link

Ben-Garcia-DB-Solutions commented Nov 20, 2023

Just adding onto this that I am facing the same issue, although I'm struggling to find the ruby.ts file.

EDIT: Timing! Thanks @vinistock

@vinistock
Copy link
Member

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

@st0012 st0012 added the transferred This issue was transferred from vscode-ruby-lsp label Mar 18, 2024
@st0012 st0012 transferred this issue from Shopify/vscode-ruby-lsp Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working transferred This issue was transferred from vscode-ruby-lsp
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants