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 on asdf >= 0.16.0: "Automatic Ruby environment activation with asdf failed: Could not find ASDF installation" #3143

Closed
rubyroobs opened this issue Feb 6, 2025 · 10 comments · Fixed by #3185
Labels
bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes

Comments

@rubyroobs
Copy link

rubyroobs commented Feb 6, 2025

TL;DR and workaround

The new golang rewrite of the asdf package manager no longer has an initialization shell script, which breaks the Ruby LSP extension as it does not handle the case of asdf already being in the PATH as an executable binary.

This can be fixed for the time being by just making an empty executable shell script in place of it with this one-liner:

mkdir -p $HOME/.asdf/ && touch $HOME/.asdf/asdf.sh && chmod +x $HOME/.asdf/asdf.sh

So far everything has been working as usual for me after doing this.

Ruby LSP Information

VS Code Version

1.96.4

Ruby LSP Extension Version

0.8.20

Ruby LSP Server Version

0.23.8

Ruby LSP Add-ons

Ruby Version

3.3.7

Ruby Version Manager

asdf

Installed Extensions

Click to expand
  • EditorConfig (0.16.4)
  • black-formatter (2024.4.0)
  • catppuccin-vsc (3.16.0)
  • catppuccin-vsc-icons (1.17.0)
  • code-spell-checker (4.0.34)
  • dart-code (3.104.0)
  • debugpy (2024.14.0)
  • flutter (3.104.0)
  • gitlab-workflow (5.38.0)
  • go (0.44.0)
  • haml (1.4.1)
  • isort (2023.10.1)
  • json (0.1.2)
  • jupyter (2024.11.0)
  • jupyter-keymap (1.1.2)
  • jupyter-renderers (1.1.0)
  • luahelper (0.2.29)
  • makefile-tools (0.11.13)
  • markdown-preview-github-styles (2.1.0)
  • material-icon-theme (5.19.0)
  • postcss (1.0.9)
  • powershell (2025.0.0)
  • prettier-vscode (11.0.0)
  • pylint (2024.0.0)
  • python (2024.22.2)
  • rails-snippets (1.0.8)
  • remote-containers (0.394.0)
  • remote-explorer (0.4.3)
  • remote-ssh (0.116.1)
  • remote-ssh-edit (0.87.0)
  • ruby-lsp (0.8.20)
  • rust-analyzer (0.3.2291)
  • solargraph (0.24.1)
  • sorbet-vscode-extension (0.3.37)
  • terraform (2.34.3)
  • test-adapter-converter (0.2.1)
  • todo-tree (0.0.226)
  • vale-vscode (0.20.0)
  • vs-code-prettier-eslint (6.0.0)
  • vscode-axe-linter (4.10.3)
  • vscode-bazel (0.11.0)
  • vscode-colorize (0.16.0)
  • vscode-docker (1.29.4)
  • vscode-dotnet-runtime (2.2.6)
  • vscode-eslint (3.0.10)
  • vscode-html-css (2.0.13)
  • vscode-kubernetes-tools (1.3.20)
  • vscode-lldb (1.11.3)
  • vscode-markdownlint (0.58.2)
  • vscode-pylance (2025.2.1)
  • vscode-rdbg (0.2.2)
  • vscode-rubocop (0.7.0)
  • vscode-ruby-test-adapter (0.9.2)
  • vscode-stylelint (1.4.0)
  • vscode-test-explorer (2.22.1)
  • vscode-yaml (1.15.0)

Ruby LSP Settings

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

Reproduction steps

  1. Upgrade to asdf >= 0.16.0
  2. Observe error with automatic asdf location resolution

Code snippet or error message

Automatic Ruby environment activation with asdf failed: Could not find ASDF installation. Searched in file:///Users/ruby/.asdf/asdf.sh, file:///opt/asdf-vm/asdf.sh, file:///opt/homebrew/opt/asdf/libexec/asdf.sh, file:///usr/local/opt/asdf/libexec/asdf.sh
@rubyroobs rubyroobs added bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes labels Feb 6, 2025
@davidwessman
Copy link

Thank you for the workaround 🙌🏻

@andyw8
Copy link
Contributor

andyw8 commented Feb 6, 2025

@vinistock
Copy link
Member

Thank you for the report. Since we still need to support old versions while people are migrating, I believe we can implement finding the asdf executable and then falling back to the old behaviour if nothing is found.

It would essentially mean:

  1. Looking for the asdf executable similar to what we do for rbenv
  2. If it was found, then we should change the command. Instead of sourcing it, we can just invoke asdf exec ruby in the activation directly
  3. If it was not found, then we fallback to the original implementation

