summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/diagnostics/ambiguity-1.lua8
-rw-r--r--script/core/diagnostics/close-non-object.lua4
-rw-r--r--script/core/diagnostics/code-after-break.lua4
-rw-r--r--script/core/diagnostics/count-down-loop.lua4
-rw-r--r--script/core/diagnostics/deprecated.lua6
-rw-r--r--script/core/diagnostics/duplicate-index.lua4
-rw-r--r--script/core/diagnostics/duplicate-set-field.lua13
-rw-r--r--script/core/diagnostics/empty-block.lua8
-rw-r--r--script/core/diagnostics/global-in-nil-env.lua12
-rw-r--r--script/core/diagnostics/lowercase-global.lua6
-rw-r--r--script/core/diagnostics/newfield-call.lua8
-rw-r--r--script/core/diagnostics/newline-call.lua8
-rw-r--r--script/core/diagnostics/redefined-local.lua6
-rw-r--r--script/core/diagnostics/redundant-parameter.lua4
-rw-r--r--script/core/diagnostics/trailing-space.lua4
-rw-r--r--script/core/diagnostics/unbalanced-assignments.lua4
-rw-r--r--script/core/diagnostics/undefined-doc-name.lua4
-rw-r--r--script/core/diagnostics/undefined-env-child.lua10
-rw-r--r--script/core/diagnostics/undefined-field.lua8
-rw-r--r--script/core/diagnostics/undefined-global.lua18
-rw-r--r--script/core/diagnostics/unused-function.lua6
-rw-r--r--script/core/diagnostics/unused-label.lua4
-rw-r--r--script/core/diagnostics/unused-local.lua4
-rw-r--r--script/core/diagnostics/unused-vararg.lua4
-rw-r--r--script/core/linker.lua7
-rw-r--r--script/parser/guide.lua69
-rw-r--r--script/vm/eachDef.lua2
-rw-r--r--script/vm/eachRef.lua2
28 files changed, 159 insertions, 82 deletions
diff --git a/script/core/diagnostics/ambiguity-1.lua b/script/core/diagnostics/ambiguity-1.lua
index 0b8385d8..37815fb5 100644
--- a/script/core/diagnostics/ambiguity-1.lua
+++ b/script/core/diagnostics/ambiguity-1.lua
@@ -1,6 +1,6 @@
-local files = require 'files'
-local searcher = require 'core.searcher'
-local lang = require 'language'
+local files = require 'files'
+local guide = require 'parser.guide'
+local lang = require 'language'
local opMap = {
['+'] = true,
@@ -30,7 +30,7 @@ return function (uri, callback)
return
end
local text = files.getText(uri)
- searcher.eachSourceType(ast.ast, 'binary', function (source)
+ guide.eachSourceType(ast.ast, 'binary', function (source)
if source.op.type ~= 'or' then
return
end
diff --git a/script/core/diagnostics/close-non-object.lua b/script/core/diagnostics/close-non-object.lua
index 11c2b820..7828efe9 100644
--- a/script/core/diagnostics/close-non-object.lua
+++ b/script/core/diagnostics/close-non-object.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local lang = require 'language'
return function (uri, callback)
@@ -8,7 +8,7 @@ return function (uri, callback)
return
end
- searcher.eachSourceType(state.ast, 'local', function (source)
+ guide.eachSourceType(state.ast, 'local', function (source)
if not source.attrs then
return
end
diff --git a/script/core/diagnostics/code-after-break.lua b/script/core/diagnostics/code-after-break.lua
index dc7226ae..f300a61a 100644
--- a/script/core/diagnostics/code-after-break.lua
+++ b/script/core/diagnostics/code-after-break.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local lang = require 'language'
local define = require 'proto.define'
@@ -10,7 +10,7 @@ return function (uri, callback)
end
local mark = {}
- searcher.eachSourceType(state.ast, 'break', function (source)
+ guide.eachSourceType(state.ast, 'break', function (source)
local list = source.parent
if mark[list] then
return
diff --git a/script/core/diagnostics/count-down-loop.lua b/script/core/diagnostics/count-down-loop.lua
index f682ec3c..ee245781 100644
--- a/script/core/diagnostics/count-down-loop.lua
+++ b/script/core/diagnostics/count-down-loop.lua
@@ -1,5 +1,5 @@
local files = require "files"
-local searcher = require "core.searcher"
+local guide = require "parser.guide"
local lang = require 'language'
return function (uri, callback)
@@ -9,7 +9,7 @@ return function (uri, callback)
return
end
- searcher.eachSourceType(state.ast, 'loop', function (source)
+ guide.eachSourceType(state.ast, 'loop', function (source)
if not source.loc or not source.loc.value then
return
end
diff --git a/script/core/diagnostics/deprecated.lua b/script/core/diagnostics/deprecated.lua
index d6bccc10..03475b65 100644
--- a/script/core/diagnostics/deprecated.lua
+++ b/script/core/diagnostics/deprecated.lua
@@ -1,7 +1,7 @@
local files = require 'files'
local vm = require 'vm'
local lang = require 'language'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local config = require 'config'
local define = require 'proto.define'
local await = require 'await'
@@ -12,7 +12,7 @@ return function (uri, callback)
return
end
- searcher.eachSource(ast.ast, function (src)
+ guide.eachSource(ast.ast, function (src)
if src.type ~= 'getglobal'
and src.type ~= 'getfield'
and src.type ~= 'getindex'
@@ -20,7 +20,7 @@ return function (uri, callback)
return
end
if src.type == 'getglobal' then
- local key = searcher.getKeyName(src)
+ local key = src[1]
if not key then
return
end
diff --git a/script/core/diagnostics/duplicate-index.lua b/script/core/diagnostics/duplicate-index.lua
index 65fb00cd..d1ba9261 100644
--- a/script/core/diagnostics/duplicate-index.lua
+++ b/script/core/diagnostics/duplicate-index.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local lang = require 'language'
local define = require 'proto.define'
local vm = require 'vm'
@@ -10,7 +10,7 @@ return function (uri, callback)
return
end
- searcher.eachSourceType(ast.ast, 'table', function (source)
+ guide.eachSourceType(ast.ast, 'table', function (source)
local mark = {}
for _, obj in ipairs(source) do
if obj.type == 'tablefield'
diff --git a/script/core/diagnostics/duplicate-set-field.lua b/script/core/diagnostics/duplicate-set-field.lua
index ff915217..7b1718ec 100644
--- a/script/core/diagnostics/duplicate-set-field.lua
+++ b/script/core/diagnostics/duplicate-set-field.lua
@@ -1,7 +1,8 @@
-local files = require 'files'
-local searcher = require 'core.searcher'
-local lang = require 'language'
-local define = require 'proto.define'
+local files = require 'files'
+local searcher = require 'core.searcher'
+local lang = require 'language'
+local define = require 'proto.define'
+local guide = require "parser.guide"
return function (uri, callback)
local ast = files.getAst(uri)
@@ -9,7 +10,7 @@ return function (uri, callback)
return
end
- searcher.eachSourceType(ast.ast, 'local', function (source)
+ guide.eachSourceType(ast.ast, 'local', function (source)
if not source.ref then
return
end
@@ -25,7 +26,7 @@ return function (uri, callback)
if nxt.type == 'setfield'
or nxt.type == 'setmethod'
or nxt.type == 'setindex' then
- local name = searcher.getKeyName(nxt)
+ local name = guide.getKeyName(nxt)
if not name then
goto CONTINUE
end
diff --git a/script/core/diagnostics/empty-block.lua b/script/core/diagnostics/empty-block.lua
index abd20bde..2024f4e3 100644
--- a/script/core/diagnostics/empty-block.lua
+++ b/script/core/diagnostics/empty-block.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local lang = require 'language'
local define = require 'proto.define'
@@ -11,7 +11,7 @@ return function (uri, callback)
return
end
- searcher.eachSourceType(ast.ast, 'if', function (source)
+ guide.eachSourceType(ast.ast, 'if', function (source)
for _, block in ipairs(source) do
if #block > 0 then
return
@@ -24,7 +24,7 @@ return function (uri, callback)
message = lang.script.DIAG_EMPTY_BLOCK,
}
end)
- searcher.eachSourceType(ast.ast, 'loop', function (source)
+ guide.eachSourceType(ast.ast, 'loop', function (source)
if #source > 0 then
return
end
@@ -35,7 +35,7 @@ return function (uri, callback)
message = lang.script.DIAG_EMPTY_BLOCK,
}
end)
- searcher.eachSourceType(ast.ast, 'in', function (source)
+ guide.eachSourceType(ast.ast, 'in', function (source)
if #source > 0 then
return
end
diff --git a/script/core/diagnostics/global-in-nil-env.lua b/script/core/diagnostics/global-in-nil-env.lua
index 02cd4f3f..9a0d4f35 100644
--- a/script/core/diagnostics/global-in-nil-env.lua
+++ b/script/core/diagnostics/global-in-nil-env.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local lang = require 'language'
-- TODO: 检查路径是否可达
@@ -12,8 +12,8 @@ return function (uri, callback)
if not ast then
return
end
- local root = searcher.getRoot(ast.ast)
- local env = searcher.getENV(root)
+ local root = guide.getRoot(ast.ast)
+ local env = guide.getENV(root)
local nilDefs = {}
if not env.ref then
@@ -36,7 +36,7 @@ return function (uri, callback)
if node.tag == '_ENV' then
local ok
for _, nilDef in ipairs(nilDefs) do
- local mode, pathA = searcher.getPath(nilDef, source)
+ local mode, pathA = guide.getPath(nilDef, source)
if mode == 'before'
and mayRun(pathA) then
ok = nilDef
@@ -61,6 +61,6 @@ return function (uri, callback)
end
end
- searcher.eachSourceType(ast.ast, 'getglobal', check)
- searcher.eachSourceType(ast.ast, 'setglobal', check)
+ guide.eachSourceType(ast.ast, 'getglobal', check)
+ guide.eachSourceType(ast.ast, 'setglobal', check)
end
diff --git a/script/core/diagnostics/lowercase-global.lua b/script/core/diagnostics/lowercase-global.lua
index aaeb2c94..8c7ae793 100644
--- a/script/core/diagnostics/lowercase-global.lua
+++ b/script/core/diagnostics/lowercase-global.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local lang = require 'language'
local config = require 'config'
local vm = require 'vm'
@@ -28,8 +28,8 @@ return function (uri, callback)
definedGlobal[name] = true
end
- searcher.eachSourceType(ast.ast, 'setglobal', function (source)
- local name = searcher.getKeyName(source)
+ guide.eachSourceType(ast.ast, 'setglobal', function (source)
+ local name = guide.getKeyName(source)
if definedGlobal[name] then
return
end
diff --git a/script/core/diagnostics/newfield-call.lua b/script/core/diagnostics/newfield-call.lua
index a71ae3e1..75681cbc 100644
--- a/script/core/diagnostics/newfield-call.lua
+++ b/script/core/diagnostics/newfield-call.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local lang = require 'language'
return function (uri, callback)
@@ -11,15 +11,15 @@ return function (uri, callback)
local lines = files.getLines(uri)
local text = files.getText(uri)
- searcher.eachSourceType(ast.ast, 'table', function (source)
+ guide.eachSourceType(ast.ast, 'table', function (source)
for i = 1, #source do
local field = source[i]
if field.type == 'call' then
local func = field.node
local args = field.args
if args then
- local funcLine = searcher.positionOf(lines, func.finish)
- local argsLine = searcher.positionOf(lines, args.start)
+ local funcLine = guide.positionOf(lines, func.finish)
+ local argsLine = guide.positionOf(lines, args.start)
if argsLine > funcLine then
callback {
start = field.start,
diff --git a/script/core/diagnostics/newline-call.lua b/script/core/diagnostics/newline-call.lua
index 31a8d09f..159a60c9 100644
--- a/script/core/diagnostics/newline-call.lua
+++ b/script/core/diagnostics/newline-call.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local lang = require 'language'
return function (uri, callback)
@@ -10,7 +10,7 @@ return function (uri, callback)
return
end
- searcher.eachSourceType(ast.ast, 'call', function (source)
+ guide.eachSourceType(ast.ast, 'call', function (source)
local node = source.node
local args = source.args
if not args then
@@ -26,8 +26,8 @@ return function (uri, callback)
return
end
- local nodeRow = searcher.positionOf(lines, node.finish)
- local argRow = searcher.positionOf(lines, args.start)
+ local nodeRow = guide.positionOf(lines, node.finish)
+ local argRow = guide.positionOf(lines, args.start)
if nodeRow == argRow then
return
end
diff --git a/script/core/diagnostics/redefined-local.lua b/script/core/diagnostics/redefined-local.lua
index 4922831b..5e53d837 100644
--- a/script/core/diagnostics/redefined-local.lua
+++ b/script/core/diagnostics/redefined-local.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local lang = require 'language'
return function (uri, callback)
@@ -7,13 +7,13 @@ return function (uri, callback)
if not ast then
return
end
- searcher.eachSourceType(ast.ast, 'local', function (source)
+ guide.eachSourceType(ast.ast, 'local', function (source)
local name = source[1]
if name == '_'
or name == ast.ENVMode then
return
end
- local exist = searcher.getLocal(source, name, source.start-1)
+ local exist = guide.getLocal(source, name, source.start-1)
if exist then
callback {
start = source.start,
diff --git a/script/core/diagnostics/redundant-parameter.lua b/script/core/diagnostics/redundant-parameter.lua
index a6907bda..b465dceb 100644
--- a/script/core/diagnostics/redundant-parameter.lua
+++ b/script/core/diagnostics/redundant-parameter.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local vm = require 'vm'
local lang = require 'language'
local define = require 'proto.define'
@@ -74,7 +74,7 @@ return function (uri, callback)
local cache = vm.getCache 'redundant-parameter'
- searcher.eachSourceType(ast.ast, 'call', function (source)
+ guide.eachSourceType(ast.ast, 'call', function (source)
local callArgs = countCallArgs(source)
if callArgs == 0 then
return
diff --git a/script/core/diagnostics/trailing-space.lua b/script/core/diagnostics/trailing-space.lua
index 6ee92d26..e54a6e60 100644
--- a/script/core/diagnostics/trailing-space.lua
+++ b/script/core/diagnostics/trailing-space.lua
@@ -1,10 +1,10 @@
local files = require 'files'
local lang = require 'language'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local function isInString(ast, offset)
local result = false
- searcher.eachSourceType(ast, 'string', function (source)
+ guide.eachSourceType(ast, 'string', function (source)
if offset >= source.start and offset <= source.finish then
result = true
end
diff --git a/script/core/diagnostics/unbalanced-assignments.lua b/script/core/diagnostics/unbalanced-assignments.lua
index 006223db..35aebb45 100644
--- a/script/core/diagnostics/unbalanced-assignments.lua
+++ b/script/core/diagnostics/unbalanced-assignments.lua
@@ -1,7 +1,7 @@
local files = require 'files'
local define = require 'proto.define'
local lang = require 'language'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
return function (uri, callback, code)
local ast = files.getAst(uri)
@@ -31,7 +31,7 @@ return function (uri, callback, code)
end
end
- searcher.eachSource(ast.ast, function (source)
+ guide.eachSource(ast.ast, function (source)
if source.type == 'local'
or source.type == 'setlocal'
or source.type == 'setglobal'
diff --git a/script/core/diagnostics/undefined-doc-name.lua b/script/core/diagnostics/undefined-doc-name.lua
index 54f08ee6..62446bb3 100644
--- a/script/core/diagnostics/undefined-doc-name.lua
+++ b/script/core/diagnostics/undefined-doc-name.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local lang = require 'language'
local define = require 'proto.define'
local vm = require 'vm'
@@ -44,7 +44,7 @@ return function (uri, callback)
return true
end
- searcher.eachSource(state.ast.docs, function (source)
+ guide.eachSource(state.ast.docs, function (source)
if source.type ~= 'doc.extends.name'
and source.type ~= 'doc.type.name' then
return
diff --git a/script/core/diagnostics/undefined-env-child.lua b/script/core/diagnostics/undefined-env-child.lua
index a32ad306..c97c3fe8 100644
--- a/script/core/diagnostics/undefined-env-child.lua
+++ b/script/core/diagnostics/undefined-env-child.lua
@@ -1,14 +1,14 @@
-local files = require 'files'
-local searcher = require 'core.searcher'
-local vm = require 'vm'
-local lang = require 'language'
+local files = require 'files'
+local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
+local lang = require 'language'
return function (uri, callback)
local ast = files.getAst(uri)
if not ast then
return
end
- searcher.eachSourceType(ast.ast, 'getglobal', function (source)
+ guide.eachSourceType(ast.ast, 'getglobal', function (source)
-- 单独验证自己是否在重载过的 _ENV 中有定义
if source.node.tag == '_ENV' then
return
diff --git a/script/core/diagnostics/undefined-field.lua b/script/core/diagnostics/undefined-field.lua
index 1f88740e..ffa70364 100644
--- a/script/core/diagnostics/undefined-field.lua
+++ b/script/core/diagnostics/undefined-field.lua
@@ -2,7 +2,7 @@ local files = require 'files'
local vm = require 'vm'
local lang = require 'language'
local config = require 'config'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local define = require 'proto.define'
return function (uri, callback)
@@ -87,7 +87,7 @@ return function (uri, callback)
end
local function checkUndefinedField(src)
- local fieldName = searcher.getKeyName(src)
+ local fieldName = guide.getKeyName(src)
local allDocClass = getAllDocClassFromInfer(src.node)
if (not allDocClass) or (#allDocClass == 0) then
@@ -118,6 +118,6 @@ return function (uri, callback)
end
end
end
- searcher.eachSourceType(ast.ast, 'getfield', checkUndefinedField);
- searcher.eachSourceType(ast.ast, 'getmethod', checkUndefinedField);
+ guide.eachSourceType(ast.ast, 'getfield', checkUndefinedField);
+ guide.eachSourceType(ast.ast, 'getmethod', checkUndefinedField);
end
diff --git a/script/core/diagnostics/undefined-global.lua b/script/core/diagnostics/undefined-global.lua
index 3c7f02d1..439a1854 100644
--- a/script/core/diagnostics/undefined-global.lua
+++ b/script/core/diagnostics/undefined-global.lua
@@ -1,9 +1,9 @@
-local files = require 'files'
-local vm = require 'vm'
-local lang = require 'language'
-local config = require 'config'
-local searcher = require 'core.searcher'
-local define = require 'proto.define'
+local files = require 'files'
+local vm = require 'vm'
+local lang = require 'language'
+local config = require 'config'
+local guide = require 'parser.guide'
+local linker = require 'core.linker'
local requireLike = {
['include'] = true,
@@ -19,8 +19,8 @@ return function (uri, callback)
end
-- 遍历全局变量,检查所有没有 set 模式的全局变量
- searcher.eachSourceType(ast.ast, 'getglobal', function (src)
- local key = searcher.getKeyName(src)
+ guide.eachSourceType(ast.ast, 'getglobal', function (src)
+ local key = src[1]
if not key then
return
end
@@ -30,7 +30,7 @@ return function (uri, callback)
if config.config.runtime.special[key] then
return
end
- if #vm.getGlobalSets(key) == 0 then
+ if #vm.getDefs(src) == 0 then
local message = lang.script('DIAG_UNDEF_GLOBAL', key)
if requireLike[key:lower()] then
message = ('%s(%s)'):format(message, lang.script('DIAG_REQUIRE_LIKE', key))
diff --git a/script/core/diagnostics/unused-function.lua b/script/core/diagnostics/unused-function.lua
index 2d224e5e..41c239f9 100644
--- a/script/core/diagnostics/unused-function.lua
+++ b/script/core/diagnostics/unused-function.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local vm = require 'vm'
local define = require 'proto.define'
local lang = require 'language'
@@ -45,7 +45,7 @@ return function (uri, callback)
local refs = vm.getRefs(source)
for _, src in ipairs(refs) do
if vm.isGet(src) then
- local func = searcher.getParentFunction(src)
+ local func = guide.getParentFunction(src)
if not checkFunction(func) then
hasGet = true
break
@@ -75,7 +75,7 @@ return function (uri, callback)
end
-- 只检查局部函数
- searcher.eachSourceType(ast.ast, 'function', function (source)
+ guide.eachSourceType(ast.ast, 'function', function (source)
checkFunction(source)
end)
end
diff --git a/script/core/diagnostics/unused-label.lua b/script/core/diagnostics/unused-label.lua
index 5d9488a1..e6d998ba 100644
--- a/script/core/diagnostics/unused-label.lua
+++ b/script/core/diagnostics/unused-label.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local define = require 'proto.define'
local lang = require 'language'
@@ -9,7 +9,7 @@ return function (uri, callback)
return
end
- searcher.eachSourceType(ast.ast, 'label', function (source)
+ guide.eachSourceType(ast.ast, 'label', function (source)
if not source.ref then
callback {
start = source.start,
diff --git a/script/core/diagnostics/unused-local.lua b/script/core/diagnostics/unused-local.lua
index 4e3c8217..9bb2c492 100644
--- a/script/core/diagnostics/unused-local.lua
+++ b/script/core/diagnostics/unused-local.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local define = require 'proto.define'
local lang = require 'language'
@@ -81,7 +81,7 @@ return function (uri, callback)
if not ast then
return
end
- searcher.eachSourceType(ast.ast, 'local', function (source)
+ guide.eachSourceType(ast.ast, 'local', function (source)
local name = source[1]
if name == '_'
or name == ast.ENVMode then
diff --git a/script/core/diagnostics/unused-vararg.lua b/script/core/diagnostics/unused-vararg.lua
index 301394c3..74cc08e7 100644
--- a/script/core/diagnostics/unused-vararg.lua
+++ b/script/core/diagnostics/unused-vararg.lua
@@ -1,5 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
+local guide = require 'parser.guide'
local define = require 'proto.define'
local lang = require 'language'
@@ -9,7 +9,7 @@ return function (uri, callback)
return
end
- searcher.eachSourceType(ast.ast, 'function', function (source)
+ guide.eachSourceType(ast.ast, 'function', function (source)
local args = source.args
if not args then
return
diff --git a/script/core/linker.lua b/script/core/linker.lua
index 825f0b52..f11855e0 100644
--- a/script/core/linker.lua
+++ b/script/core/linker.lua
@@ -782,6 +782,13 @@ function m.getID(source)
return getID(source)
end
+---获取source的key
+---@param source parser.guide.object
+---@return string
+function m.getKey(source)
+ return getKey(source)
+end
+
---编译整个文件的link
---@param source parser.guide.object
---@return table
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 5de14856..f87bbbaa 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -723,4 +723,73 @@ function m.getSpecial(source)
return source.special
end
+function m.getKeyNameOfLiteral(obj)
+ if not obj then
+ return nil
+ end
+ local tp = obj.type
+ if tp == 'field'
+ or tp == 'method' then
+ return obj[1]
+ elseif tp == 'string' then
+ local s = obj[1]
+ if s then
+ return s
+ end
+ elseif tp == 'number' then
+ local n = obj[1]
+ if n then
+ return ('%s'):format(util.viewLiteral(obj[1]))
+ end
+ elseif tp == 'boolean' then
+ local b = obj[1]
+ if b then
+ return tostring(b)
+ end
+ end
+end
+
+function m.getKeyName(obj)
+ if not obj then
+ return nil
+ end
+ local tp = obj.type
+ if tp == 'getglobal'
+ or tp == 'setglobal' then
+ return obj[1]
+ elseif tp == 'local'
+ or tp == 'getlocal'
+ or tp == 'setlocal' then
+ return obj[1]
+ elseif tp == 'getfield'
+ or tp == 'setfield'
+ or tp == 'tablefield' then
+ if obj.field then
+ return obj.field[1]
+ end
+ elseif tp == 'getmethod'
+ or tp == 'setmethod' then
+ if obj.method then
+ return obj.method[1]
+ end
+ elseif tp == 'getindex'
+ or tp == 'setindex'
+ or tp == 'tableindex' then
+ return m.getKeyNameOfLiteral(obj.index)
+ elseif tp == 'field'
+ or tp == 'method'
+ or tp == 'doc.see.field' then
+ return obj[1]
+ elseif tp == 'doc.class' then
+ return obj.class[1]
+ elseif tp == 'doc.alias' then
+ return obj.alias[1]
+ elseif tp == 'doc.field' then
+ return obj.field[1]
+ elseif tp == 'dummy' then
+ return obj[1]
+ end
+ return m.getKeyNameOfLiteral(obj)
+end
+
return m
diff --git a/script/vm/eachDef.lua b/script/vm/eachDef.lua
index a00b61bb..b120c8a5 100644
--- a/script/vm/eachDef.lua
+++ b/script/vm/eachDef.lua
@@ -31,7 +31,7 @@ end
function vm.getDefs(source, deep)
deep = deep or -999
- if searcher.isGlobal(source) then
+ if false and searcher.isGlobal(source) then
local key = searcher.getKeyName(source)
if not key then
return {}
diff --git a/script/vm/eachRef.lua b/script/vm/eachRef.lua
index 0556a6a3..7ac523ee 100644
--- a/script/vm/eachRef.lua
+++ b/script/vm/eachRef.lua
@@ -30,7 +30,7 @@ end
function vm.getRefs(source, deep)
deep = deep or -999
- if searcher.isGlobal(source) then
+ if false and searcher.isGlobal(source) then
local key = searcher.getKeyName(source)
if not key then
return {}