-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pyright languageserver #303
Add pyright languageserver #303
Conversation
There are currently some issues discovering python module completion, still working through it. It works intermittently for some modules now, and there's a difference using the new pyright-langserver cli option vs manually building and running the language server directly... |
@mjlbach what are the current issues you are seeing, and is there something I can help fix or look into? |
Hi @bryall, there's not any issues, but pyright won't work without implementing some additional features in neovim core (namely workspaceDidChange). See: neovim/neovim#12638 That PR works, it's just a bit messy. |
It's also important to note that the Microsoft Python Language server in C# will soon be no longer maintained. |
i know, I am planning on switching to this LSP soon, and want to see if I can provide support to help get this in good shape. I will take a look at the issue |
If you try out the above PR and the one from neovim core, let me know how it works :) |
@justinmk I temporarily added a workaround (cc: @bryall) until the neovim/neovim#12638 is merged, so I believe this can be merged now. |
@justinmk I temporarily added a workaround (cc: @bryall) until the #299
is merged, so I believe this can be merged now.
Dym until
[neovim/neovim#12638](neovim/neovim#12638) is
merged?
Rohan Kumar
|
Yes, fixed |
Well hot dang. Can we merge? |
FYI for those wanting to use this and waiting for this to be merged, you can add what this PR does to your init.vim. :lua << EOF
local nvim_lsp = require('nvim_lsp')
-- vim.lsp.set_log_level("debug")
local on_attach = function(_, bufnr)
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
require'diagnostic'.on_attach()
require'completion'.on_attach()
-- Mappings.
local opts = { noremap=true, silent=true }
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wl', '<cmd>lua vim.lsp.buf.list_workspace_folders()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>e', '<cmd>lua vim.lsp.util.show_line_diagnostics()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', '<cmd>lua vim.api.nvim_command("NextDiagnosticCycle")<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', '<cmd>lua vim.api.nvim_command("PrevDiagnosticCycle")<CR>', opts)
end
local configs = require('nvim_lsp/configs')
--if not configs.pyright then
configs.pyright = {
default_config = {
cmd = {"pyright-langserver", "--stdio"};
filetypes = {"python"};
root_dir = nvim_lsp.util.root_pattern(".git", "setup.py", "setup.cfg", "pyproject.toml", "requirements.txt");
settings = {
analysis = { autoSearchPaths= true; };
pyright = { useLibraryCodeForTypes = true; };
};
-- The following before_init function can be removed once https://github.com/neovim/neovim/pull/12638 is merged
before_init = function(initialize_params)
initialize_params['workspaceFolders'] = {{
name = 'workspace',
uri = initialize_params['rootUri']
}}
end
};
}
--end
local servers = {'gopls', 'rust_analyzer', 'sumneko_lua', 'tsserver', 'vimls', 'jsonls', 'html', 'ghcide', 'rnix', 'ocamllsp', 'pyright'}
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
}
end
EOF |
@h-michael Can we merge this? |
From pyright? |
Oh, I see. Yep, I'll fix |
Done, I can squash commits if necessary |
@mjlbach Thanks |
@mjlbach excited to try this. does it still need neovim/neovim#12638 in order to work? if so, 🤞 that gets merged soon! |
@kamalmarhubi Nope, I added a temporary fix to bypass the need for that PR, I'll remove the fix once that PR is merged. |
really dumb question @mjlbach : is pyright supposed to work as an alternative to pyls now? |
Fom my understanding this should currently be the best python language server out there. |
Anyone manage to get this setup using the code pasted by OP above? I have the pyright installed and can see that I have the pyright object selected but when I try run setup i'm running into |
This was merged, did you try just using the current plugin? And I use the snippet I posted |
I am actually using your nix neovim-nightly-master which hasn't updated yet but was eager to try it out :) Yep copy + paste just changed |
Ah that might be out of date, you may need to try replace nvim_lsp with lspconfig in the snippet |
Pyright (as seen in the quickstart guide), works fine. No workarounds needed. |
Closes #299
Depends on neovim/neovim#12638