neovim / neovim

Vim-fork focused on extensibility and usability
https://neovim.io
Other
81.64k stars 5.59k forks source link

Spawning language server with cmd: `pyright-langserver` failed. The language server is either not installed, missing from PATH, or not executable. #17354

Closed winkee01 closed 2 years ago

winkee01 commented 2 years ago

Neovim version (nvim -v)

NVIM v0.7.0-dev+719-gbdfea9d9a

Language server name/version

pyright

Operating system/version

macOS Monterey 12.1

Steps to reproduce using "nvim -u minimal_init.lua"

I installed nvim-lspconfig, nvim-lsp-installer and cmp-nvim-lsp plugins, also I installed pyright via :LspInstall pyright,

config file for nvim-lspconfig

local nvim_lsp = require('lspconfig')
local on_attach = function(client, bufnr)
  local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
  local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end

  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

  -- Mappings
  local opts = { noremap=true, silent=true }
  buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
  buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
  buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
  buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
  buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
  buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
  buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
  buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
  buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
  buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
  buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
  buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
  buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)

  -- Set some keybinds conditional on server capabilities
  if client.resolved_capabilities.document_formatting then
    buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
  end
  if client.resolved_capabilities.document_range_formatting then
    buf_set_keymap("v", "<space>f", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
  end

  -- Set autocommands conditional on server_capabilities
  if client.resolved_capabilities.document_highlight then
    vim.api.nvim_exec([[
      hi LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow
      hi LspReferenceText cterm=bold ctermbg=red guibg=LightYellow
      hi LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow
      augroup lsp_document_highlight
        autocmd! * <buffer>
        autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
        autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
      augroup END
    ]], false)
  end
end

-- Use a loop to conveniently both setup defined servers 
-- and map buffer local keybindings when the language server attaches
local servers = { "pyright", "rust_analyzer", "tsserver", "clangd" }
for _, lsp in ipairs(servers) do
  nvim_lsp[lsp].setup { on_attach = on_attach }
end

nvim-lsp-installer

local lsp_installer = require("nvim-lsp-installer")

local lsp_installer_servers = require('nvim-lsp-installer.servers')

local servers = {
    "rust_analyzer",
    "clangd",
    "pyright",
    "tsserver",
    "sumneko_lua",
}

for _, server_name in pairs(servers) do
    local server_available, server = lsp_installer_servers.get_server(server_name)
    if server_available then
        server:on_ready(function ()
            -- When this particular server is ready (i.e. when installation is finished or the server is already installed),
            -- this function will be invoked. Make sure not to also use the "catch-all" lsp_installer.on_server_ready()
            -- function to set up your servers, because by doing so you'd be setting up the same server twice.
            local opts = {}
            server:setup(opts)
        end)
        if not server:is_installed() then
            -- Queue the server to be installed.
            server:install()
        end
    end
end

the only difference that made the mentioned error is that I added below config for nvim-cmp

local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)

local lspconfig = require('lspconfig')

-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver' }
for _, lsp in ipairs(servers) do
  lspconfig[lsp].setup {
    -- on_attach = my_custom_on_attach,
    capabilities = capabilities,
  }
end

To reproduce with minimal setup.

nvim -u minimal_init.lua

Expected behavior

No error should display.

Actuall, If I delete the casuing-error config, pyright can be detected correct and function correctly.

Actual behavior

When I open a python file like this: nvim test.py, I get this error:

Spawning language server with cmd: `pyright-langserver` failed. The language server is either not installed, missing from PATH, or not executable.

Log file

No response

winkee01 commented 2 years ago

Without below config, lsp can detect my pyright correctly.

local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)

local lspconfig = require('lspconfig')

-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver' }
for _, lsp in ipairs(servers) do
  lspconfig[lsp].setup {
    -- on_attach = my_custom_on_attach,
    capabilities = capabilities,
  }
end

Can someone explain why?

winkee01 commented 2 years ago

ok, I get it, on_attach is not enabled 😂. Sorry.

sukai-cheng commented 2 years ago

can you tell me how to resolve this problem, thanks? I met the same problem

image
urmzd commented 2 years ago

@sukai-cheng Can you provide a copy of your init.lua? I experienced the same issue after updating nvim-lspconfig and nvim-lsp-installer. Might be a version mismatch? Not entirely sure ATM.

flexmachina commented 2 years ago

I have the same issue when using nvim-lsp-installer and pyright. I'd mistakenly installed the wrong Python LSP from nvim-lsp-installer I think.

Worst case scenario, sudo npm install -g pyright should work

Terricola commented 1 year ago

Can i configure multiple python servers in one lspconfig.lua file?. I just configure my nvim setup and i put 4 python servers and when opening a python file all failed except: jedi_language_server. Did i do something wrong? Captura de Pantalla 2022-12-01 a la(s) 7 04 48 p m

peidrao commented 1 year ago

I have the same issue when using nvim-lsp-installer and pyright. I'd mistakenly installed the wrong Python LSP from nvim-lsp-installer I think.

Worst case scenario, sudo npm install -g pyright should work

Works for me, TKS!

Blazkowiz47 commented 10 months ago

For me, npm wasn't installed... So I just did sudo apt-get install npm and it works now...

HanslettTheDev commented 7 months ago

sudo npm install -g pyright

This worked too Thanks