2022-03-01 02:58:43 +00:00
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M.config()
|
2022-09-22 18:31:50 +00:00
|
|
|
local signs = {
|
2023-01-10 18:21:09 +00:00
|
|
|
{ name = 'DiagnosticSignError', text = '' },
|
|
|
|
{ name = 'DiagnosticSignWarn', text = '' },
|
|
|
|
{ name = 'DiagnosticSignHint', text = '' },
|
|
|
|
{ name = 'DiagnosticSignInfo', text = '' },
|
2022-09-22 18:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, sign in ipairs(signs) do
|
2023-01-10 18:21:09 +00:00
|
|
|
vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = '' })
|
2022-09-22 18:31:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local config = {
|
|
|
|
virtual_text = false,
|
|
|
|
signs = {
|
|
|
|
active = signs,
|
|
|
|
},
|
|
|
|
update_in_insert = true,
|
|
|
|
underline = true,
|
|
|
|
severity_sort = true,
|
|
|
|
float = {
|
|
|
|
focusable = false,
|
2023-01-10 18:21:09 +00:00
|
|
|
style = 'minimal',
|
|
|
|
border = 'rounded',
|
|
|
|
source = 'always',
|
|
|
|
header = '',
|
|
|
|
prefix = '',
|
2022-09-22 18:31:50 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
vim.diagnostic.config(config)
|
|
|
|
|
2023-01-10 18:21:09 +00:00
|
|
|
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, {
|
|
|
|
border = 'rounded',
|
2022-09-22 18:31:50 +00:00
|
|
|
})
|
|
|
|
|
2023-01-10 18:21:09 +00:00
|
|
|
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, {
|
|
|
|
border = 'rounded',
|
2022-09-22 18:31:50 +00:00
|
|
|
})
|
|
|
|
|
2023-01-10 18:21:09 +00:00
|
|
|
vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
2022-09-22 18:31:50 +00:00
|
|
|
virtual_text = false,
|
|
|
|
})
|
|
|
|
|
2023-01-10 18:21:09 +00:00
|
|
|
local status_ok, lspconfig = pcall(require, 'lspconfig')
|
2022-09-22 18:31:50 +00:00
|
|
|
if not status_ok then
|
2022-03-01 02:58:43 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local function lsp_keymaps(bufnr)
|
|
|
|
local opts = { noremap = true, silent = true }
|
2023-01-10 18:21:09 +00:00
|
|
|
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)
|
2022-03-01 07:25:09 +00:00
|
|
|
--vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]]
|
2022-03-01 02:58:43 +00:00
|
|
|
end
|
|
|
|
|
2023-01-10 18:21:09 +00:00
|
|
|
local on_attach = function(client, bufnr)
|
|
|
|
lsp_keymaps(bufnr)
|
|
|
|
end
|
2022-03-01 02:58:43 +00:00
|
|
|
|
2023-01-10 18:21:09 +00:00
|
|
|
-- 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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2022-09-22 19:13:23 +00:00
|
|
|
|
2023-01-10 18:21:09 +00:00
|
|
|
-- pyright
|
|
|
|
-- pip install pyright
|
|
|
|
lspconfig.pyright.setup({
|
|
|
|
on_attach = on_attach,
|
|
|
|
})
|
2022-10-04 03:54:10 +00:00
|
|
|
|
2023-01-10 18:21:09 +00:00
|
|
|
-- vscode-json-language-server
|
|
|
|
-- npm i -g vscode-langservers-extracted
|
|
|
|
lspconfig.jsonls.setup({
|
|
|
|
on_attach = on_attach,
|
|
|
|
})
|
2022-10-04 03:54:10 +00:00
|
|
|
|
2023-01-10 18:21:09 +00:00
|
|
|
-- typescript-language-server
|
|
|
|
-- npm i -g typescript-language-server
|
|
|
|
lspconfig.tsserver.setup({
|
|
|
|
on_attach = on_attach,
|
|
|
|
})
|
2022-03-01 02:58:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|