@@ -174,11 +174,17 @@ M.get_all_entries = function()
174174 local index_parsed = vim .fn .json_decode (INDEX_PATH :read ())
175175
176176 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
178183 local entry = {
179184 name = string.format (" [%s] %s" , alias , doc_entry .name ),
180185 alias = alias ,
181186 path = doc_entry .path ,
187+ next_path = next_path ,
182188 link = doc_entry .link ,
183189 }
184190 table.insert (entries , entry )
@@ -197,8 +203,12 @@ M.read_entry = function(entry, callback)
197203
198204 file_path :_read_async (vim .schedule_wrap (function (content )
199205 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
200210 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 )
202212
203213 callback (filtered_lines )
204214 end ))
207217--- if we have a pattern to search for, only consider lines after the pattern
208218--- @param lines string[]
209219--- @param pattern ? string
220+ --- @param next_pattern ? string
210221--- @return string[]
211- M .filter_doc = function (lines , pattern )
222+ M .filter_doc = function (lines , pattern , next_pattern )
212223 if not pattern then return lines end
213224
214225 -- https://stackoverflow.com/a/34953646/516188
@@ -218,15 +229,15 @@ M.filter_doc = function(lines, pattern)
218229 local found = false
219230 local pattern_lines = vim .split (pattern , " \n " )
220231 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
224237
225238 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
230241 end
231242 if line :match (search_pattern ) then found = true end
232243 if found then table.insert (filtered_lines , line ) end
0 commit comments