diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-04-03 13:08:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-03 13:08:28 +0200 |
commit | f28da92b46090051ce83e642098562faf1693154 (patch) | |
tree | 333d0df17eea9e0d4816cf128becdea0a15307e4 /runtime/lua/vim | |
parent | f4cbe0360651123d7f33ddbaa046f797c7d73671 (diff) | |
parent | a93024555720325ecede9d2d15e4bd0f1fd82739 (diff) | |
download | rneovim-f28da92b46090051ce83e642098562faf1693154.tar.gz rneovim-f28da92b46090051ce83e642098562faf1693154.tar.bz2 rneovim-f28da92b46090051ce83e642098562faf1693154.zip |
Merge pull request #22783 from luukvbaal/inspect
refactor(lua): get all extmarks instead of iterating over namespaces
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/_inspector.lua | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/runtime/lua/vim/_inspector.lua b/runtime/lua/vim/_inspector.lua index 92d380b08c..05983d3f0d 100644 --- a/runtime/lua/vim/_inspector.lua +++ b/runtime/lua/vim/_inspector.lua @@ -81,6 +81,12 @@ function vim.inspect_pos(bufnr, row, col, filter) 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 --- @private local function to_map(extmark) @@ -90,6 +96,8 @@ function vim.inspect_pos(bufnr, row, col, filter) col = extmark[3], 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_col = extmark.opts.end_col or (extmark.col + 1) -- exclusive return extmark @@ -104,17 +112,9 @@ function vim.inspect_pos(bufnr, row, col, filter) end -- all extmarks at this position - local extmarks = {} - for ns, nsid in pairs(vim.api.nvim_get_namespaces()) do - local ns_marks = vim.api.nvim_buf_get_extmarks(bufnr, nsid, 0, -1, { details = true }) - 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 + local extmarks = vim.api.nvim_buf_get_extmarks(bufnr, -1, 0, -1, { details = true }) + extmarks = vim.tbl_map(to_map, extmarks) + extmarks = vim.tbl_filter(is_here, extmarks) if filter.semantic_tokens then results.semantic_tokens = vim.tbl_filter(function(extmark) |