diff options
-rw-r--r-- | script/workspace/require-path.lua | 24 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 36 |
2 files changed, 18 insertions, 42 deletions
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua index 94a8a161..52151dba 100644 --- a/script/workspace/require-path.lua +++ b/script/workspace/require-path.lua @@ -30,7 +30,7 @@ end function m.getVisiblePath(path) local searchers = config.get 'Lua.runtime.path' local strict = config.get 'Lua.runtime.pathStrict' - path = path:gsub('^[/\\]+', '') + path = workspace.normalize(path) local uri = furi.encode(path) local libraryPath = files.getLibraryPath(uri) if not m.cache[path] then @@ -42,6 +42,7 @@ function m.getVisiblePath(path) for _, searcher in ipairs(searchers) do local isAbsolute = searcher:match '^[/\\]' or searcher:match '^%a+%:' + searcher = workspace.normalize(searcher) local cutedPath = path local currentPath = path local head @@ -87,6 +88,8 @@ function m.findUrisByRequirePath(path) if type(path) ~= 'string' then return {} end + local separator = config.get 'Lua.completion.requireSeparator' + local fspath = path:gsub('%' .. separator, '/') local vm = require 'vm' local cache = vm.getCache 'findUrisByRequirePath' if cache[path] then @@ -94,30 +97,27 @@ function m.findUrisByRequirePath(path) 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 + if open == fspath 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 + for uri in files.eachFile() do + local infos = m.getVisiblePath(furi.decode(uri)) + for _, info in ipairs(infos) do + local fsexpect = info.expect:gsub('%' .. separator, '/') + if fsexpect == fspath then results[#results+1] = uri - searchers[uri] = posts[uri] .. luapath + searchers[uri] = info.searcher end end end + tracy.ZoneEnd() cache[path] = { results = results, diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index a715908c..cb6b140e 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -389,44 +389,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 '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 + if uri == myUri then + results[#results+1] = uri end - ::CONTINUE:: end - tracy.ZoneEnd() - resultCache[path] = { - results = results, - posts = posts, - } - return results, posts + resultCache[path] = results + return results end function m.normalize(path) |