williamboman / mason-lspconfig.nvim

Extension to mason.nvim that makes it easier to use lspconfig with mason.nvim.
Apache License 2.0
2.73k stars 167 forks source link

PylspInstall not available #80

Open felix-clark opened 1 year ago

felix-clark commented 1 year ago

Problem description

Despite calling require("mason-lspconfig").setup() (in Packer's config field for mason-lspconfig.nvim) and installing pylsp via LspInstall, the :PylspInstall command to install extra pylsp features is not available in a python buffer. The LSP is otherwise attached and setup properly as far as I can tell.

I am reasonably confident that require("mason-lspconfig").setup() is indeed being called, because I have the lua language server listed under ensure_installed and it is re-installed when starting neovim after I manually uninstall it.

Perhaps there is a problem with my config, but I just had this working in nvim-lsp-installer and it's not clear what I would be missing. Is there guidance on how to debug this issue?

Why do you think this is an issue with mason-lspconfig.nvim?

I'm not positive that it is - it could be an issue with my config - but based on my reading of the documentation it's not clear what I could be missing.

Neovim version (>= 0.7)

NVIM v0.8.0-1210-gd367ed9b2 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3

Operating system/version

Linux 5.4.0-128-generic #144-Ubuntu SMP Tue Sep 20 11:00:04 UTC 2022 x86_64

I've manually reviewed the Nvim LPS client log (:LspLog) to find potential errors

I've recently downloaded the latest plugin version of mason.nvim, mason-lspconfig.nvim, and nvim-lspconfig

Affected language servers

pylsp

Steps to reproduce

  1. Install and mason, mason-lspconfig, and nvim-lspconfig as instructed in the documentation and help files.
  2. Use :LspInstall pylsp to install the python language server
  3. Open a python buffer in neovim.
  4. Attempt to use :PylspInstall.

Actual behavior

The PylspInstall command to install addons to pylsp is not available or recognized

Expected behavior

I'd expect to be able to use :PylspInstall as I could with nvim-lsp-installer

LspInfo

Language client log: /home/felix/.local/state/nvim/lsp.log
 Detected filetype:   python

 2 client(s) attached to this buffer: 

 Client: pylsp (id: 1, pid: nil, bufnr: [1])
    filetypes:       python
    autostart:       true
    root directory:  /home/felix/Projects/rna-binding
    cmd:             pylsp

 Client: null-ls (id: 2, pid: 5001, bufnr: [1])
    filetypes:       lua, luau, graphql, less, markdown.mdx, yaml, typescript, javascriptreact, javascript, handlebars, markdown, css, jsonc, scss, html, typescriptreact, json, vue
    autostart:       false
    root directory:  /home/felix/Projects/rna-binding
    cmd:             <function>

 Configured servers list: sumneko_lua, pylsp

LspLog

lots of noise but nothing that looks relevant to pylsp

Healthcheck

npm and node are not available; presumably this is irrelevant

Screenshots or recordings

No response

felix-clark commented 1 year ago

In :MasonLog I do see some lines like the following:

[ERROR Fri 14 Oct 2022 11:02:26 AM EDT] ...er/opt/mason-lspconfig.nvim/lua/mason-lspconfig/init.lua:19: Failed to set up lspconfig integration. ...on-lspconfig.nvim/lua/mason-lspconfig/lspconfig_hook.lua:51: module 'lspconfig.util' not found:
felix-clark commented 1 year ago

Ok, I figured out the cause of my problem.

The mason-lspconfig readme instructs to set up mason-lspconfig before nvim-lspconfig. However, mason-lspconfig's setup() function indirectly requires "lspconfig.util", meaning that nvim-lspconfig must be loaded, if not "set up", before mason-lspconfig.setup() is called.

Now I'm using Packer to load in the following order: 1) mason.nvim 2) mason-lspconfig.nvim 3) nvim-lspconfig, but then calling require("mason-lspconfig").setup({}) not when mason-lspconfig.nvim is loaded, but only when I configure nvim-lspconfig.

I'm leaving this open for now because IMO this could be explained a little more clearly in the documentation, but as far as I can tell this isn't an actual bug otherwise.

felix-clark commented 1 year ago

I'm not sure I've actually completely solved the issue, because some additional plugins installed with PylspInstall cause the python LSP client to crash. For instance, flake8 cannot be found despite being visible and present in the venv. It's as if pylsp is not properly using the virtual environment it's setting up.

grimm26 commented 1 year ago

I'm not sure I've actually completely solved the issue, because some additional plugins installed with PylspInstall cause the python LSP client to crash. For instance, flake8 cannot be found despite being visible and present in the venv. It's as if pylsp is not properly using the virtual environment it's setting up.

I am having the same issue with flake8 under pylsp:

[ERROR][2022-12-21 14:13:11] .../vim/lsp/rpc.lua:734    "rpc"   "pylsp" "stderr"    "2022-12-21 14:13:11,079 CST - WARNING - pylsp.config.config - Failed to load hook pylsp_lint: [Errno 2] No such file or directory: 'flake8'\nTraceback (most recent call last):\n  File \"/home/mkeisler/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pylsp/config/config.py\", line 33, in _hookexec\n    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/home/mkeisler/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pluggy/_manager.py\", line 327, in traced_hookexec\n    return outcome.get_result()\n           ^^^^^^^^^^^^^^^^^^^^\n  File \"/home/mkeisler/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pluggy/_result.py\", line 60, in get_result\n    raise ex[1].with_traceback(ex[2])\n  File \"/home/mkeisler/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pluggy/_result.py\", line 33, in from_call\n    result = func()\n             ^^^^^^\n  File \"/home/mkeisler/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pluggy/_manager.py\", line 324, in <lambda>\n    lambda: oldcall(hook_name, hook_impls, kwargs, firstresult)\n            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/home/mkeisler/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pluggy/_callers.py\", line 60, in _multicall\n    return outcome.get_result()\n           ^^^^^^^^^^^^^^^^^^^^\n  File \"/home/mkeisler/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pluggy/_result.py\", line 60, in get_result\n    raise ex[1].with_traceback(ex[2])\n  File \"/home/mkeisler/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pluggy/_callers.py\", line 39, in _multicall\n    res = hook_impl.function(*args)\n          ^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/home/mkeisler/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pyls_flake8/plugin.py\", line 127, in pylsp_lint\n    p = run_flake8(args, document)\n        ^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/home/mkeisler/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/pyls_flake8/plugin.py\", line 121, in run_flake8\n    return run(args, stdout=PIPE, stderr=PIPE, input=document.source.encode())\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/home/mkeisler/.pyenv/versions/3.11.0/lib/python3.11/subprocess.py\", line 546, in run\n    with Popen(*popenargs, **kwargs) as process:\n         ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/home/mkeisler/.pyenv/versions/3.11.0/lib/python3.11/subprocess.py\", line 1022, in __init__\n    self._execute_child(args, executable, preexec_fn, close_fds,\n  File \"/home/mkeisler/.pyenv/versions/3.11.0/lib/python3.11/subprocess.py\", line 1899, in _execute_child\n    raise child_exception_type(errno_num, err_msg, err_filename)\nFileNotFoundError: [Errno 2] No such file or directory: 'flake8'\n"
14:26:03 ❯ ls -d /home/mkeisler/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/flake8
 /home/mkeisler/.local/share/nvim/mason/packages/python-lsp-server/venv/lib/python3.11/site-packages/flake8
williamboman commented 1 year ago

Hey, forgot to reply here before.

The mason-lspconfig readme instructs to set up mason-lspconfig before nvim-lspconfig. However, mason-lspconfig's setup() function indirectly requires "lspconfig.util", meaning that nvim-lspconfig must be loaded, if not "set up", before mason-lspconfig.setup() is called.

I believe this might've been fixed since?

I'm leaving this open for now because IMO this could be explained a little more clearly in the documentation, but as far as I can tell this isn't an actual bug otherwise.

Would you say the current README and :h mason-lspconfig-requirements explains it more clearly?

felix-clark commented 1 year ago

I believe this might've been fixed since?

I'm not sure this is what you mean by "fixed" but it appears that require("mason-lspconfig").setup{} does still need require("lspconfig") to be called first, otherwise I still get the error about needing lspconfig.util.

Would you say the current README and :h mason-lspconfig-requirements explains it more clearly?

To be honest, the README on its own would still not really clarify the issue for me. I would still try to call require("mason-lspconfig").setup{} before loading nvim-lspconfig at all. I think part of the source of confusion is the ambiguity in the term "set up" - does this mean first requireing the package, or calling its setup() function? In many cases these happen at the same time, but in this particular case the difference matters.

The help page is a little better because of the note, but it still may not be the most clear for inexperienced users. For instance, I'm not familiar with "rtp", so while the meaning is clear to me with hindsight of the issue, I'm not sure it would be as clear up front.

Would it make sense to add a step in the instructions, i.e. conceptually:

  1. require and setup mason
  2. require lspconfig to make sure it is loaded
  3. require and setup mason-lspconfig
  4. configure and setup the lsp servers with lspconfig, mason-lspconfig's setup_handlers(), etc.

This is admittedly colored by my personal biases, conventions, and expectations but hopefully it illustrates what threw me off.