nvim-config/lua/configs/lspconfig.lua
2023-02-02 16:28:47 -08:00

145 lines
3.6 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.sumneko_lua.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,
},
},
},
})
-- pyright
-- pip install pyright
lspconfig.pyright.setup({
on_attach = on_attach,
settings = {
python = {
analysis = {
autoSearchPaths = true,
useLibraryCodeForTypes = false,
diagnosticMode = 'openFilesOnly',
},
},
},
})
-- 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