From 318c0415d5b10b44fee4afa06994734f1beb7e71 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Sun, 1 Sep 2024 12:15:02 -0500 Subject: [PATCH] fix(ui): correctly pass metadata to get_node_text #30222 Fixes: #30220 --- runtime/lua/vim/_meta/api_keysets_extra.lua | 2 +- runtime/lua/vim/ui.lua | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/runtime/lua/vim/_meta/api_keysets_extra.lua b/runtime/lua/vim/_meta/api_keysets_extra.lua index 8faf5f49aa..81bce50746 100644 --- a/runtime/lua/vim/_meta/api_keysets_extra.lua +++ b/runtime/lua/vim/_meta/api_keysets_extra.lua @@ -23,7 +23,7 @@ error('Cannot require a meta file') --- @field conceal? boolean --- @field spell? boolean --- @field ui_watched? boolean ---- @field url? boolean +--- @field url? string --- @field hl_mode? string --- --- @field virt_text? [string, string][] diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index b831a4f23e..c2b19e92c0 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -170,7 +170,7 @@ end --- Returns all URLs at cursor, if any. --- @return string[] function M._get_urls() - local urls = {} + local urls = {} ---@type string[] local bufnr = vim.api.nvim_get_current_buf() local cursor = vim.api.nvim_win_get_cursor(0) @@ -183,7 +183,7 @@ function M._get_urls() }) for _, v in ipairs(extmarks) do local details = v[4] - if details.url then + if details and details.url then urls[#urls + 1] = details.url end end @@ -195,7 +195,7 @@ function M._get_urls() local lang = ltree:lang() local query = vim.treesitter.query.get(lang, 'highlights') if query then - local tree = ltree:tree_for_range(range) + local tree = assert(ltree:tree_for_range(range)) for _, match, metadata in query:iter_matches(tree:root(), bufnr, row, row + 1, { all = true }) do for id, nodes in pairs(match) do for _, node in ipairs(nodes) do @@ -203,7 +203,8 @@ function M._get_urls() local url = metadata[id] and metadata[id].url if url and match[url] then for _, n in ipairs(match[url]) do - urls[#urls + 1] = vim.treesitter.get_node_text(n, bufnr, metadata[url]) + urls[#urls + 1] = + vim.treesitter.get_node_text(n, bufnr, { metadata = metadata[url] }) end end end