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

LspInstall for pyright and intelephense fails when node packages are installed with the same name as the plugin #467

Closed
rverton opened this issue Dec 19, 2020 · 19 comments
Labels
bug Something isn't working

Comments

@rverton
Copy link

rverton commented Dec 19, 2020

  • nvim --version: v0.5.0-dev+950-g5ce328df4
  • nvim-lsp version(commit hash): 1e4a963
  • :checkhealth result: https://dpaste.com/9PFATQ2MA
  • What language server(If the problem is related to a specific language server): pyright, intelephense
  • Operating system/version: macOS Big Sur
  • Terminal name/version: iterm2
  • $TERM: xterm-256color
  • NPM version: 6.14.9

How to reproduce the problem from neovim startup

Execute :LspInstall pyright or :LspInstall intelephense.

Actual behaviour

The following error is printed (reformatted because its broken):

18 verbose stack Error: Refusing to install package with name "pyright" under a package
18 verbose stack also called "pyright". Did you name your project the same
18 verbose stack as the dependency you're installing?

The same happens when installing intelephense. Looking in the /Users/robin/.cache/nvim/lspconfig/pyright folder (which is created by the LspInstall command), there is a package.json with the following content:

{
  "name": "pyright",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

Running a npm install pyright here fails because the package name can't have the same name as the dependency I think. Executing :LspInstall tsserver works here, because the actual package which is installed is called typescript-language-server and therefore has a different name than the folder.

@rverton rverton added the bug Something isn't working label Dec 19, 2020
@mjlbach
Copy link
Contributor

mjlbach commented Dec 19, 2020

I'm not sure I understand this bug. If pyright is already installed, and you call :LspInstall pyright it fails?

@rverton
Copy link
Author

rverton commented Dec 19, 2020

Pyright/intelephense are not installed. If they would be installed, LspInstall would tell it and refuse to go on.

The LspInstall command creates a folder called “pyright”, puts a package.json in there with the name “pyright” and tries to install the module “pyright” in this I guess. Npm then refuses to do this.

@mjlbach
Copy link
Contributor

mjlbach commented Dec 19, 2020

Does npm i -g pyright not work for you?

@rverton
Copy link
Author

rverton commented Dec 20, 2020

When I install pyright manually via npm, then LSP does not work here. This is what LspInstallInfo gives me for pyright:

  pyright = {
    bin_dir = "/Users/robin/.cache/nvim/lspconfig/pyright/node_modules/.bin",
    binaries = {
      ["pyright-langserver"] = "/Users/robin/.cache/nvim/lspconfig/pyright/node_modules/.bin/pyright-langserver"
    },
    install_dir = "/Users/robin/.cache/nvim/lspconfig/pyright",
    is_installed = false
  },

The folder /Users/robin/.cache/nvim/lspconfig/pyright does not exist (when pyright is installed manually), is it the intended way that I create it and symlink pyright in there?

@mjlbach
Copy link
Contributor

mjlbach commented Dec 20, 2020

It doesn't matter where pyright is installed so long as it is in your path. LspInstallInfo just uses the built-in installer directory to check if pyright was installed via LspInstall (not that it's actually present) so this would be a false negative, but you can install pyright as a global npm package and it will work (no symlink required)

@rverton
Copy link
Author

rverton commented Dec 20, 2020

All right. So even when it is installed, I’m missing the LSP features. Is there some log or health info to see what’s wrong?

@mjlbach
Copy link
Contributor

mjlbach commented Dec 20, 2020

Are you using node15? There's a tracking issue and PR to workaround node 15 issues if you look in the tracker. To get logs you can add vim.lsp.set_log_level("debug") to your lua heredoc, and your log will be saved as $HOME/.local/share/nvim/lsp.log

@rverton
Copy link
Author

rverton commented Dec 20, 2020

@mjlbach thanks for the hint, I'm using node v15.0.1. I guess you are referring to #451.

I had a look at the lsp.log and found this:

