luaneovimpyrightmasonnvim-lspconfig

Neovim, LSP, Mason - Python client not attaching to buffer


In neovim NVIM v0.10.0-dev on Linux Mint. I wrote my whole config in 'lua' and I'm very happy so far. The only thing thats not working is lsp with python. I configured lsp and cmp and mason, mason-lspconfig. I works great with tex, java and html but the python client does not attach to the buffers. When opening a '.py' file I get the following error for pyright:

Client pyright quit with exit code 1 and signal 0. Check log for errors: ~/.local/state/nvim/lsp.log

The log gives me the following output:

 [ERROR][2023-08-11 16:49:35] .../vim/lsp/rpc.lua:675    "rpc"   "~/.local/share/nvim/mason/bin/pyright-langserver"   "stderr"    "internal/modules/cjs/loader.js:638\n    throw err;\      n    ^\n\nError: Cannot find module 'worker_threads'\n    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)\n    at Function.Module._load (internal/modules/cjs/loader      .js:562:25)\n    at Module.require (internal/modules/cjs/loader.js:692:17)\n    at require (internal/modules/cjs/helpers.js:25:18)\n    at Object.1267 (~/.local/share/nvim/mason/pac      kages/pyright/node_modules/pyright/dist/pyright-langserver.js:1:568)\n    at s (~/.local/share/nvim/mason/packages/pyright/node_modules/pyright/dist/pyright-langserver.js:1:744)\n          at Object.9560 (~/.local/share/nvim/mason/packages/pyright/node_modules/pyright/dist/pyright-internal.js:1:997879)\n    at s (~/.local/share/nvim/mason/packages/pyright      /node_modules/pyright/dist/pyright-langserver.js:1:744)\n    at Object.6334 (~/.local/share/nvim/mason/packages/pyright/node_modules/pyright/dist/pyright-internal.js:1:1327466)\n          at s (~/.local/share/nvim/mason/packages/pyright/node_modules/pyright/dist/pyright-langserver.js:1:744)\n"

and when I run :LspInfo in a '.py' file I get this:

 Language client log: ~/.local/state/nvim/lsp.log
 Detected filetype:   python
 
 1 client(s) attached to this buffer: 
 
 Client: null-ls (id: 2, bufnr: [1])
    filetypes:       handlebars, html, typescript, graphql, markdown.mdx, scss, javascriptreact, json, markdown, javascript, less, yaml, typescriptreact, jsonc, vue, css, python, lua, luau
    autostart:       false
    root directory:  ~/.../file.py
    cmd:             <function>
 
 Other clients that match the filetype: python
 
 Config: pyright
    filetypes:         python
    root directory:    Not found.
    cmd:               ~/.local/share/nvim/mason/bin/pyright-langserver --stdio
    cmd is executable: true
    autostart:         true
    custom handlers:   
 
 Configured servers list: texlab, jsonls, pyright, lua_ls

Any Ideas on how to fix it? Can I force attachement?

I read somewhere that it might be an issue with 'node' not being up to date but I could not find any more details on how to update it.

If you need more info, I'm happy to provide it. Thanks


Solution

  • So the problem was with node or nodejs as it's called in the api. The official api just installed node 10.X. To remedy this - as @Zizizizz pointed out - it is possible to install the current version of node or on Linux Mint like so:

    sudo apt-get install curl python-software-properties software-properties-common 
    
    curl -sL https://deb.nodesource.com/setup_20.x | sudo bash - 
    
    sudo apt-get update
    
    sudo apt-get install nodejs