diff options
| author | ruki <[email protected]> | 2024-10-22 23:24:31 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-10-22 23:24:31 +0800 |
| commit | ddbef7afc5573db90df1af0ed0bde9f681905e98 (patch) | |
| tree | 5dda169eaa278e553cee364dc03d19f9089837e2 /xmake/modules/private | |
| parent | 9a7d7d8f5b90ab09a0bfc90f7cfd4750a729cef6 (diff) | |
improve and cache searchdirs #5744
Diffstat (limited to 'xmake/modules/private')
| -rw-r--r-- | xmake/modules/private/action/require/impl/repository.lua | 22 | ||||
| -rw-r--r-- | xmake/modules/private/xrepo/quick_search/cache.lua | 19 | ||||
| -rw-r--r-- | xmake/modules/private/xrepo/quick_search/completion.lua | 4 |
3 files changed, 18 insertions, 27 deletions
diff --git a/xmake/modules/private/action/require/impl/repository.lua b/xmake/modules/private/action/require/impl/repository.lua index 74b97efda..aab908e5b 100644 --- a/xmake/modules/private/action/require/impl/repository.lua +++ b/xmake/modules/private/action/require/impl/repository.lua @@ -220,25 +220,3 @@ function artifacts_manifest(packagename, version) end end --- search package directories from repositories -function searchdirs(name) - - -- find the package directories from all repositories - local unique = {} - local packageinfos = {} - for _, repo in ipairs(repositories()) do - for _, file in ipairs(os.files(path.join(repo:directory(), "packages", "*", string.ipattern("*" .. name .. "*"), "xmake.lua"))) do - local dir = path.directory(file) - local subdirname = path.basename(path.directory(dir)) - if #subdirname == 1 then -- ignore l/luajit/port/xmake.lua - local packagename = path.filename(dir) - if not unique[packagename] then - table.insert(packageinfos, {name = packagename, repo = repo, packagedir = path.directory(file)}) - unique[packagename] = true - end - end - end - end - return packageinfos -end - diff --git a/xmake/modules/private/xrepo/quick_search/cache.lua b/xmake/modules/private/xrepo/quick_search/cache.lua index e14074d24..9ba142076 100644 --- a/xmake/modules/private/xrepo/quick_search/cache.lua +++ b/xmake/modules/private/xrepo/quick_search/cache.lua @@ -37,7 +37,7 @@ function _list_package_dirs() if #subdirname == 1 then -- ignore l/luajit/port/xmake.lua local packagename = path.filename(dir) if not unique[packagename] then - table.insert(packageinfos, {name = packagename, repo = repo, packagedir = path.directory(file)}) + table.insert(packageinfos, {name = packagename, repo = repo, packagedir = dir}) unique[packagename] = true end end @@ -58,6 +58,7 @@ function update() for _, packageinfo in ipairs(_list_package_dirs()) do local package = core_package.load_from_repository(packageinfo.name, packageinfo.packagedir, {repo = packageinfo.repo}) cache:set(packageinfo.name, { + reponame = package:repo() and package:repo():name(), description = package:description(), versions = package:versions(), }) @@ -77,13 +78,25 @@ function get() return cache:data() end -function find(name) +-- find package +function find(name, opt) _init() + opt = opt or {} local list_result = {} for packagename, packagedata in pairs(cache:data()) do - if packagename:startswith(name) then + local found = false + if opt.prefix then + found = packagename:startswith(name) + else + found = packagename:find(name) + end + if not found and opt.description and packagedata.description and packagedata.description:find(name) then + found = true + end + if found then table.insert(list_result, {name = packagename, data = packagedata}) end end return list_result end + diff --git a/xmake/modules/private/xrepo/quick_search/completion.lua b/xmake/modules/private/xrepo/quick_search/completion.lua index 8b8b802bb..b1a26e117 100644 --- a/xmake/modules/private/xrepo/quick_search/completion.lua +++ b/xmake/modules/private/xrepo/quick_search/completion.lua @@ -23,7 +23,7 @@ import("private.xrepo.quick_search.cache") -- complete xrepo packages function _xmake_package_complete(complete, opt) local candidates = {} - local found = cache.find(complete) + local found = cache.find(complete, {prefix = true}) for _, candidate in ipairs(found) do table.insert(candidates, {value = candidate.name, description = candidate.data.description}) end @@ -59,4 +59,4 @@ function main(complete, opt) end end return packages or {} -end
\ No newline at end of file +end |
