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 virtualenv neovim3 # Assumes working pyenv
pyenv activate neovim3 pyenv activate neovim3
pip install -U pip setuptools wheel 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 pyenv deactivate
``` ```

View file

@ -104,8 +104,24 @@ cmp.setup.cmdline(':', {
-- Setup lspconfig. -- Setup lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
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,
}
elseif file_exists(pylsp_file) then
require('lspconfig')['pylsp'].setup{ require('lspconfig')['pylsp'].setup{
cmd = {os.getenv( "HOME" ).."/.pyenv/versions/neovim3/bin/pylsp"}, cmd = {pylsp_file},
on_attach = on_attach, on_attach = on_attach,
flags = lsp_flags, flags = lsp_flags,
settings = { settings = {
@ -118,6 +134,8 @@ require('lspconfig')['pylsp'].setup{
}, },
capabilities = capabilities capabilities = capabilities
} }
end
require('lspconfig')['fortls'].setup{ require('lspconfig')['fortls'].setup{
cmd = {os.getenv( "HOME" ).."/.pyenv/versions/neovim3/bin/fortls"}, cmd = {os.getenv( "HOME" ).."/.pyenv/versions/neovim3/bin/fortls"},
on_attach = on_attach, on_attach = on_attach,