[ ERROR ] 2020-12-20T13:18:50+0100 ] .../share/nvim-osx64/share/nvim/runtime/lua/vim/lsp/rpc.lua:455 ]	"rpc"	"pyright-langserver"	"stderr"	"Error: MethodNotFound\n    at handleResponse (/usr/local/Cellar/node/15.0.1/lib/node_modules/pyright/dist/pyright-internal/node_modules/vscode-jsonrpc/lib/common/connection.js:477:48)\n    at processMessageQueue (/usr/local/Cellar/node/15.0.1/lib/node_modules/pyright/dist/pyright-internal/node_modules/vscode-jsonrpc/lib/common/connection.js:292:17)\n    at Immediate.<anonymous> (/usr/local/Cellar/node/15.0.1/lib/node_modules/pyright/dist/pyright-internal/node_modules/vscode-jsonrpc/lib/common/connection.js:276:13)\n    at processImmediate (node:internal/timers:462:21)\n"

There is also an issue for this bug (which is all linked to the node15 bug I think). I replace my local file .vim/plugged/nvim-lspconfig/lua/lspconfig/pyright.lua with the one from your PR and it worked, awesome! I guess the easiest way is to leave this replaced file now, wait until the PR gets merged and then do a fresh pull from the master branch then?

@mjlbach
Copy link
Contributor

mjlbach commented Dec 20, 2020

Yep! You can follow that issue and pr for updates.

@mjlbach mjlbach closed this as completed Dec 21, 2020
@monooso
Copy link

monooso commented Dec 22, 2020

@mjlbach I have the same issue as the OP. The ensuing discussion didn't address the initial problem, so I think it's worth re-opening this issue.

To reiterate, Node will not install a dependency which has the same name as the package into which it's being installed. An example may help to clarify this statement.

Assume you have the following package.json:

{ "name": "intelephense" }

In this case, npm install intelephense will fail, because the dependency name conflicts with the package name.

Unfortunately, this is exactly what :LspInstall attempts to do; it creates the following ~/.cache/nvim/lspconfig/intelephense/package.json, and then attempts to install the intelephense package.

{
  "name": "intelephense",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

This seems like a bug in the behaviour of LspInstall.

@mjlbach
Copy link
Contributor

mjlbach commented Dec 22, 2020

Yes, that's true (I realize I just helped OP workaround the built-in installer). Have you seen the pinned issue? #334

These installers are likely being removed soon. There are a ton of issues with the built-in installers, as evidenced by a large number of bug reports ultimately being related to failing installers, and windows support is spotty at best.

@mjlbach
Copy link
Contributor

mjlbach commented Dec 22, 2020

Do you want to try #476?

@mjlbach mjlbach reopened this Dec 22, 2020
@mjlbach
Copy link
Contributor

mjlbach commented Dec 22, 2020

Whoops ignore, wrong fix

@monooso
Copy link

monooso commented Dec 22, 2020

@mjlbach Thanks for pointing me to #334. Am I correct in saying that the current advice is to avoid :LspInstall, and manually install and run the appropriate LSP instead?

@mjlbach
Copy link
Contributor

mjlbach commented Dec 22, 2020

I don't think there's official advice/general policy, but my gut would be that PRs will be merged that fix LspInstall but that generally it will be more in-line with future recommendations to allow your system package manager to handle install of servers. FWIW, I use nix for this, and only ever debug LspInstall on behalf of others.

@monooso
Copy link

monooso commented Dec 22, 2020

Does that mean you manually spin up the relevant Language Servers outside of Neovim, so that the Neovim LSP client can connect to them?

Sorry if that's a dumb question; I'm a little unclear as to what I need to do manually, and what this plugin takes care of automatically.

@mjlbach
Copy link
Contributor

mjlbach commented Dec 22, 2020

No, neovim will launch the language server for you. What is planning to be removed is the installer (so LspInstall and LspInstallInfo). So long as the language server is on your path, everything will work as it does currently.

@monooso
Copy link

monooso commented Dec 22, 2020

Got it. Thanks for the clarification.

@mjlbach
Copy link
Contributor

mjlbach commented Jan 3, 2021

Closed by #498

@mjlbach mjlbach closed this as completed Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants