jdx / mise

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

Cannot use installed version of Go from Mise in VS Code #2270

Open assembly-winston opened 3 weeks ago

assembly-winston commented 3 weeks ago

It gives me the below error message:

Failed to run '/opt/homebrew/Cellar/mise/2024.6.2/bin/mise env. The config change may not be applied correctly.

2024-06-08 23:39:55.745 [info] Failed to run '/opt/homebrew/Cellar/mise/2024.6.2/bin/mise env' (cwd: /Users/winston/Developer/assembly/search-server): Error: Command failed: /opt/homebrew/Cellar/mise/2024.6.2/bin/mise env -json GOPATH GOROOT GOPROXY GOBIN GOMODCACHE
error: unexpected argument '-j' found
roele commented 3 weeks ago

VS Code should be looking for the go binary and not mise. Correctly configured, VS Code should show something like "go.goroot setting (/Users/USER/.local/share/mise/installs/go/latest) will be applied and set the GOROOT environment variable."

So you should either have go installed and available globally or for your project. Usually in VS Code you point the plugin to the installed tool in ~/.local/share/mise/installs/<TOOL>/<VERSION>. Additionally to get binaries working reliably in IDEs you might need to enable shims ($HOME/.local/share/mise/shims) by adding them to your PATH (also see https://mise.jdx.dev/dev-tools/shims.html)

Please attach the output of mise doctor for a more detailed answer regarding your current setup.

assembly-winston commented 3 weeks ago
❯ mise doctor
version: 2024.6.2 macos-arm64 (87957bc 2024-06-07)
activated: yes
shims_on_path: no

build_info:
  Target: aarch64-apple-darwin
  Features: DEFAULT, NATIVE_TLS, OPENSSL
  Built: Fri, 7 Jun 2024 02:14:15 +0000
  Rust Version: rustc 1.78.0 (9b00956e5 2024-04-29)
  Profile: release

shell:
  /bin/zsh
  zsh 5.9 (x86_64-apple-darwin23.0)

dirs:
  data: ~/.local/share/mise
  config: ~/.config/mise
  cache: ~/Library/Caches/mise
  state: ~/.local/state/mise
  shims: ~/.local/share/mise/shims

config_files:
  ~/.tool-versions
  ~/.config/mise/config.toml

backends:
  cargo
  core
  go
  npm
  pipx
  spm
  ubi

plugins:
  bun     (core)
  deno    (core)
  erlang  (core)
  go      (core)
  java    (core)
  node    (core)
  python  (core)
  ruby    (core)

toolset:
  bun@1.1.10            (missing)
  zig@0.13.0            (missing)
  go@1.22.4
  rust@latest           (missing)
  ruby@3.2.2            (missing)
  node@21.6.1           (missing)
  java@temurin-22.0.1+8  (missing)

env_vars:
  MISE_SHELL=zsh

settings:
  activate_aggressive = false
  all_compile = false
  always_keep_download = false
  always_keep_install = false
  asdf_compat = false
  cargo_binstall = true
  color = true
  disable_default_shorthands = false
  disable_tools = []
  experimental = false
  go_default_packages_file = "~/.default-go-packages"
  go_download_mirror = "https://dl.google.com/go"
  go_repo = "https://github.com/golang/go"
  go_set_gopath = false
  go_set_goroot = true
  go_skip_checksum = false
  http_timeout = 30
  jobs = 4
  legacy_version_file = true
  legacy_version_file_disable_tools = []
  node_compile = false
  not_found_auto_install = true
  paranoid = false
  plugin_autoupdate_last_check_duration = "7d"
  python_default_packages_file = "/Users/winston/.default-python-packages"
  python_pyenv_repo = "https://github.com/pyenv/pyenv.git"
  raw = false
  trusted_config_paths = []
  quiet = false
  verbose = false
  yes = false
  ci = false
  debug = false
  trace = false
  log_level = "info"
  python_venv_auto_create = false

  [status]
  missing_tools = "if_other_versions_installed"
  show_env = false
  show_tools = false

No warnings found
No problems found
assembly-winston commented 3 weeks ago

The failed to run opt/homebrew thing was something VS Code pulled on its own, not something i pointed it to. Not sure why that happens.

I also ran the directives in the linked page, now it says shims on path, but VS Code doesn't work unless i manually point goroot to the installs/ subfolder, which means I'd have to update the path each time I change the go version in mise.

vrslev commented 3 weeks ago

Hey there!

I fixed the issue of discovering of binaries that mise provides with using mise hook-env: https://github.com/vrslev/dotfiles/blob/55f02dda0b357ec71edf3b11c49a5e4ec3e60f62/config/fish/conf.d/0-login.fish#L26

vrslev commented 3 weeks ago

The approach recommended in the docs didn’t work. @jdk maybe we should update the docs?

roele commented 3 weeks ago

@vrslev I use Go in VS Code via mise without any issues but my setup might differ a bit.

  1. I activate mise myself and have the shims on my PATH
    
    set -Ux MISE_FISH_AUTO_ACTIVATE 0

if type -q mise fish_add_path -m $HOME/.local/share/mise/shims mise activate --quiet fish | source set -x MISE_USE_TOML 1 else echo 'mise not found, see https://mise.jdx.dev for installation instructions' return 1 end

2. I set `go.gopath` and `go.goroot` in VS Code (Profile) Settings (also works without this settings)
```json
{

"go.gopath": "~/.local/share/mise/installs/go/latest/pgk",
"go.goroot": "~/.local/share/mise/installs/go/latest",

}
vrslev commented 3 weeks ago

Yes, I was trying to solve a different problem.

With mise activate --shims recommended by the documentation, VS Code failed to detect binaries provided by mise. It works if I add mise hook-env instead, thus I suggested updating it.

nickchomey commented 2 weeks ago

What worked for me, after endless trial and error, was the following (when using default bash terminal in VS Code Ubuntu WSL2)

  1. add eval "$($HOME/.local/bin/mise activate bash --shims)" to $HOME/.bash_profile. This seems to run for non-interactive terminals (which is what is running behind the scenes in VS Code - be it normally or in a debug session)
  2. add eval "$($HOME/.local/bin/mise activate bash)" to $HOME/.bashrc, to add mise to $PATH when you've opened an interactive bash terminal. The shims path will be in $PATH as well because .bash_profile runs before .bashrc, but it will be further down the list and shouldn't end up getting called.