fix(ui): correctly pass metadata to get_node_text #30222

Fixes: #30220
This commit is contained in:
Gregory Anders 2024-09-01 12:15:02 -05:00 committed by GitHub
parent 97f8d1de1c
commit 318c0415d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View File

@ -23,7 +23,7 @@ error('Cannot require a meta file')
--- @field conceal? boolean --- @field conceal? boolean
--- @field spell? boolean --- @field spell? boolean
--- @field ui_watched? boolean --- @field ui_watched? boolean
--- @field url? boolean --- @field url? string
--- @field hl_mode? string --- @field hl_mode? string
--- ---
--- @field virt_text? [string, string][] --- @field virt_text? [string, string][]

View File

@ -170,7 +170,7 @@ end
--- Returns all URLs at cursor, if any. --- Returns all URLs at cursor, if any.
--- @return string[] --- @return string[]
function M._get_urls() function M._get_urls()
local urls = {} local urls = {} ---@type string[]
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
local cursor = vim.api.nvim_win_get_cursor(0) local cursor = vim.api.nvim_win_get_cursor(0)
@ -183,7 +183,7 @@ function M._get_urls()
}) })
for _, v in ipairs(extmarks) do for _, v in ipairs(extmarks) do
local details = v[4] local details = v[4]
if details.url then if details and details.url then
urls[#urls + 1] = details.url urls[#urls + 1] = details.url
end end
end end
@ -195,7 +195,7 @@ function M._get_urls()
local lang = ltree:lang() local lang = ltree:lang()
local query = vim.treesitter.query.get(lang, 'highlights') local query = vim.treesitter.query.get(lang, 'highlights')
if query then 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 _, match, metadata in query:iter_matches(tree:root(), bufnr, row, row + 1, { all = true }) do
for id, nodes in pairs(match) do for id, nodes in pairs(match) do
for _, node in ipairs(nodes) do for _, node in ipairs(nodes) do
@ -203,7 +203,8 @@ function M._get_urls()
local url = metadata[id] and metadata[id].url local url = metadata[id] and metadata[id].url
if url and match[url] then if url and match[url] then
for _, n in ipairs(match[url]) do 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 end
end end