mirror of
https://github.com/neovim/neovim.git
synced 2025-10-20 16:51:48 +00:00
fix(help): only set url for help files in $VIMRUNTIME #36165
Problem: Checking if the tag is nvim-owned (defined in a $VIMRUNTIME/doc/*.txt file) is too expensive for now without non-obvious workarounds Solution: Only set url extmarks for $VIMRUNTIME/doc/*.txt files. Closes: #36163
This commit is contained in:

committed by
GitHub

parent
a65202e6bd
commit
25322a3a3b
@@ -116,7 +116,9 @@ do
|
||||
end
|
||||
|
||||
local url_ns = vim.api.nvim_create_namespace('nvim.help.urls')
|
||||
do
|
||||
local filepath = vim.fs.normalize(vim.api.nvim_buf_get_name(0))
|
||||
|
||||
if vim.fs.relpath(vim.env.VIMRUNTIME, filepath) ~= nil then
|
||||
local base = 'https://neovim.io/doc/user/helptag.html?tag='
|
||||
local query = vim.treesitter.query.parse(
|
||||
'vimdoc',
|
||||
@@ -129,28 +131,17 @@ 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)
|
||||
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
|
||||
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
|
||||
|
Reference in New Issue
Block a user