Shopify / ruby-lsp

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

Failed to activate asdf environment #1999

Open davijonm opened 2 weeks ago

davijonm commented 2 weeks ago

Vscode, asdf and Ruby LSP are all in the latest versions

  1. Start the Ruby LSP using vs code
  2. Open a Ruby file
  3. Try to Ruby LSP: Start
  4. Shows the error ailed to activate asdf environment: Unexpected token '/', "/bin/sh: 2"... is not valid JSON Screenshot from 2024-05-01 13-17-02 Screenshot from 2024-05-01 13-19-16

Code snippet or error message VS code message: Failed to activate asdf environment: Unexpected token '/', "/bin/sh: 2"... is not valid JSON

andyw8 commented 2 weeks ago

:wave: This seems like the same issue as https://github.com/Shopify/ruby-lsp/issues/1990 which was solved by updating asdf. What version of asdf is in use?

davijonm commented 2 weeks ago

Latest version

Captura de tela 2024-05-01 141209

andyw8 commented 2 weeks ago

Thanks. And how was asdf installed?

vinistock commented 2 weeks ago

In the latest release, we start printing invalid JSON environments to the output tab to make this type of problem easier to diagnose. Could you please give it a try and report what the extension tried to parse as the environment?

davijonm commented 2 weeks ago

here it is:

Screenshot from 2024-05-02 12-26-21

and the file is there:

Screenshot from 2024-05-02 12-28-21

vinistock commented 2 weeks ago

Based on what I could gather, it seems that /bin/sh (the default shell used when calling exec) doesn't support the [[ ]] syntax on all operating systems. I assume you're using some other shell in your terminal and not /bin/sh, otherwise you'd see the problem there as well.

I think we can try to run exec with the shell identified by VS Code, which I'm exploring on this PR https://github.com/Shopify/ruby-lsp/pull/2006.

@davijonm it would be extremely helpful if you could confirm that this fixes the issue. You can do so by following these steps:

  1. Clone the project
  2. Switch to the branch in the PR or apply the changes manually (since it's only a few changes)
  3. Install dependencies (cd vscode && yarn install)
  4. Open our custom workspace by clicking on the workspace file and then click the button open workspace
  5. In the Run and debug panel, select the task Run extension and click start. This will open a second VS Code window where the development version of the extension is running
  6. In the second window, did the Ruby LSP launch properly with the changes in the branch?
davijonm commented 2 weeks ago

Ok, did all the steps. In the step 5, it opened a second window with this error bellow: Screenshot from 2024-05-02 20-26-25

davijonm commented 2 weeks ago

I use zsh but asdf is set in both .zshrc and .bashrc files

vinistock commented 1 week ago

Not sure why it still used /bin/sh. I pushed https://github.com/Shopify/ruby-lsp/pull/2006 to fallback to process.env.SHELL and added a print so that we can inspect the values. If you don't mind giving it another try, I'd like to understand if vscode.env.shell is not set for you.

davijonm commented 1 week ago

Here is the result Screenshot from 2024-05-03 17-43-50

davijonm commented 6 days ago

Hey guys, any updates?

andyw8 commented 6 days ago

@davijonm we're still investigating. For now, you can downgrade to v0.5.19 of the extension to switch to the older activation approach.