diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-12-16 17:30:37 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-12-16 17:30:37 +0800 |
commit | ab5e1b39ec6eedf3cc47c845fe0544da48e58829 (patch) | |
tree | 42fa33ae3a61c56055486b1255c976ec4a6bbb38 /script/workspace/require-path.lua | |
parent | 8b0d3827faf0cdc967e52ddfbe043c07c0dbe6a2 (diff) | |
download | lua-language-server-ab5e1b39ec6eedf3cc47c845fe0544da48e58829.zip |
clean up
Diffstat (limited to 'script/workspace/require-path.lua')
-rw-r--r-- | script/workspace/require-path.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua index e2149bac..94a8a161 100644 --- a/script/workspace/require-path.lua +++ b/script/workspace/require-path.lua @@ -81,6 +81,51 @@ function m.getVisiblePath(path) return m.cache[path] end +--- 查找符合指定require path的所有uri +---@param path string +function m.findUrisByRequirePath(path) + if type(path) ~= 'string' then + return {} + end + local vm = require 'vm' + local cache = vm.getCache 'findUrisByRequirePath' + if cache[path] then + return cache[path].results, cache[path].searchers + end + tracy.ZoneBeginN('findUrisByRequirePath') + local results = {} + local mark = {} + local searchers = {} + for uri in files.eachDll() do + local opens = files.getDllOpens(uri) or {} + for _, open in ipairs(opens) do + if open == path then + results[#results+1] = uri + end + end + end + + local input = path:gsub('%.', '/') + :gsub('%%', '%%%%') + for _, luapath in ipairs(config.get 'Lua.runtime.path') do + local part = workspace.normalize(luapath:gsub('%?', input)) + local uris, posts = workspace.findUrisByFilePath(part) + for _, uri in ipairs(uris) do + if not mark[uri] then + mark[uri] = true + results[#results+1] = uri + searchers[uri] = posts[uri] .. luapath + end + end + end + tracy.ZoneEnd() + cache[path] = { + results = results, + searchers = searchers, + } + return results, searchers +end + function m.flush() m.cache = {} end |