From b9ef74b412c2406b2f64f589aa8388e4778c4ce0 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 13 Dec 2021 22:04:05 -0300 Subject: [PATCH] Agragados mappings para los LSP --- init.lua | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 688c98c..fca2ae4 100644 --- a/init.lua +++ b/init.lua @@ -66,10 +66,47 @@ ts.setup {ensure_installed = 'maintained', highlight = {enable = true, indent = ---- LSP ---- local lsp = require 'lspconfig' --- Golang -- -require'lspconfig'.golangci_lint_ls.setup{on_attach=require'completion'.on_attach} --- Rust -- -require'lspconfig'.rust_analyzer.setup{on_attach=require'completion'.on_attach} + +-- 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 + 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', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', opts) + buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) + buf_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.formatting()', opts) +end + +-- Use a loop to conveniently call 'setup' on multiple servers and +-- map buffer local keybindings when the language server attaches +local servers = { 'gopls', 'rust_analyzer' } +for _, server in ipairs(servers) do + lsp[server].setup { + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + } + } +end ---- Plugins ---- ---- ale @@ -78,6 +115,7 @@ g.ale_linters = { c = {}, cpp = {}, css = {'stylelint'}, + go = {'gobuild', 'golangci-lint'}, html = {'tidy'}, javascript = {'eslint'}, python = {'flake8'},