Skip to content

Commit 6924e8a

Browse files
committedDec 16, 2021
clean up
1 parent ab5e1b3 commit 6924e8a

File tree

2 files changed

+18
-42
lines changed

2 files changed

+18
-42
lines changed
 

‎script/workspace/require-path.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ end
3030
function m.getVisiblePath(path)
3131
local searchers = config.get 'Lua.runtime.path'
3232
local strict = config.get 'Lua.runtime.pathStrict'
33-
path = path:gsub('^[/\\]+', '')
33+
path = workspace.normalize(path)
3434
local uri = furi.encode(path)
3535
local libraryPath = files.getLibraryPath(uri)
3636
if not m.cache[path] then
@@ -42,6 +42,7 @@ function m.getVisiblePath(path)
4242
for _, searcher in ipairs(searchers) do
4343
local isAbsolute = searcher:match '^[/\\]'
4444
or searcher:match '^%a+%:'
45+
searcher = workspace.normalize(searcher)
4546
local cutedPath = path
4647
local currentPath = path
4748
local head
@@ -87,37 +88,36 @@ function m.findUrisByRequirePath(path)
8788
if type(path) ~= 'string' then
8889
return {}
8990
end
91+
local separator = config.get 'Lua.completion.requireSeparator'
92+
local fspath = path:gsub('%' .. separator, '/')
9093
local vm = require 'vm'
9194
local cache = vm.getCache 'findUrisByRequirePath'
9295
if cache[path] then
9396
return cache[path].results, cache[path].searchers
9497
end
9598
tracy.ZoneBeginN('findUrisByRequirePath')
9699
local results = {}
97-
local mark = {}
98100
local searchers = {}
99101
for uri in files.eachDll() do
100102
local opens = files.getDllOpens(uri) or {}
101103
for _, open in ipairs(opens) do
102-
if open == path then
104+
if open == fspath then
103105
results[#results+1] = uri
104106
end
105107
end
106108
end
107109

108-
local input = path:gsub('%.', '/')
109-
:gsub('%%', '%%%%')
110-
for _, luapath in ipairs(config.get 'Lua.runtime.path') do
111-
local part = workspace.normalize(luapath:gsub('%?', input))
112-
local uris, posts = workspace.findUrisByFilePath(part)
113-
for _, uri in ipairs(uris) do
114-
if not mark[uri] then
115-
mark[uri] = true
110+
for uri in files.eachFile() do
111+
local infos = m.getVisiblePath(furi.decode(uri))
112+
for _, info in ipairs(infos) do
113+
local fsexpect = info.expect:gsub('%' .. separator, '/')
114+
if fsexpect == fspath then
116115
results[#results+1] = uri
117-
searchers[uri] = posts[uri] .. luapath
116+
searchers[uri] = info.searcher
118117
end
119118
end
120119
end
120+
121121
tracy.ZoneEnd()
122122
cache[path] = {
123123
results = results,

‎script/workspace/workspace.lua

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -389,44 +389,20 @@ function m.findUrisByFilePath(path)
389389
if type(path) ~= 'string' then
390390
return {}
391391
end
392-
local lpath = furi.encode(path):gsub('^file:///', '')
392+
local myUri = furi.encode(path)
393393
local vm = require 'vm'
394394
local resultCache = vm.getCache 'findUrisByRequirePath.result'
395395
if resultCache[path] then
396-
return resultCache[path].results, resultCache[path].posts
396+
return resultCache[path]
397397
end
398-
tracy.ZoneBeginN('findUrisByFilePath #1')
399-
local strict = config.get 'Lua.runtime.pathStrict'
400398
local results = {}
401-
local posts = {}
402399
for uri in files.eachFile() do
403-
if not uri:find(lpath, 1, true) then
404-
goto CONTINUE
405-
end
406-
local relat = m.getRelativePath(uri)
407-
local pathLen = #path
408-
local curPath = relat
409-
local curLen = #curPath
410-
local seg = curPath:sub(curLen - pathLen, curLen - pathLen)
411-
if seg == '/' or seg == '\\' or seg == '' then
412-
if strict and seg ~= '' then
413-
goto CONTINUE
414-
end
415-
local see = curPath:sub(curLen - pathLen + 1, curLen)
416-
if see == path then
417-
results[#results+1] = uri
418-
local post = curPath:sub(1, curLen - pathLen)
419-
posts[uri] = post:gsub('^[/\\]+', '')
420-
end
400+
if uri == myUri then
401+
results[#results+1] = uri
421402
end
422-
::CONTINUE::
423403
end
424-
tracy.ZoneEnd()
425-
resultCache[path] = {
426-
results = results,
427-
posts = posts,
428-
}
429-
return results, posts
404+
resultCache[path] = results
405+
return results
430406
end
431407

432408
function m.normalize(path)

0 commit comments

Comments
 (0)