aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/_inspector.lua
diff options
context:
space:
mode:
authorLuuk van Baal <luukvbaal@gmail.com>2025-03-17 00:18:27 +0100
committerChristian Clason <ch.clason+github@icloud.com>2025-03-18 09:39:19 +0100
commitd40481322a7959d36804cb4f438d8756fb8171a0 (patch)
tree60e2bbe5d0be20bcc39aeadff301d9d236d24fb8 /runtime/lua/vim/_inspector.lua
parent1369d86812a55d2a1a575299e05e75ea4a6a8461 (diff)
downloadrneovim-d40481322a7959d36804cb4f438d8756fb8171a0.tar.gz
rneovim-d40481322a7959d36804cb4f438d8756fb8171a0.tar.bz2
rneovim-d40481322a7959d36804cb4f438d8756fb8171a0.zip
fix(lua): ensure inspect_pos() only shows visible highlight extmarks
Problem: Unpaired marks are shown with `filter.extmarks == true`, which should only return visible highlights. Misleading `end_col` included in `inspect_pos()` for unpaired mark; it is set to `start_col + 1` which would be a visible highlight, which it is not. Custom "is_here" filter used to get extmarks overlapping a position. Solution: Exclude unpaired highlight extmarks with `filter.extmarks == true`. Set `end_col` to `start_col` for an unpaired mark. Supply appropriate arguments to nvim_buf_get_extmarks() to return overlapping extmarks; exclude marks whose end is at `{row, col}` with `filter.extmarks == true`.
Diffstat (limited to 'runtime/lua/vim/_inspector.lua')
-rw-r--r--runtime/lua/vim/_inspector.lua32
1 files changed, 17 insertions, 15 deletions
diff --git a/runtime/lua/vim/_inspector.lua b/runtime/lua/vim/_inspector.lua
index 35063dffca..08dc2c5c78 100644
--- a/runtime/lua/vim/_inspector.lua
+++ b/runtime/lua/vim/_inspector.lua
@@ -104,30 +104,32 @@ function vim.inspect_pos(bufnr, row, col, filter)
--- Convert an extmark tuple into a table
local function to_map(extmark)
- extmark = {
+ local opts = resolve_hl(extmark[4])
+ return {
id = extmark[1],
row = extmark[2],
col = extmark[3],
- opts = resolve_hl(extmark[4]),
+ end_row = opts.end_row or extmark[2],
+ end_col = opts.end_col or extmark[3],
+ opts = opts,
+ ns_id = opts.ns_id,
+ ns = nsmap[opts.ns_id] or '',
}
- extmark.ns_id = extmark.opts.ns_id
- extmark.ns = nsmap[extmark.ns_id] or ''
- extmark.end_row = extmark.opts.end_row or extmark.row -- inclusive
- extmark.end_col = extmark.opts.end_col or (extmark.col + 1) -- exclusive
- return extmark
end
- --- Check if an extmark overlaps this position
- local function is_here(extmark)
- return (row >= extmark.row and row <= extmark.end_row) -- within the rows of the extmark
- and (row > extmark.row or col >= extmark.col) -- either not the first row, or in range of the col
- and (row < extmark.end_row or col < extmark.end_col) -- either not in the last row or in range of the col
+ --- Exclude end_col and unpaired marks from the overlapping marks, unless
+ --- filter.extmarks == 'all' (a highlight is drawn until end_col - 1).
+ local function exclude_end_col(extmark)
+ return filter.extmarks == 'all' or row < extmark.end_row or col < extmark.end_col
end
- -- all extmarks at this position
- local extmarks = vim.api.nvim_buf_get_extmarks(bufnr, -1, 0, -1, { details = true })
+ -- All overlapping extmarks at this position:
+ local extmarks = vim.api.nvim_buf_get_extmarks(bufnr, -1, { row, col }, { row, col }, {
+ details = true,
+ overlap = true,
+ })
extmarks = vim.tbl_map(to_map, extmarks)
- extmarks = vim.tbl_filter(is_here, extmarks)
+ extmarks = vim.tbl_filter(exclude_end_col, extmarks)
if filter.semantic_tokens then
results.semantic_tokens = vim.tbl_filter(function(extmark)