dotfiles/.config/nvim/after/plugin/lsp.lua

112 lines
3.1 KiB
Lua

-- here you can setup the language servers
local lsp_zero = require('lsp-zero')
lsp_zero.on_attach(function(client, bufnr)
-- see :help lsp-zero-keybindings
-- to learn the available actions
lsp_zero.default_keymaps({buffer = bufnr})
end)
-- to learn how to use mason.nvim
-- read this: https://github.com/VonHeikemen/lsp-zero.nvim/blob/v3.x/doc/md/guide/integrate-with-mason-nvim.md
require('mason').setup({})
require('mason-lspconfig').setup({
-- https://github.com/williamboman/mason-lspconfig.nvim?tab=readme-ov-file
ensure_installed = {
"pylsp",
"pyright",
},
handlers = {
function(server_name)
require('lspconfig')[server_name].setup({})
end,
},
})
-- https://github.com/williamboman/mason-lspconfig.nvim/blob/main/lua/mason-lspconfig/server_configurations/pylsp/README.md
require "lspconfig".pylsp.setup {
on_attach = on_attach,
settings = {
pylsp = {
plugins = {
flake8 = {
enabled = false,
maxLineLength = 119,
},
mypy = {
enabled = true,
},
pycodestyle = {
enabled = false,
},
pyflakes = {
enabled = false,
},
}
}
}
}
require "lspconfig".pyright.setup {
-- on_attach = on_attach,
settings = {
-- pyright = {autoImportCompletion = true,},
python = {
analysis = {
-- autoSearchPaths = true,
-- diagnosticMode = 'openFilesOnly',
-- useLibraryCodeForTypes = true,
-- typeCheckingMode = 'off',
diagnosticSeverityOverrides = {
-- I edit code that lives in docker containers and pyright complains when I import modules that aren't on my PC:
reportMissingImports = false
}
}
}
}
}
-- disable pyright complaints about '*args" and '**kwargs' not being accessed in a function
-- https://github.com/MaskRay/ccls/issues/869#issuecomment-1793044831
function filter_diagnostics_pyright(diagnostic)
-- Allow kwargs to be unused, sometimes you want many functions to take the
-- same arguments but you don't use all the arguments in all the functions,
-- so kwargs is used to suck up all the extras
if diagnostic.message == '"args" is not accessed' or
diagnostic.message == '"kwargs" is not accessed' then
return false
end
-- -- Allow variables starting with an underscore
-- if string.match(diagnostic.message, '"_.+" is not accessed') then
-- return false
-- end
return true
end
function filter_diagnostics(diagnostic)
if diagnostic.source == "Pyright" then
return filter_diagnostics_pyright(diagnostic)
end
return true
end
function custom_on_publish_diagnostics(a, params, client_id, c, config)
params.diagnostics = vim.tbl_filter(filter_diagnostics, params.diagnostics)
vim.lsp.diagnostic.on_publish_diagnostics(a, params, client_id, c, config)
end
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
custom_on_publish_diagnostics, {})