nvim-config/lua/configs/lspconfig.lua
2023-08-04 11:22:25 -07:00

162 lines
4.1 KiB
Lua

local M = {}
function M.config()
local signs = {
{ name = 'DiagnosticSignError', text = '' },
{ name = 'DiagnosticSignWarn', text = '' },
{ name = 'DiagnosticSignHint', text = '' },
{ name = 'DiagnosticSignInfo', text = '' },
}
for _, sign in ipairs(signs) do
vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = '' })
end
local config = {
virtual_text = false,
signs = {
active = signs,
},
update_in_insert = true,
underline = true,
severity_sort = true,
float = {
focusable = false,
style = 'minimal',
border = 'rounded',
source = 'always',
header = '',
prefix = '',
},
}
vim.diagnostic.config(config)
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, {
border = 'rounded',
})
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, {
border = 'rounded',
})
vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = false,
})
local status_ok, lspconfig = pcall(require, 'lspconfig')
if not status_ok then
return
end
local function lsp_keymaps(bufnr)
local opts = { noremap = true, silent = true }
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',
'gl',
"<cmd>lua vim.diagnostic.open_float({ source = false, prefix = function(d, i, ttl) return string.rep(' ', #tostring(ttl) - #tostring(i)) .. tostring(i) .. ': ', nil end })<CR>",
opts
)
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', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'go', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
vim.api.nvim_buf_set_keymap(
bufnr,
'n',
'[d',
'<cmd>lua vim.diagnostic.goto_prev({ border = "rounded" })<CR>',
opts
)
vim.api.nvim_buf_set_keymap(
bufnr,
'n',
']d',
'<cmd>lua vim.diagnostic.goto_next({ border = "rounded" })<CR>',
opts
)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ll', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>lf', '<cmd>lua vim.lsp.buf.formatting_sync()<CR>', opts)
--vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]]
end
local on_attach = function(client, bufnr)
lsp_keymaps(bufnr)
end
-- lua-language-server
-- pacman -S lua-language-server
lspconfig.lua_ls.setup({
on_attach = on_attach,
settings = {
Lua = {
format = {
enable = false,
},
diagnostics = {
globals = { 'vim' },
},
workspace = {
library = {
-- include neovim runtime files
[vim.fn.expand('$VIMRUNTIME/lua')] = true,
[vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true,
},
checkThirdParty = false, -- disable "do you want to set up the workspace"
},
telemetry = {
enable = false,
},
},
},
})
-- vim.g.python3_host_prog = '/home/peters/src/invsys/docker-path/python'
-- pyright
-- pip install pyright
lspconfig.pyright.setup({
-- cmd = { '/home/peters/src/invsys/docker-path/pyright-langserver', '--stdio' },
-- cmd = { 'pyright-langserver', '--stdio' },
on_attach = on_attach,
root_dir = require'lspconfig.util'.root_pattern("pyproject.toml"),
settings = {
python = {
analysis = {
autoSearchPaths = true,
useLibraryCodeForTypes = false,
diagnosticMode = 'openFilesOnly',
},
},
},
})
-- pip install ruff ruff-lsp
lspconfig.ruff_lsp.setup({
on_attach = on_attach,
init_options = {
settings = {
args = {
-- disable distracting whitespace rules
"--ignore", "W291,W293",
},
}
}
})
-- vscode-json-language-server
-- npm i -g vscode-langservers-extracted
lspconfig.jsonls.setup({
on_attach = on_attach,
})
-- typescript-language-server
-- npm i -g typescript-language-server
lspconfig.tsserver.setup({
on_attach = on_attach,
})
end
return M