Use pyright (if available), fallback to pylsp otherwise

This commit is contained in:
Evie Litherland-Smith 2022-11-02 11:14:31 +00:00
parent 667115842f
commit e5cb627087
2 changed files with 36 additions and 18 deletions

View file

@ -38,7 +38,7 @@ Plugin definitions are in `plugins.lua`, inside `vim` run `:PackerSync` to insta
pyenv virtualenv neovim3 # Assumes working pyenv
pyenv activate neovim3
pip install -U pip setuptools wheel
pip install -U pynvim "python-lsp-server[all]" fortls pylsp-mypy python-lsp-black
pip install -U pynvim pyright fortl # If pyright not available, fallback to: "python-lsp-server[all]" pylsp-mypy
pyenv deactivate
```

View file

@ -104,25 +104,43 @@ cmp.setup.cmdline(':', {
-- Setup lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
require('lspconfig')['pylsp'].setup{
cmd = {os.getenv( "HOME" ).."/.pyenv/versions/neovim3/bin/pylsp"},
on_attach = on_attach,
flags = lsp_flags,
settings = {
pylsp = {
plugins = {
pycodestyle = {maxLineLength = 88},
flake8 = {maxLineLength = 88}
}
local function file_exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
local pyright_file = os.getenv( "HOME" ).."/.pyenv/versions/neovim3/bin/pyright-langserver"
local pylsp_file = os.getenv( "HOME" ).."/.pyenv/versions/neovim3/bin/pylsp"
if file_exists(pyright_file) then
require('lspconfig')['pyright'].setup{
cmd = {pyright_file, "--stdio"},
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities,
}
},
capabilities = capabilities
}
elseif file_exists(pylsp_file) then
require('lspconfig')['pylsp'].setup{
cmd = {pylsp_file},
on_attach = on_attach,
flags = lsp_flags,
settings = {
pylsp = {
plugins = {
pycodestyle = {maxLineLength = 88},
flake8 = {maxLineLength = 88}
}
}
},
capabilities = capabilities
}
end
require('lspconfig')['fortls'].setup{
cmd = {os.getenv( "HOME" ).."/.pyenv/versions/neovim3/bin/fortls"},
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities
cmd = {os.getenv( "HOME" ).."/.pyenv/versions/neovim3/bin/fortls"},
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities
}
require('lspconfig')['sumneko_lua'].setup {