jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
10.21k stars 293 forks source link

Docs: Further details on how to make VScode extensions that require PATH binaries, function properly with rtx installed #972

Open ELLIOTTCABLE opened 1 year ago

ELLIOTTCABLE commented 1 year ago

Describe the bug The docs mention the following for VScode support:

IDEs work better with shims than they do environment variable modifications. The simplest way is to add the rtx shim directory to PATH.

For IntelliJ and VSCode—and likely others, you can modify ~/.zprofile with the following:

export PATH="$HOME/.local/share/rtx/shims:$PATH"

Unfortunately, that doesn't seem to be enough, in a lot of cases — that can only help when extensions setup a login-shell to evaluate a command; but my experience has been that plenty of extensions don't do so.

For example, since switching to an rtx-managed opam binary, the vscode-ocaml-platform extension is unable to find it; displaying this in the VScode "Output" pane:

$ opam exec --switch=/Users/ec/Documents/Code/ocaml-ambient-context -- ocamlc --version
/bin/sh: opam: command not found

$ opam exec --switch=/Users/ec/Documents/Code/ocaml-ambient-context -- ocamllsp --version
/bin/sh: opam: command not found

Are there any other workarounds? (ChatGPT suggested some things to do with sudo launchctl config user path /your/complete/path, but that doesn't seem like it'd work with a shell-specific, dynamic $PATH-rewriting solution like rtx?)

More details about this in the README would be great, even if it's just an additional mention of the limitations and drawbacks around this right now. (=

rtx doctor output ```console $ rtx doctor rtx version: 2023.10.2 macos-arm64 (45ff35f 2023-10-15) build: Target: aarch64-apple-darwin Features: DEFAULT, NATIVE_TLS, OPENSSL, SELF_UPDATE Built: Sun, 15 Oct 2023 23:11:35 +0000 Rust Version: rustc 1.72.1 (d5c2e9c34 2023-09-13) Profile: release shell: /bin/zsh zsh 5.9 (x86_64-apple-darwin23.0) rtx data directory: /Users/ec/.local/share/rtx rtx environment variables: RTX_CONFIG_FILE=/Users/ec/.config/rtx/config.toml RTX_NPM_DEFAULT_PACKAGES_FILE=/Users/ec/.config/rtx/default-npm-packages RTX_SHELL=zsh settings: {"always_keep_download": "false", "always_keep_install": "false", "asdf_compat": "false", "disable_default_shorthands": "false", "disable_tools": "[]", "experimental": "false", "jobs": "4", "legacy_version_file": "true", "legacy_version_file_disable_tools": "[]", "log_level": "INFO", "missing_runtime_behavior": "warn", "plugin_autoupdate_last_check_duration": "10080", "raw": "false", "trusted_config_paths": "[]", "verbose": "false", "yes": "false"} config files: /Users/ec/.config/rtx/config.toml plugins: cabal https://github.com/sestrella/asdf-ghcup.git#54e3549 deno https://github.com/asdf-community/asdf-deno.git#87442fe dotnet https://github.com/hensou/asdf-dotnet#1fab4d6 go https://github.com/kennyp/asdf-golang.git#f006a12 hls https://github.com/sestrella/asdf-ghcup.git#54e3549 java (core) jq https://github.com/azmcode/asdf-jq.git#af8cad8 lua https://github.com/Stratus3D/asdf-lua.git#6d4e66a luaJIT https://github.com/smashedtoatoms/asdf-luaJIT.git#bbfe3cd node https://github.com/rtx-plugins/rtx-nodejs.git#946dc23 opam https://github.com/asdf-community/asdf-opam.git#5e88c73 php https://github.com/asdf-community/asdf-php.git#1eaf4de postgres https://github.com/smashedtoatoms/asdf-postgres.git#fd8d5aa purescript https://github.com/nsaunders/asdf-purescript.git#24813a0 python https://github.com/rtx-plugins/rtx-python.git#2b29b16 racket https://github.com/asdf-community/asdf-racket.git#a1bdfe4 ruby https://github.com/rtx-plugins/rtx-ruby.git#e0728ce rust https://github.com/code-lever/asdf-rust.git#0c88f99 toolset: deno@latest, dotnet@latest, go@latest, jq@latest, lua@latest, node@latest, opam@latest, postgres@latest, purescript@latest, python@latest, racket@latest, ruby@latest, rust@latest No problems found ```
jdx commented 1 year ago

