78 lines
2.6 KiB
Lua
78 lines
2.6 KiB
Lua
local u = require('utils')
|
|
local nvim_lsp = require'lspconfig'
|
|
|
|
local on_attach = function(client, bufnr)
|
|
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
|
|
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
|
|
|
|
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
local opts = { noremap=true, silent=true }
|
|
|
|
buf_set_keymap('n', '<c-]>', ':lua vim.lsp.buf.definition()<CR>', opts)
|
|
buf_set_keymap('n', 'K', ':lua vim.lsp.buf.hover()<CR>', opts)
|
|
buf_set_keymap('n', 'gD', ':lua vim.lsp.buf.implementation()<CR>', opts)
|
|
buf_set_keymap('n', '<c-k>', ':lua vim.lsp.buf.signature_help()<CR>', opts)
|
|
buf_set_keymap('n', '1gD', ':lua vim.lsp.buf.type_definition()<CR>', opts)
|
|
buf_set_keymap('n', 'gr', ':lua vim.lsp.buf.references()<CR>', opts)
|
|
buf_set_keymap('n', 'g0', ':lua vim.lsp.buf.document_symbol()<CR>', opts)
|
|
buf_set_keymap('n', 'gW', ':lua vim.lsp.buf.workspace_symbol()<CR>', opts)
|
|
buf_set_keymap('n', 'gd', ':lua vim.lsp.buf.definition()<CR>', opts)
|
|
buf_set_keymap('n', 'ga', ':lua vim.lsp.buf.code_action()<CR>', opts)
|
|
buf_set_keymap('n', 'ff', ':lua vim.lsp.buf.formatting()<CR>', opts)
|
|
buf_set_keymap('n', 'gn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
|
|
--require'completion'.on_attach(client)
|
|
|
|
-- Set highlight colors
|
|
local highlights = {
|
|
Error = "Red",
|
|
Warning = "Yellow",
|
|
Information = "Blue",
|
|
Hint = "Green",
|
|
}
|
|
|
|
for typ, color in pairs(highlights) do
|
|
u.hi('LspDiagnosticsDefault'..typ, {ctermfg = color})
|
|
u.hi('LspDiagnosticsUnderline'..typ, {cterm = 'underline'})
|
|
end
|
|
|
|
vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(
|
|
vim.lsp.diagnostic.on_publish_diagnostics,
|
|
{
|
|
virtual_text = true,
|
|
signs = true,
|
|
update_in_insert = true,
|
|
underline = true
|
|
}
|
|
)
|
|
require "lsp_signature".on_attach({doc_lines = 0})
|
|
end
|
|
|
|
-- nvim-cmp supports additional completion capabilities
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
|
|
|
|
|
|
local servers = require'nvim-lsp-installer'
|
|
servers.on_server_ready(function(server)
|
|
local config = {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
flags = {debounce_text_changes = 150}
|
|
}
|
|
if server.name == "sumneko_lua" then
|
|
config.settings = require'lsp.lua'
|
|
end
|
|
if server.name == "rust_analyzer" then
|
|
config.settings = require'lsp.rust'
|
|
end
|
|
server:setup(config)
|
|
end)
|
|
|
|
-- Set completeopt to have a better completion experience
|
|
vim.o.completeopt = 'menuone,noselect'
|
|
|
|
|
|
|