Hi,
I am not sure how to approach debugging the issues I’m facing with pyright (for some time already). Currently I’m running neovim 0.6.0 release, pyright 1.1.191. The issue seems cross-platform: comes up on Windows 10 (not WSL) and Ubuntu (16.04. run on VM), and docker (with Ubuntu 18.04).
So, sometimes pyright runs high on CPU and RAM for long times in more complex projects. Lsp is not responsive at those times: I can’t jump to definition (or rather I jump but after couple of minutes), autocompletion is not working. Then things start working again, and after some time situation repeats.
I have run lsp with trace levels and I see that there are lines like the the following:
[TRACE][2021-12-03 12:18:58] .../lua/vim/lsp.lua:724 "notification" "window/logMessage" { message = "[FG] Long operation: analyzing: <<path_to_file>> (160024ms)"
Here is my setup for lsp:
Summary
vim.g.diagnostic_enable_virtual_text=1
-- Set completeopt to have a better completion experience
vim.o.completeopt = "menuone,noinsert,noselect"
-- Avoid showing message extra message when using completion
vim.o.shortmess = vim.o.shortmess .. 'c'
local cmp = require'cmp'
cmp.setup {
sources = {
{ name = 'nvim_lsp',
keyword_length = 5 },
{ name = 'path' },
{ name = 'buffer',
keyword_length = 5 },
{ name = 'nvim_lua' },
},
mapping = {
['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 's' })
}
}
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
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', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
-- buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<leader>d', '<cmd>lua vim.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<leader>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
-- Set some keybinds conditional on server capabilities
if client.resolved_capabilities.document_formatting then
buf_set_keymap("n", "<leader>gf", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
elseif client.resolved_capabilities.document_range_formatting then
buf_set_keymap("n", "<leader>gf", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
end
end
-- Use a loop to conveniently both setup defined servers
-- and map buffer local keybindings when the language server attaches
local servers = { "pyright", "vimls", "tsserver" }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {capabilities = capabilities, on_attach = on_attach}
end
nvim_lsp["r_language_server"].setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {
rich_documentation = false,
}
}
Any ideas what I can check or change to understand better what the issue might be for pyright with these files?