summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/hover/label.lua4
-rw-r--r--script/core/noder.lua7
-rw-r--r--script/core/searcher.lua4
-rw-r--r--test/references/all.lua78
-rw-r--r--test/references/init.lua25
5 files changed, 83 insertions, 35 deletions
diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua
index 73d924e1..ce77dfe6 100644
--- a/script/core/hover/label.lua
+++ b/script/core/hover/label.lua
@@ -49,11 +49,11 @@ local function asValue(source, title)
local type = infer.searchAndViewInfers(source)
local literal = infer.searchAndViewLiterals(source)
local cont
- if not infer.hasType(source, 'string', 0)
+ if not infer.hasType(source, 'string')
and not type:find('%[%]$')
and not type:find('%w%<') then
if #vm.getRefs(source, '*') > 0
- or infer.hasType(source, 'table', 0) then
+ or infer.hasType(source, 'table') then
cont = buildTable(source)
end
end
diff --git a/script/core/noder.lua b/script/core/noder.lua
index 86dafff3..e6c7581f 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -464,7 +464,6 @@ function m.compileNode(noders, source)
if source.extends then
for _, ext in ipairs(source.extends) do
pushBackward(noders, id, getID(ext))
- pushBackward(noders, getID(ext), id)
end
end
if source.bindSources then
@@ -655,9 +654,6 @@ function m.compileNode(noders, source)
rtn.returnIndex
)
pushForward(noders, fullID, getID(rtn))
- for _, typeUnit in ipairs(rtn.types) do
- pushBackward(noders, getID(typeUnit), fullID)
- end
hasDocReturn[rtn.returnIndex] = true
end
end
@@ -743,7 +739,6 @@ function m.compileNode(noders, source)
)
local returnID = getID(rtn)
pushForward(noders, closureID, returnID)
- pushBackward(noders, returnID, closureID)
end
end
if source.type == 'generic.value' then
@@ -903,7 +898,7 @@ function m.compileNodes(source)
end)
-- Special rule: ('').XX -> stringlib.XX
pushBackward(noders, 'str:', 'dn:stringlib')
- --pushBackward(noders, 'dn:string', 'dn:stringlib')
+ pushBackward(noders, 'dn:string', 'dn:stringlib')
return noders
end
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 20fd600f..4063426d 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -227,7 +227,7 @@ function m.searchRefsByID(status, uri, expect, mode)
mark[id] = cmark
end
log.debug('search:', id, field)
- if field then
+ if field then
if cmark[field] then
return
end
@@ -354,7 +354,7 @@ function m.searchRefsByID(status, uri, expect, mode)
end
local function checkBackward(id, node, field)
- if mode ~= 'ref' and not field or ignoredIDs[id] then
+ if mode ~= 'ref' and not field then
return
end
for _, backwardID in ipairs(node.backward) do
diff --git a/test/references/all.lua b/test/references/all.lua
new file mode 100644
index 00000000..c27beb3c
--- /dev/null
+++ b/test/references/all.lua
@@ -0,0 +1,78 @@
+local core = require 'core.reference'
+local files = require 'files'
+
+local function catch_target(script)
+ local list = {}
+ local cur = 1
+ while true do
+ local start, finish = script:find('<[!?].-[!?]>', cur)
+ if not start then
+ break
+ end
+ list[#list+1] = { start + 2, finish - 2 }
+ cur = finish + 1
+ end
+ return list
+end
+
+local function founded(targets, results)
+ if #targets ~= #results then
+ return false
+ end
+ for _, target in ipairs(targets) do
+ for _, result in ipairs(results) do
+ if target[1] == result[1] and target[2] == result[2] then
+ goto NEXT
+ end
+ end
+ do return false end
+ ::NEXT::
+ end
+ return true
+end
+
+function TEST(script)
+ files.removeAll()
+ local expect = catch_target(script)
+ local start = script:find('<[?~]')
+ local finish = script:find('[?~]>')
+ local pos = (start + finish) // 2 + 1
+ local new_script = script:gsub('<[!?~]', ' '):gsub('[!?~]>', ' ')
+ files.setText('', new_script)
+
+ local results = core('', pos)
+ if results then
+ local positions = {}
+ for i, result in ipairs(results) do
+ positions[i] = { result.target.start, result.target.finish }
+ end
+ assert(founded(expect, positions))
+ else
+ assert(#expect == 0)
+ end
+end
+
+TEST [[
+---@class A
+local a = {}
+a.<?x?> = 1
+
+---@return A
+local function f() end
+
+local b = f()
+return b.<!x!>
+]]
+
+TEST [[
+---@class A
+local a = {}
+a.<?x?> = 1
+
+---@return table
+---@return A
+local function f() end
+
+local a, b = f()
+return a.x, b.<!x!>
+]]
diff --git a/test/references/init.lua b/test/references/init.lua
index cb026cbc..e6abc3bd 100644
--- a/test/references/init.lua
+++ b/test/references/init.lua
@@ -334,31 +334,6 @@ function mt2:doSomething()
end
]]
-TEST [[
----@class A
-local a = {}
-a.<?x?> = 1
-
----@return A
-local function f() end
-
-local b = f()
-return b.<!x!>
-]]
-
-TEST [[
----@class A
-local a = {}
-a.<?x?> = 1
-
----@return table
----@return A
-local function f() end
-
-local a, b = f()
-return a.x, b.<!x!>
-]]
-
-- TODO 支持泛型
do return end
TEST [[