@@ -174,11 +174,17 @@ M.get_all_entries = function()
174
174
local index_parsed = vim .fn .json_decode (INDEX_PATH :read ())
175
175
176
176
for alias , index in pairs (index_parsed ) do
177
- for _ , doc_entry in ipairs (index .entries ) do
177
+ local entries_count = # index .entries
178
+ for idx , doc_entry in ipairs (index .entries ) do
179
+ local next_path = nil
180
+ if idx < entries_count then
181
+ next_path = index .entries [idx + 1 ].path
182
+ end
178
183
local entry = {
179
184
name = string.format (" [%s] %s" , alias , doc_entry .name ),
180
185
alias = alias ,
181
186
path = doc_entry .path ,
187
+ next_path = next_path ,
182
188
link = doc_entry .link ,
183
189
}
184
190
table.insert (entries , entry )
@@ -197,8 +203,12 @@ M.read_entry = function(entry, callback)
197
203
198
204
file_path :_read_async (vim .schedule_wrap (function (content )
199
205
local pattern = splited_path [2 ]
206
+ local next_pattern = nil
207
+ if entry .next_path ~= nil then
208
+ next_pattern = vim .split (entry .next_path , " ," )[2 ]
209
+ end
200
210
local lines = vim .split (content , " \n " )
201
- local filtered_lines = M .filter_doc (lines , pattern )
211
+ local filtered_lines = M .filter_doc (lines , pattern , next_pattern )
202
212
203
213
callback (filtered_lines )
204
214
end ))
207
217
--- if we have a pattern to search for, only consider lines after the pattern
208
218
--- @param lines string[]
209
219
--- @param pattern ? string
220
+ --- @param next_pattern ? string
210
221
--- @return string[]
211
- M .filter_doc = function (lines , pattern )
222
+ M .filter_doc = function (lines , pattern , next_pattern )
212
223
if not pattern then return lines end
213
224
214
225
-- https://stackoverflow.com/a/34953646/516188
@@ -218,15 +229,15 @@ M.filter_doc = function(lines, pattern)
218
229
local found = false
219
230
local pattern_lines = vim .split (pattern , " \n " )
220
231
local search_pattern = create_pattern (pattern_lines [1 ]) -- only search the first line
221
- local split = vim .split (pattern , " " )
222
- local header = split [1 ]
223
- local top_header = header and header :sub (1 , # header - 1 )
232
+ local next_search_pattern = nil
233
+ if next_pattern then
234
+ local next_pattern_lines = vim .split (next_pattern , " \n " )
235
+ next_search_pattern = create_pattern (next_pattern_lines [1 ]) -- only search the first line
236
+ end
224
237
225
238
for _ , line in ipairs (lines ) do
226
- if found then
227
- local line_split = vim .split (line , " " )
228
- local first = line_split [1 ]
229
- if first == header or first == top_header then break end
239
+ if found and next_search_pattern then
240
+ if line :match (next_search_pattern ) then break end
230
241
end
231
242
if line :match (search_pattern ) then found = true end
232
243
if found then table.insert (filtered_lines , line ) end
0 commit comments