@@ -72,30 +72,38 @@ local function apidocs_open(params, slugs_to_mtimes, candidates)
7272 :find ()
7373end
7474
75+ local function get_data_dirs (opts )
76+ local data_dir = common .data_folder ()
77+ if not (opts and opts .restrict_sources ) then
78+ return { data_dir }
79+ end
80+ local dirs = {}
81+ local install_dirs = vim .fn .readdir (data_dir )
82+ for _ , source in ipairs (opts .restrict_sources ) do
83+ local dir = data_dir .. source .. " /"
84+ if vim .fn .isdirectory (dir ) == 1 then
85+ table.insert (dirs , dir )
86+ else
87+ for _ , entry in ipairs (install_dirs ) do
88+ if entry :match (" ^" .. source .. " ~%d+" ) then
89+ -- check for partial match
90+ -- e.g. "python" -> "python~3.12"
91+ table.insert (dirs , data_dir .. entry .. " /" )
92+ end
93+ end
94+ end
95+ end
96+ return dirs
97+ end
98+
7599local function apidocs_search (opts )
76100 local previewers = require (" telescope.previewers" )
77101 local make_entry = require (" telescope.make_entry" )
78102 local folder = common .data_folder ()
79103 if opts and opts .source then
80104 folder = folder .. opts .source .. " /"
81105 end
82- local search_dirs = { folder }
83- if opts and opts .restrict_sources then
84- local install_dirs = vim .fn .readdir (folder )
85- for _ , source in ipairs (opts .restrict_sources ) do
86- for _ , entry in ipairs (install_dirs ) do
87- if vim .fn .isdirectory (folder .. entry ) == 1 then
88- if entry == source then
89- table.insert (search_dirs , folder .. entry .. " /" )
90- elseif entry :match (" ^" .. source .. " ~%d+(%.%d+)?$" ) then
91- -- check for partial match
92- -- e.g. "python" -> "python~3.12"
93- table.insert (search_dirs , folder .. entry .. " /" )
94- end
95- end
96- end
97- end
98- end
106+ local search_dirs = get_data_dirs (opts )
99107
100108 local default_entry_maker = make_entry .gen_from_vimgrep ()
101109 local function entry_maker (entry )
0 commit comments