@@ -7,6 +7,7 @@ local state = require("telescope.state")
7
7
local actions = require (" telescope.actions" )
8
8
local action_state = require (" telescope.actions.state" )
9
9
local config = require (" telescope.config" ).values
10
+ local entry_display = require (" telescope.pickers.entry_display" )
10
11
11
12
local list = require (" nvim-devdocs.list" )
12
13
local notify = require (" nvim-devdocs.notify" )
@@ -176,10 +177,6 @@ M.open_picker = function(entries, float)
176
177
picker :find ()
177
178
end
178
179
179
- M .open_picker_grep = function (subfolder )
180
- require (' telescope.builtin' ).live_grep ({cwd = DOCS_DIR :joinpath (subfolder ).filename })
181
- end
182
-
183
180
--- @param alias string
184
181
--- @param float ? boolean
185
182
M .open_picker_alias = function (alias , float )
@@ -193,4 +190,61 @@ M.open_picker_alias = function(alias, float)
193
190
end
194
191
end
195
192
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
+
196
250
return M
0 commit comments