mirror of
https://github.com/neovim/neovim.git
synced 2025-10-17 07:16:09 +00:00
fix(help): wrong tag url in third-party help docs #36115
fix(help): only set url for nvim-owned tags Problem: 1. gx on |nonexistingtag| opens https://neovim.io/doc/user/helptag.html?nonexistingtag. 2. b:undo_ftplugin doesn't remove url extmarks. Solution: 1. Check if the tag is defined in a help file in $VIMRUNTIME. 2. Solution: clear namespace for buffer in b:undo_ftplugin.
This commit is contained in:

committed by
GitHub

parent
c6113da5a9
commit
62d3a2110d
@@ -115,8 +115,8 @@ do
|
||||
end, { buffer = true })
|
||||
end
|
||||
|
||||
local url_ns = vim.api.nvim_create_namespace('nvim.help.urls')
|
||||
do
|
||||
local ns = vim.api.nvim_create_namespace('nvim.help.urls')
|
||||
local base = 'https://neovim.io/doc/user/helptag.html?tag='
|
||||
local query = vim.treesitter.query.parse(
|
||||
'vimdoc',
|
||||
@@ -129,17 +129,28 @@ do
|
||||
]]
|
||||
)
|
||||
|
||||
local function is_nvim_tag(tag)
|
||||
local tagsfile = vim.fs.joinpath(vim.env.VIMRUNTIME, 'doc', 'tags')
|
||||
local candidates = vim.fn.taglist('^' .. tag .. '$', tagsfile)
|
||||
if #candidates == 0 then
|
||||
return false
|
||||
end
|
||||
return vim.fs.relpath(vim.env.VIMRUNTIME, candidates[1].filename) ~= nil
|
||||
end
|
||||
|
||||
for _, match, _ in query:iter_matches(root, 0, 0, -1) do
|
||||
for id, nodes in pairs(match) do
|
||||
if query.captures[id] == 'helplink' then
|
||||
for _, node in ipairs(nodes) do
|
||||
local start_line, start_col, end_line, end_col = node:range()
|
||||
local tag = vim.treesitter.get_node_text(node, 0)
|
||||
vim.api.nvim_buf_set_extmark(0, ns, start_line, start_col, {
|
||||
end_line = end_line,
|
||||
end_col = end_col,
|
||||
url = base .. vim.uri_encode(tag),
|
||||
})
|
||||
if is_nvim_tag(tag) then
|
||||
vim.api.nvim_buf_set_extmark(0, url_ns, start_line, start_col, {
|
||||
end_line = end_line,
|
||||
end_col = end_col,
|
||||
url = base .. vim.uri_encode(tag),
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -149,4 +160,5 @@ end
|
||||
vim.b.undo_ftplugin = (vim.b.undo_ftplugin or '')
|
||||
.. '\n sil! exe "nunmap <buffer> gO" | sil! exe "nunmap <buffer> g=="'
|
||||
.. '\n sil! exe "nunmap <buffer> ]]" | sil! exe "nunmap <buffer> [["'
|
||||
.. ('\n call v:lua.vim.api.nvim_buf_clear_namespace(0, %d, 0, -1)'):format(url_ns)
|
||||
vim.b.undo_ftplugin = vim.b.undo_ftplugin .. ' | call v:lua.vim.treesitter.stop()'
|
||||
|
Reference in New Issue
Block a user