volta-cli / volta

Volta: JS Toolchains as Code. ⚡
https://volta.sh
Other
10.96k stars 230 forks source link

volta + neovim compatibility issues #866

Open stefanpenner opened 3 years ago

stefanpenner commented 3 years ago

problem

neovim cannot discover node modules installed globally by volta

investigation

nvim +checkhealth

yields:

## Node.js provider (optional)
  - INFO: Node.js: v14.15.0
  - WARNING: Missing "neovim" npm (or yarn) package.
    - ADVICE:
      - Run in shell: npm install -g neovim
      - Run in shell (if you use yarn): yarn global add neovim

Given that when using volta, npm i -g and volta global add are discouraged, i run:

volta install neovim

Which still has nvim +checkhealth yielding:

## Node.js provider (optional)
  - INFO: Node.js: v14.15.0
  - WARNING: Missing "neovim" npm (or yarn) package.
    - ADVICE:
      - Run in shell: npm install -g neovim
      - Run in shell (if you use yarn): yarn global add neovim

Investigating further, neovim's algorithm essentially looks each of the following locations:

Likely ideal solution

Add volta support to neovim? corresponding neovim issue

Workaround:

The following has volta behave as if it were yarn, which appears to address the issue in question.

volta install yarn 
rm -rf $HOME/.config/yarn/global/
mkdir -p $HOME/.config/yarn/global/
ln -s $HOME/.volta/tools/shared/ $HOME/.config/yarn/global/node_modules

yields a functional node.js provider for neovim.


## Node.js provider (optional)
  - INFO: Node.js: v14.15.0
  - INFO: Neovim node.js host: /Users/spenner/.config/yarn/global//node_modules/neovim/bin/cli.js
  - OK: Latest "neovim" npm/yarn package is installed: 4.9.0
chriskrycho commented 3 years ago

@stefanpenner which version of Volta are you using? Our recent 0.9.x releases should have (a) stopped discouraging use of npm i -g or yarn global add and (b) made this work!

charlespierce commented 3 years ago

@chriskrycho The changes in 0.9.x still didn't quite get this working. neovim itself isn't launched by Volta, so it doesn't pick up the NODE_PATH that makes the neovim package available with require. It looks (given the above-linked issue) like neovim looks in a couple of specific locations for the Node package, and Volta's custom package handling breaks those assumptions.

chriskrycho commented 3 years ago

Ahhhh, that would do it; I misunderstood the dynamics with neovim specifically. Thanks for clarifying, @charlespierce!

mainendra commented 3 years ago

@stefanpenner - You have to specify node path in neovim config (init.vim). Please add let g:node_host_prog = system('volta which neovim-node-host | tr -d "\n"') to your neovim config and try again.

stefanpenner commented 3 years ago

@mainendra that is a better workaround than the one I have listed, thank you.

That being said it would be great to make this more seamless.

In the meantime, I've changed my work-around to add the following to my init.vim based on @mainendra's suggestion:

if executable('volta')
  let g:node_host_prog = trim(system("volta which neovim-node-host"))
endif
mainendra commented 3 years ago

I think we can convert this to enhancement story.

DriesVerb commented 1 year ago

Thanks for your solutions. For me they were not 100% clear, so if anyone had the same problem. It worked with me via this:

local g = vim.g 

g["node_host_prog"] = vim.call("system", 'volta which neovim-node-host | tr -d "\n"')