mirror of
https://github.com/neovim/neovim.git
synced 2025-09-19 01:38:16 +00:00
feat(help): gx opens help tag in web browser #35778
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.
This commit is contained in:

committed by
GitHub

parent
a5d6932686
commit
47b0a718c3
@@ -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)
|
||||
|
Reference in New Issue
Block a user