diff --git a/lua/plugins/completions.lua b/lua/plugins/completions.lua index bf756da..cdf2613 100644 --- a/lua/plugins/completions.lua +++ b/lua/plugins/completions.lua @@ -4,7 +4,6 @@ return { 'williamboman/mason.nvim', 'williamboman/mason-lspconfig.nvim', - 'neovim/nvim-lspconfig', 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', @@ -42,5 +41,52 @@ return { -- TODO: snippets }, }) - end, + + -- Disable displaying diagnostics as virtual text + vim.diagnostic.config({ + virtual_text = false, + }) + + -- Diagnostic mappings + -- TODO: trouble.nvim mappings instead? https://youtu.be/MuUrCcvE-Yw?t=631 + vim.keymap.set('n', '', vim.diagnostic.goto_next, { noremap = true }) + vim.keymap.set('n', '', vim.diagnostic.goto_prev, { noremap = true }) + vim.keymap.set('n', 'sd', vim.diagnostic.open_float, { noremap = true }) + + -- Mappings to create once a language server attaches to a buffer + local augroup = vim.api.nvim_create_augroup('lsp', { clear = true }) + vim.api.nvim_create_autocmd('LspAttach', { + pattern = '*', + group = augroup, + callback = function(ev) + local opts = { noremap = true, buffer = ev.buf } + + -- FIXME: Should I drop this? It's only for expanding snippets because + -- coc.nvim was being weird about it + -- inoremap coc#pum#visible() ? coc#pum#confirm() : "\" + + vim.keymap.set('n', 'fi', function() + -- FIXME: This doesn't stop the prompt to select the code action when + -- there is only one. Also not sure if its actually filtering + vim.lsp.buf.code_action({ context = { only = { 'quickfix' } } }) + end, opts) + + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + + -- nnoremap gt (coc-type-definition) + + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + + -- nnoremap gu (coc-references-used) + + -- Refactoring mappings + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + -- TODO: vim.lsp.buf.format + + -- Help mappings + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('i', '', vim.lsp.buf.signature_help, opts) + end + }) + end }