Large cleanup and switch to NVIM LSP
This commit is contained in:
parent
37fb739795
commit
2eed622601
14 changed files with 221 additions and 83 deletions
33
lua/conf/compe.lua
Normal file
33
lua/conf/compe.lua
Normal file
|
@ -0,0 +1,33 @@
|
|||
require'compe'.setup {
|
||||
enabled = true;
|
||||
autocomplete = true;
|
||||
debug = false;
|
||||
min_length = 1;
|
||||
preselect = 'enable';
|
||||
throttle_time = 80;
|
||||
source_timeout = 200;
|
||||
resolve_timeout = 800;
|
||||
incomplete_delay = 400;
|
||||
max_abbr_width = 100;
|
||||
max_kind_width = 100;
|
||||
max_menu_width = 100;
|
||||
documentation = {
|
||||
border = { '', '' ,'', ' ', '', '', '', ' ' }, -- the border option is the same as `|help nvim_open_win|`
|
||||
winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder",
|
||||
max_width = 120,
|
||||
min_width = 60,
|
||||
max_height = math.floor(vim.o.lines * 0.3),
|
||||
min_height = 1,
|
||||
};
|
||||
|
||||
source = {
|
||||
path = true;
|
||||
buffer = true;
|
||||
calc = true;
|
||||
nvim_lsp = true;
|
||||
nvim_lua = true;
|
||||
vsnip = true;
|
||||
ultisnips = true;
|
||||
luasnip = true;
|
||||
};
|
||||
}
|
5
lua/conf/trouble.lua
Normal file
5
lua/conf/trouble.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
require("trouble").setup {
|
||||
-- your configuration comes here
|
||||
-- or leave it empty to use the default settings
|
||||
-- refer to the configuration section below
|
||||
}
|
8
lua/lsputils.lua
Normal file
8
lua/lsputils.lua
Normal file
|
@ -0,0 +1,8 @@
|
|||
vim.lsp.handlers['textDocument/codeAction'] = require'lsputil.codeAction'.code_action_handler
|
||||
vim.lsp.handlers['textDocument/references'] = require'lsputil.locations'.references_handler
|
||||
vim.lsp.handlers['textDocument/definition'] = require'lsputil.locations'.definition_handler
|
||||
vim.lsp.handlers['textDocument/declaration'] = require'lsputil.locations'.declaration_handler
|
||||
vim.lsp.handlers['textDocument/typeDefinition'] = require'lsputil.locations'.typeDefinition_handler
|
||||
vim.lsp.handlers['textDocument/implementation'] = require'lsputil.locations'.implementation_handler
|
||||
vim.lsp.handlers['textDocument/documentSymbol'] = require'lsputil.symbols'.document_handler
|
||||
vim.lsp.handlers['workspace/symbol'] = require'lsputil.symbols'.workspace_handler
|
91
lua/my-lsp.lua
Normal file
91
lua/my-lsp.lua
Normal file
|
@ -0,0 +1,91 @@
|
|||
local nvim_lsp = require('lspconfig')
|
||||
|
||||
-- enable snippet support
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
capabilities.textDocument.completion.completionItem.resolveSupport = {
|
||||
properties = {
|
||||
'documentation',
|
||||
'detail',
|
||||
'additionalTextEdits',
|
||||
}
|
||||
}
|
||||
|
||||
-- Use an on_attach function to only map the following keys
|
||||
-- after the language server attaches to the current buffer
|
||||
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
|
||||
|
||||
--Enable completion triggered by <c-x><c-o>
|
||||
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||
|
||||
-- Mappings.
|
||||
local opts = { noremap=true, silent=true }
|
||||
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
||||
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
||||
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
||||
buf_set_keymap('v', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
||||
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
||||
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
||||
buf_set_keymap('n', '<Leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
||||
buf_set_keymap('n', '<Leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
||||
buf_set_keymap('n', '<M-a>', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
||||
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
||||
buf_set_keymap('n', '<M-e>', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
|
||||
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
|
||||
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
|
||||
buf_set_keymap('n', '<M-q>', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
|
||||
buf_set_keymap("n", "<Leader>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
|
||||
require'completion'.on_attach(client, bufnr)
|
||||
end
|
||||
|
||||
|
||||
require'lspinstall'.setup() -- important
|
||||
|
||||
local servers = require'lspinstall'.installed_servers()
|
||||
for _, server in pairs(servers) do
|
||||
require'lspconfig'[server].setup{
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
metals_config = require("metals").bare_config
|
||||
metals_config.init_options.statusBarProvider = "on"
|
||||
metals_config.settings = { showImplicitArguments = true }
|
||||
metals_config.on_attach = on_attach
|
||||
|
||||
vim.cmd [[augroup lsp]]
|
||||
vim.cmd [[au!]]
|
||||
vim.cmd [[au FileType scala,sbt lua require("metals").initialize_or_attach(metals_config)]]
|
||||
vim.cmd [[augroup end]]
|
||||
|
||||
-- Use a loop to conveniently call 'setup' on multiple servers and
|
||||
-- map buffer local keybindings when the language server attaches
|
||||
local servers = { "lemminx" }
|
||||
for _, lsp in ipairs(servers) do
|
||||
nvim_lsp[lsp].setup {
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
flags = {
|
||||
debounce_text_changes = 150,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
|
||||
vim.lsp.diagnostic.on_publish_diagnostics, {
|
||||
virtual_text = false,
|
||||
underline = true,
|
||||
signs = true,
|
||||
}
|
||||
)
|
||||
|
||||
-- vim.cmd [[autocmd CursorMoved * lua vim.lsp.diagnostic.show_line_diagnostics()]]
|
||||
-- vim.cmd [[autocmd CursorMoved * lua vim.lsp.diagnostic.show_line_diagnostics()]]
|
||||
vim.cmd [[autocmd CursorHoldI * silent! lua vim.lsp.buf.signature_help()]]
|
||||
vim.cmd [[autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics({max_width = 100, focusable = false})]]
|
Loading…
Add table
Add a link
Reference in a new issue