jorgebucaran / nvm.fish

The Node.js version manager you'll adore, crafted just for Fish
https://git.io/nvm.fish
MIT License
2.06k stars 69 forks source link

Does not handle env variables at startup in VSCode environment (OSX) #203

Closed termosa closed 1 year ago

termosa commented 1 year ago
set --universal nvm_default_version v18.4.0

While this code does what it is meant to do in the regular Terminal app in OSX, it does not make the plugin choose the default node version in the VSCode terminal (configured to use fish).

I'm not sure if this is the plugin, fish, or VSCode problem but maybe somebody here can address me.

VSCode: 1.75.0 (Universal) Fish: 3.6.0

CleanShot 2023-02-22 at 20 34 49@2x
termosa commented 1 year ago

Killing all VSCode processes has helped Sometimes you just need to restart tools 🤷

termosa commented 1 year ago

But now the system node has priority over the nvm version

CleanShot 2023-02-22 at 20 49 02@2x
jorgebucaran commented 1 year ago

Only in VSCode?

treykasada commented 1 year ago

I've just set up a new MacBook and I might be having the same problem in WebStorm. 😞

I tried checking the environment in both my regular terminal and the WebStorm integrated terminal, and it looks like nvm isn't being loaded at all in WebStorm:

WebStorm integrated terminal

> ps -f | string match --all '*fish*'

  502  3935  3872   0  3:51PM ttys000    0:00.03 /opt/homebrew/bin/fish --login -i
> set --show | string match --all '*nvm*'

Regular terminal

> ps -f | string match --all '*fish*'

  502  2318  2316   0  3:29pm ttys000    0:00.90 /opt/homebrew/bin/fish --login --init-command printf '\x1b\x50\x24\x647b22686f6f6b223a2022496e69745368656c6c222c202276616c7565223a207b227368656c6c223a202266697368227d7d\x9c'
> set --show | string match --all '*nvm*'

$PATH[1]: |/Users/username/.local/share/nvm/v18.14.2/bin|
$_fisher_jorgebucaran_2F_nvm_2E_fish_files: set in universal scope, unexported, with 7 elements
$_fisher_jorgebucaran_2F_nvm_2E_fish_files[1]: |~/.config/fish/functions/_nvm_index_update.fish|
$_fisher_jorgebucaran_2F_nvm_2E_fish_files[2]: |~/.config/fish/functions/_nvm_list.fish|
$_fisher_jorgebucaran_2F_nvm_2E_fish_files[3]: |~/.config/fish/functions/_nvm_version_activate.fish|
$_fisher_jorgebucaran_2F_nvm_2E_fish_files[4]: |~/.config/fish/functions/_nvm_version_deactivate.fish|
$_fisher_jorgebucaran_2F_nvm_2E_fish_files[5]: |~/.config/fish/functions/nvm.fish|
$_fisher_jorgebucaran_2F_nvm_2E_fish_files[6]: |~/.config/fish/conf.d/nvm.fish|
$_fisher_jorgebucaran_2F_nvm_2E_fish_files[7]: |~/.config/fish/completions/nvm.fish|
$_fisher_plugins[2]: |jorgebucaran/nvm.fish|
$nvm_current_version: set in global scope, exported, with 1 elements
$nvm_current_version[1]: |v18.14.2|
$nvm_data: set in universal scope, unexported, with 1 elements
$nvm_data[1]: |/Users/username/.local/share/nvm|
$nvm_default_version: set in universal scope, unexported, with 1 elements
$nvm_default_version[1]: |lts|
$nvm_mirror: set in universal scope, unexported, with 1 elements
$nvm_mirror[1]: |https://nodejs.org/dist|

This is a fresh setup. Fish installed via Homebrew.

treykasada commented 1 year ago

Ugh, scratch that. Disabling Shell integration in WebStorm seems to fix the problem: image No idea what that's doing to prevent nvm from loading. 🤷

treykasada commented 1 year ago

Ahh, but WebStorm unfortunately still can't auto-detect the path to the node executable. 😞 image Probably need something like NVM_SYMLINK_CURRENT for that, but that's a separate feature request.

jorgebucaran commented 1 year ago

Are you using nvm.fish or nvm.sh?

treykasada commented 1 year ago

nvm.fish

jorgebucaran commented 1 year ago

Is Fish your main shell? Is Web Storm configured to use Fish as its default shell?

treykasada commented 1 year ago

Yep and yep. 🙂

jorgebucaran commented 1 year ago

And this problem only occurs inside Web Storm? At this point, I'd have to look at your config.fish.

treykasada commented 1 year ago

Tbh WebStorm is the only editor I have installed right now, so I'm honestly not sure if this is a WebStorm-specific issue. 🤷

For config.fish though:

> cat ~/.config/fish/config.fish

if status is-interactive
    # Commands to run in interactive sessions can go here
end

Is it supposed to have more in it?

jorgebucaran commented 1 year ago

No, you are not supposed to have anything in it specifically for nvm.fish, I was just wondering if there might be something in there conflicting with nvm.fish, but that doesn't appear to be the case.

Can you reproduce the issue outside Web Storm, i.e. in your terminal?

treykasada commented 1 year ago

Terminal is fine; both nvm install/use and $nvm_default_version seem to work as expected. 👍

termosa commented 1 year ago

I still have it in VSCode (also with shell integration enabled). Does it count as the case outside of WebStorm?

termosa commented 1 year ago

Temporarily fixed it for me:

code $__fish_config_dir/config.fish                 
    if status is-interactive
        # Commands to run in interactive sessions can go here
+       nvm use > /dev/null 2>&1
    end
treykasada commented 1 year ago

Including nvm use in config.fish unfortunately doesn't solve the problem for WebStorm - it's still unable to automatically find the node path. 😢

I did some further investigation:

If I have nvm use in config.fish, leave Shell integration disabled (as mentioned above), and open WebStorm's integrated terminal, I see a "Now using Node v..." message. So config.fish is at least running when opening WebStorm's terminal. But that doesn't seem to help with the IDE's auto-detection of node. 🤷

Interestingly, if I have nvm use in config.fish, re-enable Shell integration, and open WebStorm's integrated terminal, I see an "Can't use Node ..., version must be installed first" error instead, even if that Node version is installed. So something about WebStorm's Shell integration is preventing nvm from accessing its installed node versions. Not sure if that's related to the node path auto-detection issues or not.

connorjs commented 1 year ago

I'm not sure if this is the plugin, fish, or VSCode problem but maybe somebody here can address me.

This seems to be IDE side. I also am having issues (WebStorm for me). I normally have just accepted workarounds as reality but spent a good hour debugging random stuff today related to this. Some findings (no solutions)

🤷🏻‍♂️

jorgebucaran commented 1 year ago

I suggest addressing the first issue on your list to start with. Fish should work consistently with WebStorm, rather than sporadically. For what it's worth, I use Visual Studio Code and have not encountered any problems.

jorgebucaran commented 1 year ago

I'm going to mark this as stale and close it, as it doesn't seem to be directly related to nvm.fish. Let me know if you have any other questions. Thanks!