Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit 4726572

Browse files
wip: improve result display
1 parent 2106776 commit 4726572

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

lua/nvim-devdocs/pickers.lua

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local state = require("telescope.state")
77
local actions = require("telescope.actions")
88
local action_state = require("telescope.actions.state")
99
local config = require("telescope.config").values
10+
local entry_display = require("telescope.pickers.entry_display")
1011

1112
local list = require("nvim-devdocs.list")
1213
local notify = require("nvim-devdocs.notify")
@@ -176,10 +177,6 @@ M.open_picker = function(entries, float)
176177
picker:find()
177178
end
178179

179-
M.open_picker_grep = function(subfolder)
180-
require('telescope.builtin').live_grep({cwd=DOCS_DIR:joinpath(subfolder).filename})
181-
end
182-
183180
---@param alias string
184181
---@param float? boolean
185182
M.open_picker_alias = function(alias, float)
@@ -193,4 +190,61 @@ M.open_picker_alias = function(alias, float)
193190
end
194191
end
195192

193+
---@param subfolder string
194+
M.open_picker_grep = function(subfolder)
195+
if not INDEX_PATH:exists() then return end
196+
197+
local index = vim.fn.json_decode(INDEX_PATH:read())
198+
local entry_map = {}
199+
200+
if subfolder == "" then
201+
for name, value in pairs(index) do
202+
entry_map[name] = {}
203+
for _, entry in pairs(value.entries) do
204+
local path = vim.fn.split(entry.path, ",")[1]
205+
entry_map[name][path] = entry.name
206+
end
207+
end
208+
else
209+
entry_map[subfolder] = {}
210+
for _, entry in pairs(index[subfolder].entries) do
211+
local path = vim.fn.split(entry.path, ",")[1]
212+
entry_map[subfolder][path] = entry.name
213+
end
214+
end
215+
216+
local entry_maker = function(entry)
217+
local _, _, filename, lnum, col, text = string.find(entry, [[(..-):(%d+):(%d+):(.*)]])
218+
local _, _, alias, path = string.find(filename, [[([^/]+)/?(%d+).md]])
219+
local displayer = entry_display.create({
220+
separator = " ",
221+
items = {
222+
{ remaining = true },
223+
{ remaining = true },
224+
{ remaining = true },
225+
},
226+
})
227+
228+
return {
229+
filename = DOCS_DIR:joinpath(subfolder, filename).filename,
230+
lnum = tonumber(lnum),
231+
col = tonumber(col),
232+
ordinal = entry,
233+
display = function()
234+
local entry_name = entry_map[alias or subfolder][path]
235+
return displayer({
236+
{ string.format("[%s]", alias or subfolder), "markdownH1" },
237+
{ entry_name or "Unlisted", "markdownH2" },
238+
{ text, "Comment" },
239+
})
240+
end,
241+
}
242+
end
243+
244+
require("telescope.builtin").live_grep({
245+
entry_maker = entry_maker,
246+
cwd = DOCS_DIR:joinpath(subfolder).filename,
247+
})
248+
end
249+
196250
return M

0 commit comments

Comments
 (0)