Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Dec 16, 2021
1 parent ab5e1b3 commit 6924e8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 42 deletions.
24 changes: 12 additions & 12 deletions script/workspace/require-path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -87,37 +88,36 @@ 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
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
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,
Expand Down
36 changes: 6 additions & 30 deletions script/workspace/workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6924e8a

Please sign in to comment.