LunarVim/lua/lsp/init.lua

168 lines
5.4 KiB
Lua
Raw Normal View History

2021-03-17 20:48:52 +01:00
-- TODO figure out why this don't work
vim.fn.sign_define(
2021-07-09 14:07:25 +02:00
"LspDiagnosticsSignError",
{ texthl = "LspDiagnosticsSignError", text = "", numhl = "LspDiagnosticsSignError" }
)
vim.fn.sign_define(
2021-07-09 14:07:25 +02:00
"LspDiagnosticsSignWarning",
{ texthl = "LspDiagnosticsSignWarning", text = "", numhl = "LspDiagnosticsSignWarning" }
)
vim.fn.sign_define(
2021-07-09 14:07:25 +02:00
"LspDiagnosticsSignHint",
{ texthl = "LspDiagnosticsSignHint", text = "", numhl = "LspDiagnosticsSignHint" }
)
vim.fn.sign_define(
2021-07-09 14:07:25 +02:00
"LspDiagnosticsSignInformation",
{ texthl = "LspDiagnosticsSignInformation", text = "", numhl = "LspDiagnosticsSignInformation" }
)
2021-03-14 21:55:38 +01:00
2021-07-09 14:07:25 +02:00
vim.cmd "nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>"
vim.cmd "nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>"
vim.cmd "nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>"
vim.cmd "nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>"
vim.cmd "nnoremap <silent> K :lua vim.lsp.buf.hover()<CR>"
2021-03-15 15:41:54 +01:00
-- vim.cmd('nnoremap <silent> <C-k> <cmd>lua vim.lsp.buf.signature_help()<CR>')
2021-07-09 14:07:25 +02:00
vim.cmd "nnoremap <silent> <C-p> :lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<CR>"
vim.cmd "nnoremap <silent> <C-n> :lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})<CR>"
2021-03-15 01:56:50 +01:00
-- scroll down hover doc or scroll in definition preview
-- scroll up hover doc
2021-07-09 14:07:25 +02:00
vim.cmd 'command! -nargs=0 LspVirtualTextToggle lua require("lsp/virtual_text").toggle()'
2021-03-15 01:34:23 +01:00
-- Set Default Prefix.
-- Note: You can set a prefix per lsp server in the lv-globals.lua file
2021-07-09 14:07:25 +02:00
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = {
prefix = "",
spacing = 0,
},
signs = true,
underline = true,
})
2021-07-09 14:07:25 +02:00
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
border = O.lsp.popup_border,
})
2021-07-09 14:07:25 +02:00
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
border = O.lsp.popup_border,
})
-- symbols for autocomplete
vim.lsp.protocol.CompletionItemKind = {
2021-07-09 14:07:25 +02:00
"  (Text) ",
"  (Method)",
"  (Function)",
"  (Constructor)",
" ﴲ (Field)",
"[] (Variable)",
"  (Class)",
" ﰮ (Interface)",
"  (Module)",
" 襁 (Property)",
"  (Unit)",
"  (Value)",
" 練 (Enum)",
"  (Keyword)",
"  (Snippet)",
"  (Color)",
"  (File)",
"  (Reference)",
"  (Folder)",
"  (EnumMember)",
" ﲀ (Constant)",
" ﳤ (Struct)",
"  (Event)",
"  (Operator)",
"  (TypeParameter)",
}
2021-03-14 21:55:38 +01:00
--[[ " autoformat
autocmd BufWritePre *.js lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.jsx lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.lua lua vim.lsp.buf.formatting_sync(nil, 100) ]]
-- Java
-- autocmd FileType java nnoremap ca <Cmd>lua require('jdtls').code_action()<CR>
2021-03-19 04:47:03 +01:00
local function documentHighlight(client, bufnr)
2021-07-09 14:07:25 +02:00
-- Set autocommands conditional on server_capabilities
if client.resolved_capabilities.document_highlight then
vim.api.nvim_exec(
[[
hi LspReferenceRead cterm=bold ctermbg=red guibg=#464646
hi LspReferenceText cterm=bold ctermbg=red guibg=#464646
hi LspReferenceWrite cterm=bold ctermbg=red guibg=#464646
augroup lsp_document_highlight
autocmd! * <buffer>
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
augroup END
]],
2021-07-09 14:07:25 +02:00
false
)
end
2021-03-19 04:47:03 +01:00
end
local lsp_config = {}
if O.document_highlight then
2021-07-09 14:07:25 +02:00
function lsp_config.common_on_attach(client, bufnr)
documentHighlight(client, bufnr)
end
2021-03-19 04:47:03 +01:00
end
function lsp_config.tsserver_on_attach(client, bufnr)
2021-07-09 14:07:25 +02:00
-- lsp_config.common_on_attach(client, bufnr)
client.resolved_capabilities.document_formatting = false
local ts_utils = require "nvim-lsp-ts-utils"
-- defaults
ts_utils.setup {
debug = false,
disable_commands = false,
enable_import_on_completion = false,
import_all_timeout = 5000, -- ms
-- eslint
eslint_enable_code_actions = true,
eslint_enable_disable_comments = true,
eslint_bin = O.lang.tsserver.linter,
eslint_config_fallback = nil,
eslint_enable_diagnostics = true,
-- formatting
enable_formatting = O.lang.tsserver.autoformat,
formatter = O.lang.tsserver.formatter,
formatter_config_fallback = nil,
-- parentheses completion
complete_parens = false,
signature_help_in_parens = false,
-- update imports on file move
update_imports_on_move = false,
require_confirmation_on_move = false,
watch_dir = nil,
}
2021-07-09 14:07:25 +02:00
-- required to fix code action ranges
ts_utils.setup_client(client)
2021-07-01 00:45:40 +02:00
2021-07-09 14:07:25 +02:00
-- TODO: keymap these?
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "gs", ":TSLspOrganize<CR>", {silent = true})
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "qq", ":TSLspFixCurrent<CR>", {silent = true})
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", ":TSLspRenameFile<CR>", {silent = true})
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", ":TSLspImportAll<CR>", {silent = true})
end
require("lv-utils").define_augroups {
_general_lsp = {
{ "FileType", "lspinfo", "nnoremap <silent> <buffer> q :q<CR>" },
},
}
2021-07-01 00:45:40 +02:00
-- Use a loop to conveniently both setup defined servers
-- and map buffer local keybindings when the language server attaches
-- local servers = {"pyright", "tsserver"}
-- for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup {on_attach = on_attach} end
return lsp_config