diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2022-10-20 13:47:23 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2022-10-20 13:47:23 +0200 |
commit | ccde4a982e6fa26086d662aeea2b7285cc6ab4f7 (patch) | |
tree | 82ca0a18f574143964ed769dd2d9ba1009b5a573 /lua/user/lsp/handlers.lua | |
parent | 88e7c8bdb0b002be8ddad75633153c4d03a30632 (diff) | |
download | vim-ccde4a982e6fa26086d662aeea2b7285cc6ab4f7.zip vim-ccde4a982e6fa26086d662aeea2b7285cc6ab4f7.tar.gz |
switch from nvim-lsp-installer to mason
Diffstat (limited to 'lua/user/lsp/handlers.lua')
-rw-r--r-- | lua/user/lsp/handlers.lua | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/lua/user/lsp/handlers.lua b/lua/user/lsp/handlers.lua index 0758841..853beb3 100644 --- a/lua/user/lsp/handlers.lua +++ b/lua/user/lsp/handlers.lua @@ -1,21 +1,21 @@ local M = {} --- TODO: backfill this to template -M.setup = function() - local signs = { - { name = "DiagnosticSignError", text = "" }, - { name = "DiagnosticSignWarn", text = "" }, - { name = "DiagnosticSignHint", text = "" }, - { name = "DiagnosticSignInfo", text = "" }, - } +local cmp_nvim_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") +if not cmp_nvim_ok then + print "cpm_nvim_lsp init failed" + return +end - for _, sign in ipairs(signs) do - vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) +M.setup = function() + local signs = { Error = "", Warn = "", Hint = "", Info = "" } + for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) end local config = { -- disable virtual text - virtual_text = true, + virtual_text = false, -- show signs signs = { active = signs, @@ -44,7 +44,7 @@ M.setup = function() }) end -local function lsp_highlight_document(client) +local function lsp_highlight(client) -- Set autocommands conditional on server_capabilities if client.server_capabilities.document_highlight then vim.api.nvim_exec( @@ -60,20 +60,22 @@ local function lsp_highlight_document(client) end end +local keymap = vim.keymap.set + local function lsp_keymaps(bufnr) - local opts = { noremap = true, silent = true } + local opts = { buffer = bufnr, noremap = true, silent = true } -- SEE : https://neovim.io/doc/user/lsp.html - vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "ga", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts) + keymap("n", "gd", vim.lsp.buf.definition, opts) + keymap("n", "gr", vim.lsp.buf.references, opts) + keymap("n", "gi", vim.lsp.buf.implementation, opts) + keymap("n", "ga", vim.lsp.buf.declaration, opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gb", "<cmd>lua vim.lsp.buf.hover()<CR>", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gé", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gk", '<cmd>lua vim.diagnostic.open_float({ border = "rounded" })<CR>', opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "g.", '<cmd>lua vim.diagnostic.goto_next({ border = "rounded" })<CR>', opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gx", '<cmd>lua vim.diagnostic.goto_prev({ border = "rounded" })<CR>', opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>q", "<cmd>lua vim.diagnostic.setloclist()<CR>", opts) + keymap("n", "gb", vim.lsp.buf.hover, opts) + keymap("n", "gé", vim.lsp.buf.signature_help, opts) + keymap("n", "gk", vim.diagnostic.open_float, opts) + keymap("n", "g.", vim.diagnostic.goto_next, opts) + keymap("n", "gx", vim.diagnostic.goto_prev, opts) + keymap("n", "<leader>q", vim.diagnostic.setloclist, opts) vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]] -- FIXME what ? end @@ -82,16 +84,11 @@ M.on_attach = function(client, bufnr) client.server_capabilities.document_formatting = false end lsp_keymaps(bufnr) - lsp_highlight_document(client) + lsp_highlight(client) end local capabilities = vim.lsp.protocol.make_client_capabilities() -local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") -if not status_ok then - return -end - M.capabilities = cmp_nvim_lsp.default_capabilities(capabilities) return M |