aboutsummaryrefslogtreecommitdiff
path: root/lua/config/lsp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/config/lsp.lua')
-rw-r--r--lua/config/lsp.lua17
1 files changed, 15 insertions, 2 deletions
diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua
index c0d18d8..156566c 100644
--- a/lua/config/lsp.lua
+++ b/lua/config/lsp.lua
@@ -1,3 +1,13 @@
+local M = {}
+
+function M.show_line_diagnostics()
+ local opts = {
+ focusable = false,
+ close_events = {'BufLeave', 'CursorMoved', 'InsertEnter', 'FocusLost'}
+ }
+ vim.lsp.diagnostic.show_line_diagnostics(opts)
+end
+
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
@@ -23,8 +33,9 @@ local on_attach = function(client, bufnr)
buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
- -- Show diagnostic automatically when cursor is on hold.
- vim.api.nvim_command('autocmd CursorHold <buffer> lua vim.lsp.diagnostic.show_line_diagnostics({focusable=false})')
+ vim.cmd [[
+ autocmd CursorHold <buffer> lua require('config.lsp').show_line_diagnostics()
+ ]]
-- Set some keybinds conditional on server capabilities
if client.resolved_capabilities.document_formatting then
@@ -148,3 +159,5 @@ vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
border = 'rounded'
}
)
+
+return M