Manually search through tags

Probably slower, but the builtin `taglist()` only looks at the first
file in 'tags', not ideal for this application. This can probably be
cleaned up a little.
This commit is contained in:
Nolan Prochnau
2020-11-15 13:26:30 -05:00
parent 1495cbec5a
commit 8eecc9c9dc

View File

@@ -418,31 +418,47 @@ previewers.help = defaulter(function(_)
preview_fn = function(self, entry, status) preview_fn = function(self, entry, status)
with_preview_window(status, nil, function() with_preview_window(status, nil, function()
local special_chars = ":~^.?/%[%]%*" local special_chars = ":~^.?/%[%]%*"
local delim = string.char(9)
local escaped = vim.fn.escape(entry.value, special_chars) local escaped = vim.fn.escape(entry.value, special_chars)
local tagfile = vim.fn.expand("$VIMRUNTIME") .. '/doc/tags'
local old_tags = vim.o.tags
vim.o.tags = '' local tags = {}
local tag_entry
for _,file in pairs(vim.fn.findfile('doc/tags', vim.o.runtimepath, -1)) do for _,file in pairs(vim.fn.findfile('doc/tags', vim.o.runtimepath, -1)) do
vim.o.tags = vim.o.tags .. file .. ',' local f = assert(io.open(file, "rb"))
for line in f:lines() do
tag_entry = {}
for match in (line..delim):gmatch("(.-)" .. delim) do
if vim.tbl_isempty(tag_entry) then
tag_entry.name = match
elseif not tag_entry.filename then
tag_entry.filename = match
else
tag_entry.cmd = match
end
end
table.insert(tags, tag_entry)
end
f:close()
end end
vim.o.tags = vim.o.tags:sub(1,-2) -- Remove trailing comma local search_tags = function(pattern)
print(vim.inspect(vim.o.tags)) local results = {}
local taglist = vim.fn.taglist('^' .. escaped .. '$') for _, tag in pairs(tags) do
vim.o.tags = old_tags if vim.fn.match(tag.name, pattern) ~= -1 then
table.insert(results, tag)
if vim.tbl_isempty(taglist) then end
taglist = vim.fn.taglist(escaped, tagfile) end
return results
end end
if vim.tbl_isempty(taglist) then local taglist = search_tags('^' .. escaped .. '$')
return if taglist == {} then taglist = search_tags(escaped) end
end
local best_entry = taglist[1] local best_entry = taglist[1]
local new_bufnr = vim.fn.bufnr(best_entry.filename, true) local new_bufnr = vim.fn.bufnr(vim.fn.findfile('doc/'..best_entry.filename, vim.o.runtimepath), true)
print(vim.inspect(new_bufnr))
vim.api.nvim_buf_set_option(new_bufnr, 'filetype', 'help') vim.api.nvim_buf_set_option(new_bufnr, 'filetype', 'help')
vim.api.nvim_win_set_buf(status.preview_win, new_bufnr) vim.api.nvim_win_set_buf(status.preview_win, new_bufnr)
@@ -451,6 +467,7 @@ previewers.help = defaulter(function(_)
-- remove leading '/' -- remove leading '/'
search_query = search_query:sub(2) search_query = search_query:sub(2)
print(search_query)
-- Set the query to "very nomagic". -- Set the query to "very nomagic".
-- This should make it work quite nicely given tags. -- This should make it work quite nicely given tags.