feat(help): gx opens help tag in web browser (#35784)

Problem:
`gx` does not work on tags in help buffers to open the documentation of that tag in the browser.

Solution:
Get the `optionlink`, `taglink` and `tag` TS nodes and set extmark "url" property.
`gx` then discovers the extmark "url" and opens it.

Co-authored-by: Yochem van Rosmalen <git@yochem.nl>
This commit is contained in:
Justin M. Keyes
2025-09-15 19:30:31 -04:00
committed by GitHub
parent 7aea000343
commit 693772100e
3 changed files with 97 additions and 38 deletions

View File

@@ -13,7 +13,7 @@ local poke_eventloop = n.poke_eventloop
describe('vim.ui', function()
before_each(function()
clear()
clear({ args_rm = { '-u' }, args = { '--clean' } })
end)
describe('select()', function()
@@ -180,5 +180,28 @@ describe('vim.ui', function()
end, { n.testprg('printargs-test'), 'arg1' })
)
end)
it('gx on a help tag opens URL', function()
n.command('helptags $VIMRUNTIME/doc')
n.command('help nvim.txt')
local link_ns = n.api.nvim_create_namespace('nvim.help.urls')
local tag = n.api.nvim_buf_get_extmarks(0, link_ns, 0, -1, {
limit = 1,
details = true,
})[1]
local url = tag[4].url
assert(url)
--- points to the neovim.io site
eq(true, vim.startswith(url, 'https://neovim.io/doc'))
-- tag is URI encoded
local param = url:match('%?tag=(.*)')
local tagname =
n.api.nvim_buf_get_text(0, tag[2], tag[3], tag[4].end_row, tag[4].end_col, {})[1]
eq(vim.uri_encode(tagname), param)
end)
end)
end)