aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2021-07-29 22:31:36 +0800
committerjdhao <jdhao@hotmail.com>2021-07-29 22:31:36 +0800
commitc8777db448b7b501d70f492523723d163e63d8bb (patch)
tree79c54fddd4d9c95f73a114b6521dc6bbf7ae0ac1
parent13dc38343e8528c723eba32316eb4406b276ebe5 (diff)
update nvim-lsp settings
We shouldn't let the diagnostic window perstist forever. Close the diagnostic windows when certain events happen.
-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