aboutsummaryrefslogtreecommitdiff
path: root/lua/config/lsp.lua
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2022-04-16 12:07:48 +0800
committerjdhao <jdhao@hotmail.com>2022-04-16 12:07:48 +0800
commita3795cd0436f3bf41bb8da9c2e1122e9a100b81e (patch)
tree9511e4064d68dc0d7831acb7ce9e66f3eeba27d3 /lua/config/lsp.lua
parentb4c55edb446c6b80f0a725fef061fcab0249bc7e (diff)
[nvim 0.7] use native lua autocmd for cleaner code
Diffstat (limited to 'lua/config/lsp.lua')
-rw-r--r--lua/config/lsp.lua31
1 files changed, 13 insertions, 18 deletions
diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua
index 7b0c67e..9ead5e5 100644
--- a/lua/config/lsp.lua
+++ b/lua/config/lsp.lua
@@ -3,19 +3,6 @@ local lsp = vim.lsp
local utils = require("utils")
-local M = {}
-
-function M.show_line_diagnostics()
- local opts = {
- focusable = false,
- close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
- border = 'rounded',
- source = 'always', -- show source in diagnostic popup window
- prefix = ' '
- }
- vim.diagnostic.open_float(nil, opts)
-end
-
local custom_attach = function(client, bufnr)
-- Mappings.
local opts = { silent = true, buffer = bufnr }
@@ -33,9 +20,19 @@ local custom_attach = function(client, bufnr)
vim.keymap.set("n", "<space>q", function() vim.diagnostic.setqflist({open = true}) end, opts)
vim.keymap.set("n", "<space>ca", vim.lsp.buf.code_action, opts)
- vim.cmd([[
- autocmd CursorHold <buffer> lua require('config.lsp').show_line_diagnostics()
- ]])
+ vim.api.nvim_create_autocmd("CursorHold", {
+ buffer=bufnr,
+ callback = function()
+ local opts = {
+ focusable = false,
+ close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
+ border = 'rounded',
+ source = 'always', -- show source in diagnostic popup window
+ prefix = ' '
+ }
+ vim.diagnostic.open_float(nil, opts)
+ end
+ })
-- Set some key bindings conditional on server capabilities
if client.resolved_capabilities.document_formatting then
@@ -200,5 +197,3 @@ vim.diagnostic.config({
lsp.handlers["textDocument/hover"] = lsp.with(vim.lsp.handlers.hover, {
border = "rounded",
})
-
-return M