From 6ebd6e83c60ff19d7a3cb74d4b11df2d67d2f8f1 Mon Sep 17 00:00:00 2001 From: Asmir A Date: Sat, 8 Jul 2023 17:11:09 +0200 Subject: [PATCH] don\'t display diagnostics by default --- vimrc.lua | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/vimrc.lua b/vimrc.lua index c470276..5f4e4d3 100644 --- a/vimrc.lua +++ b/vimrc.lua @@ -99,6 +99,49 @@ vim.api.nvim_create_autocmd('LspAttach', { end }) +-- Function to check if a floating dialog exists and if not +-- then check for diagnostics under the cursor +function OpenDiagnosticIfNoFloat() + for _, winid in pairs(vim.api.nvim_tabpage_list_wins(0)) do + if vim.api.nvim_win_get_config(winid).zindex then + return + end + end + -- THIS IS FOR BUILTIN LSP + vim.diagnostic.open_float(0, { + scope = "cursor", + focusable = false, + close_events = { + "CursorMoved", + "CursorMovedI", + "BufHidden", + "InsertCharPre", + "WinLeave", + }, + }) +end + +vim.diagnostic.config({ + virtual_text = false, -- Turn off inline diagnostics +}) +-- Show all diagnostics on current line in floating window +vim.api.nvim_set_keymap( + 'n', 'd', ':lua vim.diagnostic.open_float()', + { noremap = true, silent = true } +) +-- Go to next diagnostic (if there are multiple on the same line, only shows +-- one at a time in the floating window) +vim.api.nvim_set_keymap( + 'n', 'n', ':lua vim.diagnostic.goto_next()', + { noremap = true, silent = true } +) +-- Go to prev diagnostic (if there are multiple on the same line, only shows +-- one at a time in the floating window) +vim.api.nvim_set_keymap( + 'n', 'p', ':lua vim.diagnostic.goto_prev()', + { noremap = true, silent = true } +) + -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches local cmp = require 'cmp'