From c8777db448b7b501d70f492523723d163e63d8bb Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 29 Jul 2021 22:31:36 +0800 Subject: [PATCH] update nvim-lsp settings We shouldn't let the diagnostic window perstist forever. Close the diagnostic windows when certain events happen. --- lua/config/lsp.lua | 17 +++++++++++++++-- 1 file 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', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - -- Show diagnostic automatically when cursor is on hold. - vim.api.nvim_command('autocmd CursorHold lua vim.lsp.diagnostic.show_line_diagnostics({focusable=false})') + vim.cmd [[ + autocmd CursorHold 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