From 8a9e0751c8e6b8935bf3cfd98027be57bf14c9bb Mon Sep 17 00:00:00 2001 From: Christian Reiniger Date: Thu, 19 Jun 2025 21:48:04 +0200 Subject: [PATCH 1/3] Properly display Class#name entries Workaround for #11 --- lua/apidocs.lua | 4 ++-- lua/apidocs/common.lua | 15 ++++++++++++++- lua/apidocs/telescope.lua | 22 +++++++++++----------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/lua/apidocs.lua b/lua/apidocs.lua index a5efb9d..960555a 100644 --- a/lua/apidocs.lua +++ b/lua/apidocs.lua @@ -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 @@ -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, -} +} \ No newline at end of file diff --git a/lua/apidocs/common.lua b/lua/apidocs/common.lua index 7d7ebc4..dbe92fe 100644 --- a/lua/apidocs/common.lua +++ b/lua/apidocs/common.lua @@ -104,6 +104,19 @@ 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, @@ -111,4 +124,4 @@ return { 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, -} +} \ No newline at end of file diff --git a/lua/apidocs/telescope.lua b/lua/apidocs/telescope.lua index dc3737e..916e7ac 100644 --- a/lua/apidocs/telescope.lua +++ b/lua/apidocs/telescope.lua @@ -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 @@ -152,4 +152,4 @@ end return { apidocs_open = apidocs_open, apidocs_search = apidocs_search, -} +} \ No newline at end of file From 5e07b414d641cdd4de5e80a1c9e503168fc88994 Mon Sep 17 00:00:00 2001 From: Christian Reiniger Date: Thu, 19 Jun 2025 22:24:20 +0200 Subject: [PATCH 2/3] Fix function visibility Workaround for #11 --- lua/apidocs/common.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/apidocs/common.lua b/lua/apidocs/common.lua index dbe92fe..807e2cb 100644 --- a/lua/apidocs/common.lua +++ b/lua/apidocs/common.lua @@ -124,4 +124,5 @@ return { 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, } \ No newline at end of file From 9c8eeed62c83998be55bfd369b17227705898b1f Mon Sep 17 00:00:00 2001 From: Christian Reiniger Date: Sat, 21 Jun 2025 08:19:16 +0200 Subject: [PATCH 3/3] Use Workaround in snacks picker Workaround for #11 --- lua/apidocs/snacks.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lua/apidocs/snacks.lua b/lua/apidocs/snacks.lua index 3aa8e9a..e34524c 100644 --- a/lua/apidocs/snacks.lua +++ b/lua/apidocs/snacks.lua @@ -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", } @@ -96,4 +95,4 @@ end return { apidocs_open = apidocs_open, apidocs_search = apidocs_search, -} +} \ No newline at end of file