From 7574d58304aa3b030aca8f5feafc0f92ec1d81e2 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 28 Feb 2023 12:12:08 +0100 Subject: fix(inspect): alwasy resolve full treesitter lang hl groups --- runtime/lua/vim/_inspector.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/_inspector.lua') diff --git a/runtime/lua/vim/_inspector.lua b/runtime/lua/vim/_inspector.lua index f46a525910..bb6608421b 100644 --- a/runtime/lua/vim/_inspector.lua +++ b/runtime/lua/vim/_inspector.lua @@ -69,7 +69,7 @@ function vim.inspect_pos(bufnr, row, col, filter) -- treesitter if filter.treesitter then for _, capture in pairs(vim.treesitter.get_captures_at_pos(bufnr, row, col)) do - capture.hl_group = '@' .. capture.capture + capture.hl_group = '@' .. capture.capture .. '.' .. capture.lang table.insert(results.treesitter, resolve_hl(capture)) end end -- cgit From 1f07307aeb6564fb794921cc1b2879f84a822921 Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Sat, 4 Mar 2023 22:05:46 +0900 Subject: docs(inspect): number → integer (#22511) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/lua/vim/_inspector.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'runtime/lua/vim/_inspector.lua') diff --git a/runtime/lua/vim/_inspector.lua b/runtime/lua/vim/_inspector.lua index bb6608421b..9e91597192 100644 --- a/runtime/lua/vim/_inspector.lua +++ b/runtime/lua/vim/_inspector.lua @@ -14,15 +14,15 @@ local defaults = { --- ---Can also be pretty-printed with `:Inspect!`. *:Inspect!* --- ----@param bufnr? number defaults to the current buffer ----@param row? number row to inspect, 0-based. Defaults to the row of the current cursor ----@param col? number col to inspect, 0-based. Defaults to the col of the current cursor +---@param bufnr? integer defaults to the current buffer +---@param row? integer row to inspect, 0-based. Defaults to the row of the current cursor +---@param col? integer col to inspect, 0-based. Defaults to the col of the current cursor ---@param filter? InspectorFilter (table|nil) a table with key-value pairs to filter the items --- - syntax (boolean): include syntax based highlight groups (defaults to true) --- - treesitter (boolean): include treesitter based highlight groups (defaults to true) --- - extmarks (boolean|"all"): include extmarks. When `all`, then extmarks without a `hl_group` will also be included (defaults to true) --- - semantic_tokens (boolean): include semantic tokens (defaults to true) ----@return {treesitter:table,syntax:table,extmarks:table,semantic_tokens:table,buffer:number,col:number,row:number} (table) a table with the following key-value pairs. Items are in "traversal order": +---@return {treesitter:table,syntax:table,extmarks:table,semantic_tokens:table,buffer:integer,col:integer,row:integer} (table) a table with the following key-value pairs. Items are in "traversal order": --- - treesitter: a list of treesitter captures --- - syntax: a list of syntax groups --- - semantic_tokens: a list of semantic tokens @@ -129,9 +129,9 @@ end --- ---Can also be shown with `:Inspect`. *:Inspect* --- ----@param bufnr? number defaults to the current buffer ----@param row? number row to inspect, 0-based. Defaults to the row of the current cursor ----@param col? number col to inspect, 0-based. Defaults to the col of the current cursor +---@param bufnr? integer defaults to the current buffer +---@param row? integer row to inspect, 0-based. Defaults to the row of the current cursor +---@param col? integer col to inspect, 0-based. Defaults to the col of the current cursor ---@param filter? InspectorFilter (table|nil) see |vim.inspect_pos()| function vim.show_pos(bufnr, row, col, filter) local items = vim.inspect_pos(bufnr, row, col, filter) -- cgit From 1cc23e1109ed88275df5c986c352f73b99a0301c Mon Sep 17 00:00:00 2001 From: swarn Date: Mon, 6 Mar 2023 12:03:13 -0600 Subject: feat(lsp)!: add rule-based sem token highlighting (#22022) feat(lsp)!: change semantic token highlighting Change the default highlights used, and add more highlights per token. Add an LspTokenUpdate event and a highlight_token function. :Inspect now shows any highlights applied by token highlighting rules, default or user-defined. BREAKING CHANGE: change the default highlight groups used by semantic token highlighting. --- runtime/lua/vim/_inspector.lua | 97 +++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 44 deletions(-) (limited to 'runtime/lua/vim/_inspector.lua') diff --git a/runtime/lua/vim/_inspector.lua b/runtime/lua/vim/_inspector.lua index 9e91597192..92d380b08c 100644 --- a/runtime/lua/vim/_inspector.lua +++ b/runtime/lua/vim/_inspector.lua @@ -2,7 +2,7 @@ ---@field syntax boolean include syntax based highlight groups (defaults to true) ---@field treesitter boolean include treesitter based highlight groups (defaults to true) ---@field extmarks boolean|"all" include extmarks. When `all`, then extmarks without a `hl_group` will also be included (defaults to true) ----@field semantic_tokens boolean include semantic tokens (defaults to true) +---@field semantic_tokens boolean include semantic token highlights (defaults to true) local defaults = { syntax = true, treesitter = true, @@ -81,47 +81,54 @@ function vim.inspect_pos(bufnr, row, col, filter) end end - -- semantic tokens - if filter.semantic_tokens then - for _, token in ipairs(vim.lsp.semantic_tokens.get_at_pos(bufnr, row, col) or {}) do - token.hl_groups = { - type = resolve_hl({ hl_group = '@' .. token.type }), - modifiers = vim.tbl_map(function(modifier) - return resolve_hl({ hl_group = '@' .. modifier }) - end, token.modifiers or {}), - } - table.insert(results.semantic_tokens, token) + --- Convert an extmark tuple into a map-like table + --- @private + local function to_map(extmark) + extmark = { + id = extmark[1], + row = extmark[2], + col = extmark[3], + opts = resolve_hl(extmark[4]), + } + 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 + --- @private + 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 + 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 + + if filter.semantic_tokens then + results.semantic_tokens = vim.tbl_filter(function(extmark) + return extmark.ns:find('vim_lsp_semantic_tokens') == 1 + end, extmarks) end - -- extmarks if filter.extmarks then - for ns, nsid in pairs(vim.api.nvim_get_namespaces()) do - if ns:find('vim_lsp_semantic_tokens') ~= 1 then - local extmarks = vim.api.nvim_buf_get_extmarks(bufnr, nsid, 0, -1, { details = true }) - for _, extmark in ipairs(extmarks) do - extmark = { - ns_id = nsid, - ns = ns, - id = extmark[1], - row = extmark[2], - col = extmark[3], - opts = resolve_hl(extmark[4]), - } - local end_row = extmark.opts.end_row or extmark.row -- inclusive - local end_col = extmark.opts.end_col or (extmark.col + 1) -- exclusive - if - (filter.extmarks == 'all' or extmark.opts.hl_group) -- filter hl_group - and (row >= extmark.row and row <= 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 < end_row or col < end_col) -- either not in the last row or in range of the col - then - table.insert(results.extmarks, extmark) - end - end - end - end + results.extmarks = vim.tbl_filter(function(extmark) + return extmark.ns:find('vim_lsp_semantic_tokens') ~= 1 + and (filter.extmarks == 'all' or extmark.opts.hl_group) + end, extmarks) end + return results end @@ -174,16 +181,17 @@ function vim.show_pos(bufnr, row, col, filter) nl() end + -- semantic tokens if #items.semantic_tokens > 0 then append('Semantic Tokens', 'Title') nl() - for _, token in ipairs(items.semantic_tokens) do - local client = vim.lsp.get_client_by_id(token.client_id) - client = client and (' (' .. client.name .. ')') or '' - item(token.hl_groups.type, 'type' .. client) - for _, modifier in ipairs(token.hl_groups.modifiers) do - item(modifier, 'modifier' .. client) - end + local sorted_marks = vim.fn.sort(items.semantic_tokens, function(left, right) + local left_first = left.opts.priority < right.opts.priority + or left.opts.priority == right.opts.priority and left.opts.hl_group < right.opts.hl_group + return left_first and -1 or 1 + end) + for _, extmark in ipairs(sorted_marks) do + item(extmark.opts, 'priority: ' .. extmark.opts.priority) end nl() end @@ -197,6 +205,7 @@ function vim.show_pos(bufnr, row, col, filter) end nl() end + -- extmarks if #items.extmarks > 0 then append('Extmarks', 'Title') -- cgit From a93024555720325ecede9d2d15e4bd0f1fd82739 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Sat, 25 Mar 2023 15:19:22 +0100 Subject: refactor(lua): get all marks instead of iterating over namespaces Inspector now also includes highlights set in anonymous namespaces. Close #22732 --- runtime/lua/vim/_inspector.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'runtime/lua/vim/_inspector.lua') 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) -- cgit From 2f779b94e7fe0fb2fba00dd8e644c60605e83179 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 16 Apr 2023 17:50:32 +0800 Subject: fix(lua): inspect_pos respect bufnr when get syntax info (#23098) --- runtime/lua/vim/_inspector.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'runtime/lua/vim/_inspector.lua') diff --git a/runtime/lua/vim/_inspector.lua b/runtime/lua/vim/_inspector.lua index 05983d3f0d..2ebb7a7efd 100644 --- a/runtime/lua/vim/_inspector.lua +++ b/runtime/lua/vim/_inspector.lua @@ -70,15 +70,18 @@ function vim.inspect_pos(bufnr, row, col, filter) if filter.treesitter then for _, capture in pairs(vim.treesitter.get_captures_at_pos(bufnr, row, col)) do capture.hl_group = '@' .. capture.capture .. '.' .. capture.lang - table.insert(results.treesitter, resolve_hl(capture)) + results.treesitter[#results.treesitter + 1] = resolve_hl(capture) end end -- syntax - if filter.syntax then - for _, i1 in ipairs(vim.fn.synstack(row + 1, col + 1)) do - table.insert(results.syntax, resolve_hl({ hl_group = vim.fn.synIDattr(i1, 'name') })) - end + if filter.syntax and vim.api.nvim_buf_is_valid(bufnr) then + vim.api.nvim_buf_call(bufnr, function() + for _, i1 in ipairs(vim.fn.synstack(row + 1, col + 1)) do + results.syntax[#results.syntax + 1] = + resolve_hl({ hl_group = vim.fn.synIDattr(i1, 'name') }) + end + end) end -- namespace id -> name map -- cgit From 08991b078267e5de0a19a136d00d4f71ad651a32 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 13 May 2023 21:33:22 +0200 Subject: docs: small fixes Co-authored-by: Christian Clason Co-authored-by: Gregory Anders Co-authored-by: HiPhish Co-authored-by: Julio B Co-authored-by: T727 <74924917+T-727@users.noreply.github.com> Co-authored-by: camoz Co-authored-by: champignoom <66909116+champignoom@users.noreply.github.com> --- runtime/lua/vim/_inspector.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/_inspector.lua') diff --git a/runtime/lua/vim/_inspector.lua b/runtime/lua/vim/_inspector.lua index 2ebb7a7efd..ecd39c35bc 100644 --- a/runtime/lua/vim/_inspector.lua +++ b/runtime/lua/vim/_inspector.lua @@ -90,7 +90,7 @@ function vim.inspect_pos(bufnr, row, col, filter) nsmap[id] = name end - --- Convert an extmark tuple into a map-like table + --- Convert an extmark tuple into a table --- @private local function to_map(extmark) extmark = { -- cgit From be74807eef13ff8c90d55cf8b22b01d6d33b1641 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 18 Jul 2023 15:42:30 +0100 Subject: docs(lua): more improvements (#24387) * docs(lua): teach lua2dox how to table * docs(lua): teach gen_vimdoc.py about local functions No more need to mark local functions with @private * docs(lua): mention @nodoc and @meta in dev-lua-doc * fixup! Co-authored-by: Justin M. Keyes --------- Co-authored-by: Justin M. Keyes --- runtime/lua/vim/_inspector.lua | 6 ------ 1 file changed, 6 deletions(-) (limited to 'runtime/lua/vim/_inspector.lua') diff --git a/runtime/lua/vim/_inspector.lua b/runtime/lua/vim/_inspector.lua index ecd39c35bc..3f7b9d2c23 100644 --- a/runtime/lua/vim/_inspector.lua +++ b/runtime/lua/vim/_inspector.lua @@ -56,7 +56,6 @@ function vim.inspect_pos(bufnr, row, col, filter) } -- resolve hl links - ---@private local function resolve_hl(data) if data.hl_group then local hlid = vim.api.nvim_get_hl_id_by_name(data.hl_group) @@ -91,7 +90,6 @@ function vim.inspect_pos(bufnr, row, col, filter) end --- Convert an extmark tuple into a table - --- @private local function to_map(extmark) extmark = { id = extmark[1], @@ -107,7 +105,6 @@ function vim.inspect_pos(bufnr, row, col, filter) end --- Check if an extmark overlaps this position - --- @private 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 @@ -148,17 +145,14 @@ function vim.show_pos(bufnr, row, col, filter) local lines = { {} } - ---@private local function append(str, hl) table.insert(lines[#lines], { str, hl }) end - ---@private local function nl() table.insert(lines, {}) end - ---@private local function item(data, comment) append(' - ') append(data.hl_group, data.hl_group) -- cgit