summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/definition.lua3
-rw-r--r--script/core/diagnostics/different-requires.lua4
-rw-r--r--script/core/hover/description.lua3
-rw-r--r--script/core/searcher.lua4
-rw-r--r--script/core/type-definition.lua3
-rw-r--r--script/vm/getLinks.lua4
-rw-r--r--script/workspace/require-path.lua45
-rw-r--r--script/workspace/workspace.lua45
-rw-r--r--test/crossfile/definition.lua23
9 files changed, 79 insertions, 55 deletions
diff --git a/script/core/definition.lua b/script/core/definition.lua
index a1f46afc..eadae30f 100644
--- a/script/core/definition.lua
+++ b/script/core/definition.lua
@@ -4,6 +4,7 @@ local files = require 'files'
local vm = require 'vm'
local findSource = require 'core.find-source'
local guide = require 'parser.guide'
+local rpath = require 'workspace.require-path'
local function sortResults(results)
-- 先按照顺序排序
@@ -74,7 +75,7 @@ local function checkRequire(source, offset)
return nil
end
if libName == 'require' then
- return workspace.findUrisByRequirePath(literal)
+ return rpath.findUrisByRequirePath(literal)
elseif libName == 'dofile'
or libName == 'loadfile' then
return workspace.findUrisByFilePath(literal)
diff --git a/script/core/diagnostics/different-requires.lua b/script/core/diagnostics/different-requires.lua
index fd7415b6..3a49ceef 100644
--- a/script/core/diagnostics/different-requires.lua
+++ b/script/core/diagnostics/different-requires.lua
@@ -3,7 +3,7 @@ local guide = require 'parser.guide'
local lang = require 'language'
local config = require 'config'
local vm = require 'vm'
-local ws = require 'workspace'
+local rpath = require 'workspace.require-path'
return function (uri, callback)
local state = files.getState(uri)
@@ -21,7 +21,7 @@ return function (uri, callback)
return
end
local literal = arg1[1]
- local results = ws.findUrisByRequirePath(literal)
+ local results = rpath.findUrisByRequirePath(literal)
if not results or #results ~= 1 then
return
end
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index 1af459c3..df9fb6e9 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -9,12 +9,13 @@ local lang = require 'language'
local util = require 'utility'
local guide = require 'parser.guide'
local noder = require 'core.noder'
+local rpath = require 'workspace.require-path'
local function collectRequire(mode, literal)
local rootPath = ws.path or ''
local result, searchers
if mode == 'require' then
- result, searchers = ws.findUrisByRequirePath(literal)
+ result, searchers = rpath.findUrisByRequirePath(literal)
elseif mode == 'dofile'
or mode == 'loadfile' then
result = ws.findUrisByFilePath(literal)
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 9c0f0faa..72dda55f 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -2,7 +2,7 @@ local noder = require 'core.noder'
local guide = require 'parser.guide'
local files = require 'files'
local generic = require 'core.generic'
-local ws = require 'workspace'
+local rpath = require 'workspace.require-path'
local vm = require 'vm.vm'
local collector = require 'core.collector'
local util = require 'utility'
@@ -796,7 +796,7 @@ function m.searchRefsByID(status, suri, expect, mode)
if not requireName then
return
end
- local uris = ws.findUrisByRequirePath(requireName)
+ local uris = rpath.findUrisByRequirePath(requireName)
footprint(status, 'require:', requireName)
for i = 1, #uris do
local ruri = uris[i]
diff --git a/script/core/type-definition.lua b/script/core/type-definition.lua
index dee07c61..e9cf3e47 100644
--- a/script/core/type-definition.lua
+++ b/script/core/type-definition.lua
@@ -5,6 +5,7 @@ local vm = require 'vm'
local findSource = require 'core.find-source'
local guide = require 'parser.guide'
local infer = require 'core.infer'
+local rpath = require 'workspace.require-path'
local function sortResults(results)
-- 先按照顺序排序
@@ -75,7 +76,7 @@ local function checkRequire(source, offset)
return nil
end
if libName == 'require' then
- return workspace.findUrisByRequirePath(literal)
+ return rpath.findUrisByRequirePath(literal)
elseif libName == 'dofile'
or libName == 'loadfile' then
return workspace.findUrisByFilePath(literal)
diff --git a/script/vm/getLinks.lua b/script/vm/getLinks.lua
index b245bdaa..77d869f8 100644
--- a/script/vm/getLinks.lua
+++ b/script/vm/getLinks.lua
@@ -2,9 +2,9 @@ local guide = require 'parser.guide'
---@class vm
local vm = require 'vm.vm'
local files = require 'files'
+local rpath = require 'workspace.require-path'
local function getFileLinks(uri)
- local ws = require 'workspace'
local links = {}
local state = files.getState(uri)
if not state then
@@ -20,7 +20,7 @@ local function getFileLinks(uri)
if not args or not args[1] or args[1].type ~= 'string' then
return
end
- local uris = ws.findUrisByRequirePath(args[1][1])
+ local uris = rpath.findUrisByRequirePath(args[1][1])
for _, u in ipairs(uris) do
if not links[u] then
links[u] = {}
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua
index e2149bac..94a8a161 100644
--- a/script/workspace/require-path.lua
+++ b/script/workspace/require-path.lua
@@ -81,6 +81,51 @@ function m.getVisiblePath(path)
return m.cache[path]
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 '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
+ results[#results+1] = uri
+ searchers[uri] = posts[uri] .. luapath
+ end
+ end
+ end
+ tracy.ZoneEnd()
+ cache[path] = {
+ results = results,
+ searchers = searchers,
+ }
+ return results, searchers
+end
+
function m.flush()
m.cache = {}
end
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index 529c8936..a715908c 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -429,51 +429,6 @@ function m.findUrisByFilePath(path)
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 '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
- end
- end
- tracy.ZoneEnd()
- cache[path] = {
- results = results,
- searchers = searchers,
- }
- return results, searchers
-end
-
function m.normalize(path)
if not path then
return nil
diff --git a/test/crossfile/definition.lua b/test/crossfile/definition.lua
index b0cc232f..f44633e1 100644
--- a/test/crossfile/definition.lua
+++ b/test/crossfile/definition.lua
@@ -869,10 +869,10 @@ print(t.<?x?>)
}
local originRuntimePath = config.get 'Lua.runtime.path'
+
config.set('Lua.runtime.path', {
'./?.lua'
})
-
TEST {
{
path = 'a.lua',
@@ -891,4 +891,25 @@ print(t.<?x?>)
}
}
+--config.set('Lua.runtime.path', {
+-- '/home/?.lua'
+--})
+--TEST {
+-- {
+-- path = '/home/a.lua',
+-- content = [[
+--return {
+-- <!x!> = 1,
+--}
+--]],
+-- },
+-- {
+-- path = 'b.lua',
+-- content = [[
+--local t = require 'a'
+--print(t.<?x?>)
+-- ]]
+-- }
+--}
+
config.set('Lua.runtime.path', originRuntimePath)