feat: support different languages for help_tags if helpfiles are available in other languages (#430)
" use helplang and show en help when it is not found. :Telescope help_tags " use helplang, but do not show en help when it is not found. :Telescope help_tags fallback=false " ignore helplang and show help from specified langs. " when helps cannot be found, show en help. :Telescope help_tags lang=ja,ru " ignore helplang and show help from specified langs only. :Telescope help_tags lang=ja,ru fallback=false
This commit is contained in:
committed by
GitHub
parent
951ede2a70
commit
5bf9e14f10
@@ -333,36 +333,62 @@ internal.vim_options = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
internal.help_tags = function(opts)
|
internal.help_tags = function(opts)
|
||||||
local all_tag_files = {}
|
opts.lang = utils.get_default(opts.lang, vim.o.helplang)
|
||||||
local all_help_files = {}
|
opts.fallback = utils.get_default(opts.fallback, true)
|
||||||
for _, v in ipairs(vim.split(vim.fn.globpath(vim.o.runtimepath, 'doc/*', 1), '\n')) do
|
|
||||||
local split_path = vim.split(v, path.separator, true)
|
local langs = vim.split(opts.lang, ',', true)
|
||||||
local filename = split_path[#split_path]
|
if opts.fallback and not vim.tbl_contains(langs, 'en') then
|
||||||
if filename == 'tags' then
|
table.insert(langs, 'en')
|
||||||
table.insert(all_tag_files, v)
|
end
|
||||||
|
local langs_map = {}
|
||||||
|
for _, lang in ipairs(langs) do
|
||||||
|
langs_map[lang] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
local tag_files = {}
|
||||||
|
local function add_tag_file(lang, file)
|
||||||
|
if langs_map[lang] then
|
||||||
|
if tag_files[lang] then
|
||||||
|
table.insert(tag_files[lang], file)
|
||||||
else
|
else
|
||||||
all_help_files[filename] = v
|
tag_files[lang] = {file}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local help_files = {}
|
||||||
|
local all_files = vim.fn.globpath(vim.o.runtimepath, 'doc/*', 1, 1)
|
||||||
|
for _, fullpath in ipairs(all_files) do
|
||||||
|
local file = utils.path_tail(fullpath)
|
||||||
|
if file == 'tags' then
|
||||||
|
add_tag_file('en', fullpath)
|
||||||
|
elseif file:match('^tags%-..$') then
|
||||||
|
local lang = file:sub(-2)
|
||||||
|
add_tag_file(lang, fullpath)
|
||||||
|
else
|
||||||
|
help_files[file] = fullpath
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local delim = string.char(9)
|
|
||||||
local tags = {}
|
local tags = {}
|
||||||
for _, file in ipairs(all_tag_files) do
|
local tags_map = {}
|
||||||
local data = vim.split(path.read_file(file), '\n')
|
local delimiter = string.char(9)
|
||||||
for _, line in ipairs(data) do
|
for _, lang in ipairs(langs) do
|
||||||
if line ~= '' then
|
for _, file in ipairs(tag_files[lang] or {}) do
|
||||||
local matches = {}
|
local lines = vim.split(path.read_file(file), '\n', true)
|
||||||
|
for _, line in ipairs(lines) do
|
||||||
for match in (line..delim):gmatch("(.-)" .. delim) do
|
-- TODO: also ignore tagComment starting with ';'
|
||||||
table.insert(matches, match)
|
if not line:match'^!_TAG_' then
|
||||||
end
|
local fields = vim.split(line, delimiter, true)
|
||||||
|
if #fields == 3 and not tags_map[fields[1]] then
|
||||||
if table.getn(matches) ~= 0 then
|
|
||||||
table.insert(tags, {
|
table.insert(tags, {
|
||||||
name = matches[1],
|
name = fields[1],
|
||||||
filename = all_help_files[matches[2]],
|
filename = help_files[fields[2]],
|
||||||
cmd = matches[3]
|
cmd = fields[3],
|
||||||
|
lang = lang,
|
||||||
})
|
})
|
||||||
|
tags_map[fields[1]] = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -374,7 +400,7 @@ internal.help_tags = function(opts)
|
|||||||
results = tags,
|
results = tags,
|
||||||
entry_maker = function(entry)
|
entry_maker = function(entry)
|
||||||
return {
|
return {
|
||||||
value = entry.name,
|
value = entry.name .. '@' .. entry.lang,
|
||||||
display = entry.name,
|
display = entry.name,
|
||||||
ordinal = entry.name,
|
ordinal = entry.name,
|
||||||
filename = entry.filename,
|
filename = entry.filename,
|
||||||
|
|||||||
Reference in New Issue
Block a user