home: vim: use smarter diagnostics float display
All checks were successful
ci/woodpecker/push/check Pipeline was successful
All checks were successful
ci/woodpecker/push/check Pipeline was successful
This commit is contained in:
parent
7c4e0e31bc
commit
5de4ee93d5
|
@ -1,5 +1,7 @@
|
||||||
local wk = require("which-key")
|
local wk = require("which-key")
|
||||||
|
|
||||||
|
local lsp = require("ambroisie.lsp")
|
||||||
|
|
||||||
local keys = {
|
local keys = {
|
||||||
-- Edition and navigation mappins
|
-- Edition and navigation mappins
|
||||||
["["] = {
|
["["] = {
|
||||||
|
@ -30,7 +32,7 @@ local keys = {
|
||||||
x = "XML encode",
|
x = "XML encode",
|
||||||
y = "C string encode",
|
y = "C string encode",
|
||||||
-- Custom
|
-- Custom
|
||||||
d = { vim.diagnostic.goto_prev, "Previous diagnostic" },
|
d = { lsp.goto_prev_diagnostic, "Previous diagnostic" },
|
||||||
},
|
},
|
||||||
["]"] = {
|
["]"] = {
|
||||||
name = "Next",
|
name = "Next",
|
||||||
|
@ -60,7 +62,7 @@ local keys = {
|
||||||
x = "XML decode",
|
x = "XML decode",
|
||||||
y = "C string decode",
|
y = "C string decode",
|
||||||
-- Custom
|
-- Custom
|
||||||
d = { vim.diagnostic.goto_next, "Next diagnostic" },
|
d = { lsp.goto_next_diagnostic, "Next diagnostic" },
|
||||||
},
|
},
|
||||||
|
|
||||||
-- Option mappings
|
-- Option mappings
|
||||||
|
|
|
@ -3,6 +3,43 @@ local M = {}
|
||||||
-- Simplified LSP formatting configuration
|
-- Simplified LSP formatting configuration
|
||||||
local lsp_format = require("lsp-format")
|
local lsp_format = require("lsp-format")
|
||||||
|
|
||||||
|
-- Move to the next/previous diagnostic, automatically showing the diagnostics
|
||||||
|
-- float if necessary.
|
||||||
|
-- @param forward whether to go forward or backwards
|
||||||
|
local function goto_diagnostic(forward)
|
||||||
|
vim.validate({
|
||||||
|
forward = { forward, "boolean" },
|
||||||
|
})
|
||||||
|
|
||||||
|
local opts = {
|
||||||
|
float = false,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Only show floating diagnostics if they are otherwise not displayed
|
||||||
|
local config = vim.diagnostic.config()
|
||||||
|
if not (config.virtual_text or config.virtual_lines) then
|
||||||
|
opts.float = true
|
||||||
|
end
|
||||||
|
|
||||||
|
if forward then
|
||||||
|
vim.diagnostic.goto_next(opts)
|
||||||
|
else
|
||||||
|
vim.diagnostic.goto_prev(opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Move to the next diagnostic, automatically showing the diagnostics float if
|
||||||
|
-- necessary.
|
||||||
|
M.goto_next_diagnostic = function()
|
||||||
|
goto_diagnostic(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Move to the previous diagnostic, automatically showing the diagnostics float
|
||||||
|
-- if necessary.
|
||||||
|
M.goto_prev_diagnostic = function()
|
||||||
|
goto_diagnostic(false)
|
||||||
|
end
|
||||||
|
|
||||||
-- shared LSP configuration callback
|
-- shared LSP configuration callback
|
||||||
-- @param client native client configuration
|
-- @param client native client configuration
|
||||||
-- @param bufnr int? buffer number of the attched client
|
-- @param bufnr int? buffer number of the attched client
|
||||||
|
|
Loading…
Reference in a new issue