diff --git a/README.md b/README.md index 57ca31e1..a27606cf 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/lua/config_lsp.lua b/lua/config_lsp.lua index 4996c588..e2a45160 100644 --- a/lua/config_lsp.lua +++ b/lua/config_lsp.lua @@ -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 {