Skip to content

Commit

Permalink
feat: added example plugin that shows a diagnostic at a certain label…
Browse files Browse the repository at this point in the history
… without moving the cursor
  • Loading branch information
folke committed Jun 21, 2023
1 parent d2e241f commit 7a9bd11
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
42 changes: 42 additions & 0 deletions lua/flash/plugins/diagnostics.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local State = require("flash.state")
local Util = require("flash.util")

local M = {}

function M.show()
local state = State.new({
search = { multi_window = true, wrap = true },
highlight = { backdrop = true, label = { current = true } },
matcher = function(win)
local buf = vim.api.nvim_win_get_buf(win)
---@param diag Diagnostic
return vim.tbl_map(function(diag)
return {
pos = { diag.lnum + 1, diag.col },
end_pos = { diag.end_lnum + 1, diag.end_col - 1 },
}
end, vim.diagnostic.get(buf))
end,
})

local pos = vim.api.nvim_win_get_cursor(0)

local char = Util.get_char()
if char then
local match = state:find({ label = char })
if match then
vim.api.nvim_win_call(match.win, function()
vim.api.nvim_win_set_cursor(match.win, match.pos)
vim.diagnostic.open_float()
vim.api.nvim_win_set_cursor(match.win, pos)
end)
else
vim.api.nvim_input(char)
end
state:hide()
end
end

M.show()

return M
2 changes: 0 additions & 2 deletions lua/flash/plugins/jumplist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,4 @@ function M.jump()
M.state:hide()
end

M.jump()

return M

0 comments on commit 7a9bd11

Please sign in to comment.