mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
refactor(lua): get all marks instead of iterating over namespaces
Inspector now also includes highlights set in anonymous namespaces. Close #22732
This commit is contained in:
@@ -81,6 +81,12 @@ function vim.inspect_pos(bufnr, row, col, filter)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- namespace id -> name map
|
||||||
|
local nsmap = {}
|
||||||
|
for name, id in pairs(vim.api.nvim_get_namespaces()) do
|
||||||
|
nsmap[id] = name
|
||||||
|
end
|
||||||
|
|
||||||
--- Convert an extmark tuple into a map-like table
|
--- Convert an extmark tuple into a map-like table
|
||||||
--- @private
|
--- @private
|
||||||
local function to_map(extmark)
|
local function to_map(extmark)
|
||||||
@@ -90,6 +96,8 @@ function vim.inspect_pos(bufnr, row, col, filter)
|
|||||||
col = extmark[3],
|
col = extmark[3],
|
||||||
opts = resolve_hl(extmark[4]),
|
opts = resolve_hl(extmark[4]),
|
||||||
}
|
}
|
||||||
|
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_row = extmark.opts.end_row or extmark.row -- inclusive
|
||||||
extmark.end_col = extmark.opts.end_col or (extmark.col + 1) -- exclusive
|
extmark.end_col = extmark.opts.end_col or (extmark.col + 1) -- exclusive
|
||||||
return extmark
|
return extmark
|
||||||
@@ -104,17 +112,9 @@ function vim.inspect_pos(bufnr, row, col, filter)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- all extmarks at this position
|
-- all extmarks at this position
|
||||||
local extmarks = {}
|
local extmarks = vim.api.nvim_buf_get_extmarks(bufnr, -1, 0, -1, { details = true })
|
||||||
for ns, nsid in pairs(vim.api.nvim_get_namespaces()) do
|
extmarks = vim.tbl_map(to_map, extmarks)
|
||||||
local ns_marks = vim.api.nvim_buf_get_extmarks(bufnr, nsid, 0, -1, { details = true })
|
extmarks = vim.tbl_filter(is_here, extmarks)
|
||||||
ns_marks = vim.tbl_map(to_map, ns_marks)
|
|
||||||
ns_marks = vim.tbl_filter(is_here, ns_marks)
|
|
||||||
for _, mark in ipairs(ns_marks) do
|
|
||||||
mark.ns_id = nsid
|
|
||||||
mark.ns = ns
|
|
||||||
end
|
|
||||||
vim.list_extend(extmarks, ns_marks)
|
|
||||||
end
|
|
||||||
|
|
||||||
if filter.semantic_tokens then
|
if filter.semantic_tokens then
|
||||||
results.semantic_tokens = vim.tbl_filter(function(extmark)
|
results.semantic_tokens = vim.tbl_filter(function(extmark)
|
||||||
|
@@ -12,9 +12,13 @@ describe('vim.inspect_pos', function()
|
|||||||
it('it returns items', function()
|
it('it returns items', function()
|
||||||
local ret = exec_lua([[
|
local ret = exec_lua([[
|
||||||
local buf = vim.api.nvim_create_buf(true, false)
|
local buf = vim.api.nvim_create_buf(true, false)
|
||||||
|
local ns1 = vim.api.nvim_create_namespace("ns1")
|
||||||
|
local ns2 = vim.api.nvim_create_namespace("")
|
||||||
vim.api.nvim_set_current_buf(buf)
|
vim.api.nvim_set_current_buf(buf)
|
||||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"})
|
vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"})
|
||||||
vim.api.nvim_buf_set_option(buf, "filetype", "lua")
|
vim.api.nvim_buf_set_option(buf, "filetype", "lua")
|
||||||
|
vim.api.nvim_buf_set_extmark(buf, ns1, 0, 10, { hl_group = "Normal" })
|
||||||
|
vim.api.nvim_buf_set_extmark(buf, ns2, 0, 10, { hl_group = "Normal" })
|
||||||
vim.cmd("syntax on")
|
vim.cmd("syntax on")
|
||||||
return {buf, vim.inspect_pos(0, 0, 10)}
|
return {buf, vim.inspect_pos(0, 0, 10)}
|
||||||
]])
|
]])
|
||||||
@@ -24,7 +28,42 @@ describe('vim.inspect_pos', function()
|
|||||||
buffer = buf,
|
buffer = buf,
|
||||||
col = 10,
|
col = 10,
|
||||||
row = 0,
|
row = 0,
|
||||||
extmarks = {},
|
extmarks = {
|
||||||
|
{
|
||||||
|
col = 10,
|
||||||
|
end_col = 11,
|
||||||
|
end_row = 0,
|
||||||
|
id = 1,
|
||||||
|
ns = 'ns1',
|
||||||
|
ns_id = 1,
|
||||||
|
opts = {
|
||||||
|
hl_eol = false,
|
||||||
|
hl_group = 'Normal',
|
||||||
|
hl_group_link = 'Normal',
|
||||||
|
ns_id = 1,
|
||||||
|
priority = 4096,
|
||||||
|
right_gravity = true
|
||||||
|
},
|
||||||
|
row = 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
col = 10,
|
||||||
|
end_col = 11,
|
||||||
|
end_row = 0,
|
||||||
|
id = 1,
|
||||||
|
ns = '',
|
||||||
|
ns_id = 2,
|
||||||
|
opts = {
|
||||||
|
hl_eol = false,
|
||||||
|
hl_group = 'Normal',
|
||||||
|
hl_group_link = 'Normal',
|
||||||
|
ns_id = 2,
|
||||||
|
priority = 4096,
|
||||||
|
right_gravity = true
|
||||||
|
},
|
||||||
|
row = 0
|
||||||
|
}
|
||||||
|
},
|
||||||
treesitter = {},
|
treesitter = {},
|
||||||
semantic_tokens = {},
|
semantic_tokens = {},
|
||||||
syntax = {
|
syntax = {
|
||||||
|
Reference in New Issue
Block a user