ruby-lsp icon indicating copy to clipboard operation
ruby-lsp copied to clipboard

Failed to activate asdf environment

Open davijonm opened this issue 1 year ago • 12 comments

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

davijonm avatar May 01 '24 16:05 davijonm

: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?

andyw8 avatar May 01 '24 17:05 andyw8

Latest version

Captura de tela 2024-05-01 141209

davijonm avatar May 01 '24 17:05 davijonm

Thanks. And how was asdf installed?

andyw8 avatar May 01 '24 18:05 andyw8

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?

vinistock avatar May 02 '24 15:05 vinistock

here it is:

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

and the file is there:

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

davijonm avatar May 02 '24 15:05 davijonm

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?

vinistock avatar May 02 '24 20:05 vinistock

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 avatar May 02 '24 23:05 davijonm

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

davijonm avatar May 02 '24 23:05 davijonm

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.

vinistock avatar May 03 '24 18:05 vinistock

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

davijonm avatar May 03 '24 20:05 davijonm

Hey guys, any updates?

davijonm avatar May 10 '24 19:05 davijonm

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

andyw8 avatar May 10 '24 19:05 andyw8

I just realized I made a mistake in the previous iteration of https://github.com/Shopify/ruby-lsp/pull/2006. I set the shell inside env, which isn't what I meant to do. I updated the branch to set the actual shell to vscode.env.shell.

Could you please try again and report if that fixes it?

vinistock avatar May 27 '24 19:05 vinistock

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 #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?

Ok, I tried again. After step 5, a new window opened and apparently there was no error, but I can't tell if it worked because the main window still shows this error: /home/davi/.asdf/asdf.sh: [[: not found

Screenshot from 2024-05-28 09-04-25

davijonm avatar May 28 '24 12:05 davijonm

Never mind, I was using an unsupported Ruby version (2.5.1). I think it works correctly now after your PR.

Screenshot from 2024-05-28 09-27-34

davijonm avatar May 28 '24 12:05 davijonm