summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/vm/global.lua3
-rw-r--r--script/vm/ref.lua36
-rw-r--r--test/crossfile/references.lua15
3 files changed, 32 insertions, 22 deletions
diff --git a/script/vm/global.lua b/script/vm/global.lua
index 1bd7576d..37b54349 100644
--- a/script/vm/global.lua
+++ b/script/vm/global.lua
@@ -34,6 +34,9 @@ end
---@param uri uri
---@param source parser.object
function mt:addGet(uri, source)
+ if PREVIEW then
+ return
+ end
local link = self.links[uri]
if not link.gets then
link.gets = {}
diff --git a/script/vm/ref.lua b/script/vm/ref.lua
index 4aa2e6d2..f342dae8 100644
--- a/script/vm/ref.lua
+++ b/script/vm/ref.lua
@@ -26,19 +26,6 @@ simpleSwitch = util.switch()
end
end
end)
- : case 'doc.alias.name'
- : call(function (source, pushResult)
- local global = vm.getGlobal('type', source[1])
- if not global then
- return
- end
- for _, get in ipairs(global:getGets(guide.getUri(source))) do
- pushResult(get)
- end
- for _, set in ipairs(global:getSets(guide.getUri(source))) do
- pushResult(set)
- end
- end)
---@async
local function searchInAllFiles(suri, searcher, notify)
@@ -229,18 +216,23 @@ function searchByParentNode(source, pushResult, defMap, fileNotify)
nodeSwitch(source.type, source, pushResult, defMap, fileNotify)
end
-local function searchByNode(source, pushResult)
- local node = vm.compileNode(source)
+local function searchByGlobal(source, pushResult)
+ if source.type == 'field'
+ or source.type == 'method'
+ or source.type == 'doc.class.name'
+ or source.type == 'doc.alias.name' then
+ source = source.parent
+ end
+ local node = vm.getGlobalNode(source)
if not node then
return
end
local uri = guide.getUri(source)
- for n in node:eachObject() do
- if n.type == 'global' then
- for _, get in ipairs(n:getGets(uri)) do
- pushResult(get)
- end
- end
+ for _, set in ipairs(node:getSets(uri)) do
+ pushResult(set)
+ end
+ for _, get in ipairs(node:getGets(uri)) do
+ pushResult(get)
end
end
@@ -292,7 +284,7 @@ function vm.getRefs(source, fileNotify)
searchBySimple(source, pushResult)
searchByLocalID(source, pushResult)
- searchByNode(source, pushResult)
+ searchByGlobal(source, pushResult)
local defMap = searchByDef(source, pushResult)
searchByParentNode(source, pushResult, defMap, fileNotify)
diff --git a/test/crossfile/references.lua b/test/crossfile/references.lua
index 0b7beb82..7376ccd8 100644
--- a/test/crossfile/references.lua
+++ b/test/crossfile/references.lua
@@ -373,3 +373,18 @@ TEST {
]]
},
}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@alias <~XX~> number
+ ]]
+ },
+ {
+ path = 'b.lua',
+ content = [[
+ ---@type <!XX!>
+ ]]
+ }
+}