Add lsp-specific config

Mon, 13 Feb 2023 02:22:25 -0600

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 13 Feb 2023 02:22:25 -0600
changeset 1016
07d37da233ef
parent 1015
21950cadff6b
child 1017
6944e81bc60f

Add lsp-specific config

.config/nvim/lua/config/lsp.lua file | annotate | diff | comparison | revisions
new file mode 100644
--- /dev/null
+++ b/.config/nvim/lua/config/lsp.lua
@@ -0,0 +1,41 @@
+vim.diagnostic.config({
+  virtual_text = { true, severity = "WARN", },
+})
+
+vim.api.nvim_create_autocmd("LspAttach", {
+  once = true,
+  callback = function(args)
+    vim.opt.number = true
+  end,
+})
+
+local opts = { noremap=true, silent=true }
+vim.keymap.set('n', '<leader>d', vim.diagnostic.open_float, opts)
+vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
+vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
+vim.keymap.set('n', '<leader>ld', vim.diagnostic.setloclist, opts)
+
+vim.api.nvim_create_autocmd("LspAttach", {
+  callback = function(args)
+    local bufnr = args.buf
+    local bufopts = { noremap=true, silent=true, buffer=bufnr }
+
+    vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
+    vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
+    vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
+    vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
+    vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
+    vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, bufopts)
+    vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
+    vim.keymap.set('n', '<leader>wl', function()
+      print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
+    end, bufopts)
+    vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, bufopts)
+    vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, bufopts)
+    vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, bufopts)
+    vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
+    vim.keymap.set('n', '<leader>f', function() vim.lsp.buf.format { async = true } end, bufopts)
+  end,
+})
+
+

mercurial