summaryrefslogtreecommitdiff
path: root/script/workspace/workspace.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/workspace/workspace.lua')
-rw-r--r--script/workspace/workspace.lua82
1 files changed, 7 insertions, 75 deletions
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index 12971ae5..a2f99b3e 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -262,89 +262,20 @@ function m.findUrisByFilePath(path)
if type(path) ~= 'string' then
return {}
end
- local lpath = furi.encode(path):gsub('^file:///', '')
+ local myUri = furi.encode(path)
local vm = require 'vm'
local resultCache = vm.getCache 'findUrisByRequirePath.result'
if resultCache[path] then
- return resultCache[path].results, resultCache[path].posts
+ return resultCache[path]
end
- tracy.ZoneBeginN('findUrisByFilePath #1')
- local strict = config.get(nil, 'Lua.runtime.pathStrict')
local results = {}
- local posts = {}
for uri in files.eachFile() do
- if not uri:find(lpath, 1, true) then
- goto CONTINUE
- end
- local relat = m.getRelativePath(uri)
- local pathLen = #path
- local curPath = relat
- local curLen = #curPath
- local seg = curPath:sub(curLen - pathLen, curLen - pathLen)
- if seg == '/' or seg == '\\' or seg == '' then
- if strict and seg ~= '' then
- goto CONTINUE
- end
- local see = curPath:sub(curLen - pathLen + 1, curLen)
- if see == path then
- results[#results+1] = uri
- local post = curPath:sub(1, curLen - pathLen)
- posts[uri] = post:gsub('^[/\\]+', '')
- end
- end
- ::CONTINUE::
- end
- tracy.ZoneEnd()
- resultCache[path] = {
- results = results,
- posts = posts,
- }
- return results, posts
-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(nil, 'Lua.runtime.path')) do
- local part = m.normalize(luapath:gsub('%?', input))
- local uris, posts = m.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
+ if uri == myUri then
+ results[#results+1] = uri
end
end
- tracy.ZoneEnd()
- cache[path] = {
- results = results,
- searchers = searchers,
- }
- return results, searchers
+ resultCache[path] = results
+ return results
end
function m.normalize(path)
@@ -361,6 +292,7 @@ function m.normalize(path)
end
end)
path = util.expandPath(path)
+ path = path:gsub('^%.[/\\]+', '')
if platform.OS == 'Windows' then
path = path:gsub('[/\\]+', '\\')
:gsub('[/\\]+$', '')