diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index a9633d5..32dc0ec 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -1,4 +1,3 @@ -local fn = vim.fn local api = vim.api local keymap = vim.keymap local lsp = vim.lsp @@ -31,16 +30,16 @@ local custom_attach = function(client, bufnr) map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) map("n", "", vim.lsp.buf.definition) map("n", "K", function() - vim.lsp.buf.hover { border = "rounded" } + vim.lsp.buf.hover { border = "single", max_height = 25 } end) map("n", "", vim.lsp.buf.signature_help) map("n", "rn", vim.lsp.buf.rename, { desc = "varialbe rename" }) map("n", "gr", vim.lsp.buf.references, { desc = "show references" }) map("n", "[d", function() - diagnostic.jump { count = -1, float = true } + diagnostic.jump { count = -1 } end, { desc = "previous diagnostic" }) map("n", "]d", function() - diagnostic.jump { count = 1, float = true } + diagnostic.jump { count = 1 } end, { desc = "next diagnostic" }) -- this puts diagnostics from opened files to quickfix map("n", "qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" }) @@ -64,33 +63,6 @@ local custom_attach = function(client, bufnr) -- but disable this feature by default, so you may need to enable inlay hint in the LSP server config. -- vim.lsp.inlay_hint.enable(true, {buffer=bufnr}) - api.nvim_create_autocmd("CursorHold", { - buffer = bufnr, - callback = function() - local float_opts = { - focusable = false, - close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, - border = "rounded", - source = "always", -- show source in diagnostic popup window - prefix = " ", - } - - if not vim.b.diagnostics_pos then - vim.b.diagnostics_pos = { nil, nil } - end - - local cursor_pos = api.nvim_win_get_cursor(0) - if - (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) - and #diagnostic.get() > 0 - then - diagnostic.open_float(nil, float_opts) - end - - vim.b.diagnostics_pos = cursor_pos - end, - }) - -- The blow command will highlight the current variable and its usages in the buffer. if client.server_capabilities.documentHighlightProvider then vim.cmd([[ @@ -288,6 +260,7 @@ end diagnostic.config { underline = false, virtual_text = false, + virtual_lines = false, signs = { text = { [diagnostic.severity.ERROR] = "🆇", @@ -297,4 +270,30 @@ diagnostic.config { }, }, severity_sort = true, + float = { + source = true, + header = "Diagnostics:", + prefix = " ", + border = "single", + }, } + +api.nvim_create_autocmd("CursorHold", { + pattern = "*", + callback = function() + if #vim.diagnostic.get(0) == 0 then + return + end + + if not vim.b.diagnostics_pos then + vim.b.diagnostics_pos = { nil, nil } + end + + local cursor_pos = api.nvim_win_get_cursor(0) + if cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2] then + diagnostic.open_float() + end + + vim.b.diagnostics_pos = cursor_pos + end, +}) diff --git a/lua/globals.lua b/lua/globals.lua index e0bdad6..2163360 100644 --- a/lua/globals.lua +++ b/lua/globals.lua @@ -69,3 +69,6 @@ vim.g.loaded_matchparen = 1 -- Disable sql omni completion, it is broken. vim.g.loaded_sql_completion = 1 + +-- control how to show health check window +vim.g.health = { style = nil } diff --git a/lua/mappings.lua b/lua/mappings.lua index 368035b..9915ef5 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -23,19 +23,6 @@ keymap.set("n", "q", "x", { silent = true, desc = "quit current -- Quit all opened buffers keymap.set("n", "Q", "qa!", { silent = true, desc = "quit nvim" }) --- Navigation in the location and quickfix list -keymap.set("n", "[l", "lpreviouszv", { silent = true, desc = "previous location item" }) -keymap.set("n", "]l", "lnextzv", { silent = true, desc = "next location item" }) - -keymap.set("n", "[L", "lfirstzv", { silent = true, desc = "first location item" }) -keymap.set("n", "]L", "llastzv", { silent = true, desc = "last location item" }) - -keymap.set("n", "[q", "cpreviouszv", { silent = true, desc = "previous qf item" }) -keymap.set("n", "]q", "cnextzv", { silent = true, desc = "next qf item" }) - -keymap.set("n", "[Q", "cfirstzv", { silent = true, desc = "first qf item" }) -keymap.set("n", "]Q", "clastzv", { silent = true, desc = "last qf item" }) - -- Close location list or quickfix list if they are present, see https://superuser.com/q/355325/736190 keymap.set("n", [[\x]], "windo lclose cclose ", { silent = true, diff --git a/viml_conf/options.vim b/viml_conf/options.vim index d0e813d..3190285 100644 --- a/viml_conf/options.vim +++ b/viml_conf/options.vim @@ -115,6 +115,8 @@ set shortmess+=S " Disable showing intro message (:intro) set shortmess+=I +set messagesopt=wait:5000,history:500 + " Completion behaviour " set completeopt+=noinsert " Auto select the first completion entry set completeopt+=menuone " Show menu even if there is only one item