Where is the new ASDF executable installed? We're going to need to search for it for Homebrew installations, but also take Linux into account.

@rubyroobs
Copy link
Author

Where is the new ASDF executable installed? We're going to need to search for it for Homebrew installations, but also take Linux into account.

It could be installed anywhere in the PATH and is explicitly documented as such for the "install pre-compiled binary" option in the new Getting Started guide.

Extract the asdf binary in the archive into a directory on your $PATH.

I think a better approach here is to just detect if the command exists or not, and only fall back to loading the script if it doesn't.

@vinistock
Copy link
Member

It's not enough to just search the PATH. If VS Code is launched from the icon instead of using code . in the terminal, it will not inherit the environment present in the shell and the NodeJS will not be aware of certain PATH modifications the user might have made in scripts.

Preferably, we should have a list of common paths we search first, as we do for the other version managers. Typically, that's Homebrew paths for Mac and the usual apt paths for Linux. Then if we can't find it, we hope that it's present in the PATH.

We also already let users configure the path to the ASDF executable, which offers an escape hatch, but we should still automatically search the most common places.

The current possible paths we search is here (for the script version of ASDF).

If people could please confirm the paths to the asdf executable for the same scenarios, that'd be very helpful:

  1. Git
  2. Pacman
  3. Homebrew M series
  4. Homebrew Intel series

@zarembas
Copy link

zarembas commented Feb 7, 2025

On homebrew M series I'm getting /opt/homebrew/bin/asdf

@jfouse
Copy link

jfouse commented Feb 8, 2025

I have the same path as @zarembas for homebrew M series. Just to confirm, OP's workaround does work for me but the following does not:

"rubyLsp.rubyVersionManager": {
    "asdfExecutablePath": "/opt/homebrew/bin/asdf",
    "identifier": "asdf"
},

@jverce
Copy link

jverce commented Feb 12, 2025

To add some info to the last comment, when setting "asdfExecutablePath": "/opt/homebrew/bin/asdf", I get the following error:

Automatic Ruby environment activation with asdf failed: Command failed: . /opt/homebrew/bin/asdf && asdf exec ruby -EUTF-8:UTF-8 '/Users/jay/.vscode/extensions/shopify.ruby-lsp-0.9.3/activation.rb' /opt/homebrew/bin/asdf:4: parse error near `)'

Image

@tbsvttr
Copy link

tbsvttr commented Feb 12, 2025

/opt/homebrew/bin/asdf

But that is a binary, not a shell script (as ruby-lsp seems to expect). Which is why this does not work:

To add some info to the last comment, when setting "asdfExecutablePath": "/opt/homebrew/bin/asdf", I get the following error:

Automatic Ruby environment activation with asdf failed: Command failed: . /opt/homebrew/bin/asdf && asdf exec ruby -EUTF-8:UTF-8 '/Users/jay/.vscode/extensions/shopify.ruby-lsp-0.9.3/activation.rb' /opt/homebrew/bin/asdf:4: parse error near `)'

Image

But this does:

TL;DR and workaround

The new golang rewrite of the asdf package manager no longer has an initialization shell script, which breaks the Ruby LSP extension as it does not handle the case of asdf already being in the PATH as an executable binary.

This can be fixed for the time being by just making an empty executable shell script in place of it with this one-liner:

mkdir -p $HOME/.asdf/ && touch $HOME/.asdf/asdf.sh && chmod +x $HOME/.asdf/asdf.sh
So far everything has been working as usual for me after doing this.

Ruby LSP Information

VS Code Version

1.96.4

Ruby LSP Extension Version

0.8.20

Ruby LSP Server Version

0.23.8

Ruby LSP Add-ons

Ruby Version

3.3.7

Ruby Version Manager

asdf

Installed Extensions

Click to expand

Ruby LSP Settings

Click to expand

Reproduction steps

  1. Upgrade to asdf >= 0.16.0
  2. Observe error with automatic asdf location resolution

Code snippet or error message

Automatic Ruby environment activation with asdf failed: Could not find ASDF installation. Searched in file:///Users/ruby/.asdf/asdf.sh, file:///opt/asdf-vm/asdf.sh, file:///opt/homebrew/opt/asdf/libexec/asdf.sh, file:///usr/local/opt/asdf/libexec/asdf.sh

@vinistock
Copy link
Member

The changes in #3185 should add proper support for v0.16.

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.

8 participants