diff options
author | sumneko <sumneko@hotmail.com> | 2021-12-21 22:49:59 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2021-12-21 22:49:59 +0800 |
commit | b7344640a0ab9a07551ee5ebc435657b45659553 (patch) | |
tree | 0fef08a7dbb0a115e0e1249b6123fd529cf1fc58 /script/workspace/workspace.lua | |
parent | c47baf932309a05673b7931fdf6a1be207fb7bc4 (diff) | |
parent | ec4f497aa2624d9dce29e1de0cfd28ecd85e7df3 (diff) | |
download | lua-language-server-b7344640a0ab9a07551ee5ebc435657b45659553.zip |
Merge remote-tracking branch 'origin/master' into multi-workspace
Diffstat (limited to 'script/workspace/workspace.lua')
-rw-r--r-- | script/workspace/workspace.lua | 82 |
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('[/\\]+$', '') |