Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lua/apidocs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ local function apidocs_open_only()
break
end
if type2 == "file" and vim.endswith(name2, ".html.md") then
local name_no_txt = name2:gsub("#.*$", "")
local name_no_txt = common.filename_to_display(name2)
table.insert(candidates, { display = name .. "/" .. name_no_txt, path = name .. "/" .. name2 })
end
end
Expand Down Expand Up @@ -201,4 +201,4 @@ return {
open_doc_in_new_window = common.open_doc_in_new_window,
open_doc_in_cur_window = common.open_doc_in_cur_window,
load_doc_in_buffer = common.load_doc_in_buffer,
}
}
16 changes: 15 additions & 1 deletion lua/apidocs/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,25 @@ local function open_doc_in_new_window(docs_path)
vim.api.nvim_buf_set_name(0, desc)
end

-- convert filename to picker display string
local function filename_to_display(filename)
local components = vim.split(filename, "#")
local display = components[1]
-- little hack: In some languages the filename contains "Class#method", which messes
-- up our "#" - separated schema. So if there are 4 "components" in the filename,
-- the first two (separated by "#") have to be the actual key to display.
if(#components == 4) then
display = display .. "#" .. components[2]
end
return display
end


return {
data_folder = data_folder,
escape_pattern = escape_pattern,
load_doc_in_buffer = load_doc_in_buffer,
open_doc_in_cur_window = open_doc_in_cur_window,
open_doc_in_new_window = open_doc_in_new_window,
}
filename_to_display = filename_to_display,
}
5 changes: 2 additions & 3 deletions lua/apidocs/snacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ local function format_entries(item, picker)
field = "file",
},
}
local fileNameParts = vim.split(filename, "#")
new_item[#new_item + 1] = {
fileNameParts[1],
common.filename_to_display(filename),
"SnacksPickerFile",
field = "file",
}
Expand Down Expand Up @@ -96,4 +95,4 @@ end
return {
apidocs_open = apidocs_open,
apidocs_search = apidocs_search,
}
}
22 changes: 11 additions & 11 deletions lua/apidocs/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ local function apidocs_search(opts)
local default_entry_maker = make_entry.gen_from_vimgrep()
local function entry_maker(entry)
local r = default_entry_maker(entry)
r.display = function(entry)
local entry_components = vim.split(entry.filename:sub(#folder+1), "#")
local source_length = entry_components[1]:find("/")
local hl_group = {
{ {0, source_length}, "TelescopeResultsTitle"},
{ {source_length, #entry_components[1]}, "TelescopeResultsMethod" },
{ {#entry_components[1], #entry_components[1] + #(tostring(entry.lnum))+2}, "TelescopeResultsLineNr" },
}
return string.format("%s:%d: %s", entry_components[1], entry.lnum, entry.text), hl_group
end
r.display = function(entry)
local display = common.filename_to_display(entry.filename:sub(#folder+1))
local source_length = display:find("/")
local hl_group = {
{ {0, source_length}, "TelescopeResultsTitle"},
{ {source_length, #display}, "TelescopeResultsMethod" },
{ {#display, #display + #(tostring(entry.lnum))+2}, "TelescopeResultsLineNr" },
}
return string.format("%s:%d: %s", display, entry.lnum, entry.text), hl_group
end
return r
end

Expand Down Expand Up @@ -152,4 +152,4 @@ end
return {
apidocs_open = apidocs_open,
apidocs_search = apidocs_search,
}
}