well there is /etc/paths but I'm not sure that's better since it's system-wide—also not sure if it works or not. I'm not sure what the best way to set paths for IDEs is

jylenhof commented 11 months ago

this could help :

https://github.com/microsoft/vscode/issues/7263

ELLIOTTCABLE commented 11 months ago

Unfortunately, that's only helpful for the terminal, yes? The main issue (since there's lots/various ways to get shell integration working as expected) is that the parent process, the GUI program itself, doesn't have the correct $PATH; and when extensions and whatnot invoke commands, they don't do them thru a login-shell.

(i.e. this Issue is not about the integrated terminal, but rather about other parts of IDEs that run commands / use the $PATH.)

jylenhof commented 11 months ago

That's a little gruick but on my linux /usr/bin/code is a link to a shell /usr/share/code/bin/code Perhaps you can modify this script to add some RTX PATH in it...

Another mean is to make an alias to code with export RTX PATH with something like : alias code='export PATH=/toto:$PATH; code'

mscrivo commented 7 months ago

Running into this as well. I have mise activated with shims in my ~./zshrc and that works great in iterm2 and RubyMine's terminal. However VSCode is behaving very strange. It won't use the shims if there are versions found elsewhere in the PATH. For example, if I have a node version installed with brew, it will chose to use that. If I delete it, then it will use the mise version. However, for ruby it's a bit more difficult. It insists on using my system ruby at /usr/bin/ruby, which can't be deleted/moved. The only way I've found to fix that is to set the following in VSCode's settings:

"terminal.integrated.inheritEnv": false,

however, that doesn't fix launch.json profiles. Previously with rbenv I had a debug config like this:

  "configurations": [
      {
          "type": "rdbg",
          "name": "Debug current file with rdbg",
          "request": "launch",
          "rdbgPath": "~/.rbenv/shims/rdbg",
          "script": "${file}",
          "env": {
              "VSCODE_DEBUG": "true"
          },
          "args": [],
          "askParameters": true
      },
  ]

which worked great, but I can't for the life of me get it to work with mise. Even if I update the rdbgpath to mise's version, it keeps wanting to use the system ruby to launch it:

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': can't find gem debug (>= 0.a) with executable rdbg (Gem::GemNotFoundException)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
    from /Users/michaelscrivo/.local/share/mise/installs/ruby/3.3.0/bin/rdbg:25:in `<main>'

Error: /bin/zsh -lic '~/.local/share/mise/shims/rdbg --version': exit code is 1

Any suggestions on how to get it to work would be very welcome. Thanks

mscrivo commented 7 months ago

So I think I have a guess at what's happening. With inheritEnv on, we're running into this issue: https://github.com/microsoft/vscode/issues/33077 ... in that case, mise activate is not putting the shims at the beginning of the path because of all the duplicates, and so it's finding ruby in another location.

If instead of using:

eval "$(/opt/homebrew/bin/mise activate zsh --shims)"

I just modify the path directly in my .zshrc, like so:

export PATH="/Users/Username/.local/share/mise/shims:$PATH"

then all works great. Is there any downside to doing that? does the mise activate --shims doing anything beyond that?

hverlin commented 3 days ago

AFAIK, most extension will allow you to configure the path. For example, with the ocaml one, you need to configure the path to a sandbox for example: (in your workspace settings.json)

    "ocaml.sandbox": {
        "kind": "custom",
        "template": "/Users/dev/.opam/5.2.1/bin/$prog $args"
    }

I am supporting configuring a few extensions automatically with this extension: https://github.com/hverlin/mise-vscode (there is a similar one for intelliJ). As far as I can see, it does not seem to be needed for opam as you need to input it manually?

I have noticed that a few lsp servers got automatic support like ruby-lsp/elixir-lsp. mise seems popular enough now that it is worth it for an extension to detect it automatically in the common places where it's installed.