diff options
-rw-r--r-- | script/core/guide.lua | 154 | ||||
-rw-r--r-- | script/core/linker.lua | 23 | ||||
-rw-r--r-- | test/basic/linker.lua | 18 |
3 files changed, 63 insertions, 132 deletions
diff --git a/script/core/guide.lua b/script/core/guide.lua index e0123987..fe6071bd 100644 --- a/script/core/guide.lua +++ b/script/core/guide.lua @@ -21,145 +21,39 @@ m.isLiteral = guide.isLiteral ---@param status guide.status ---@param mode guide.searchmode ---@param ref parser.guide.object ----@param simple table -function m.pushResult(status, mode, ref, simple) +function m.pushResult(status, mode, ref) local results = status.results if mode == 'def' then - if ref.type == 'setglobal' + if ref.type == 'local' or ref.type == 'setlocal' - or ref.type == 'local' then - results[#results+1] = ref - elseif ref.type == 'setfield' - or ref.type == 'tablefield' then - results[#results+1] = ref - elseif ref.type == 'setmethod' then - results[#results+1] = ref - elseif ref.type == 'setindex' - or ref.type == 'tableindex' then - results[#results+1] = ref - elseif ref.type == 'call' then - if ref.node.special == 'rawset' then - results[#results+1] = ref - end - elseif ref.type == 'function' then - results[#results+1] = ref - elseif ref.type == 'table' then - results[#results+1] = ref - elseif ref.type == 'doc.type.function' - or ref.type == 'doc.class.name' - or ref.type == 'doc.alias.name' - or ref.type == 'doc.field' - or ref.type == 'doc.type.table' - or ref.type == 'doc.type.array' then - results[#results+1] = ref - elseif ref.type == 'doc.type' then - if #ref.enums > 0 or #ref.resumes > 0 then - results[#results+1] = ref - end - end - if ref.parent and ref.parent.type == 'return' then - if m.getParentFunction(ref) ~= m.getParentFunction(simple.node) then - results[#results+1] = ref - end - end - if m.isLiteral(ref) - and ref.parent and ref.parent.type == 'callargs' - and ref ~= simple.node then + or ref.type == 'setglobal' + or ref.type == 'label' + or ref.type == 'setfield' + or ref.type == 'setmethod' + or ref.type == 'setindex' + or ref.type == 'tableindex' + or ref.type == 'tablefield' then results[#results+1] = ref end elseif mode == 'ref' then - if ref.type == 'setfield' + if ref.type == 'local' + or ref.type == 'setlocal' + or ref.type == 'getlocal' + or ref.type == 'setglobal' + or ref.type == 'getglobal' + or ref.type == 'label' + or ref.type == 'goto' + or ref.type == 'setfield' or ref.type == 'getfield' + or ref.type == 'setmethod' + or ref.type == 'getmethod' + or ref.type == 'setindex' + or ref.type == 'getindex' + or ref.type == 'tableindex' or ref.type == 'tablefield' then results[#results+1] = ref - elseif ref.type == 'setmethod' - or ref.type == 'getmethod' then - results[#results+1] = ref - elseif ref.type == 'setindex' - or ref.type == 'getindex' - or ref.type == 'tableindex' then - results[#results+1] = ref - elseif ref.type == 'setglobal' - or ref.type == 'getglobal' - or ref.type == 'local' - or ref.type == 'setlocal' - or ref.type == 'getlocal' then - results[#results+1] = ref - elseif ref.type == 'function' then - results[#results+1] = ref - elseif ref.type == 'table' then - results[#results+1] = ref - elseif ref.type == 'call' then - if ref.node.special == 'rawset' - or ref.node.special == 'rawget' then - results[#results+1] = ref - end - elseif ref.type == 'doc.type.function' - or ref.type == 'doc.class.name' - or ref.type == 'doc.alias.name' - or ref.type == 'doc.field' - or ref.type == 'doc.type.table' - or ref.type == 'doc.type.array' then - results[#results+1] = ref - elseif ref.type == 'doc.type' then - if #ref.enums > 0 or #ref.resumes > 0 then - results[#results+1] = ref - end - end - if ref.parent and ref.parent.type == 'return' then - results[#results+1] = ref - end - if guide.isLiteral(ref) - and ref.parent - and ref.parent.type == 'callargs' - and ref ~= simple.node then - results[#results+1] = ref end elseif mode == 'field' then - if ref.type == 'setfield' - or ref.type == 'getfield' - or ref.type == 'tablefield' then - results[#results+1] = ref - elseif ref.type == 'setmethod' - or ref.type == 'getmethod' then - results[#results+1] = ref - elseif ref.type == 'setindex' - or ref.type == 'tableindex' then - results[#results+1] = ref - elseif ref.type == 'getindex' then - -- do not trust `t[1]` - if ref.index and ref.index.type == 'string' then - results[#results+1] = ref - end - elseif ref.type == 'setglobal' - or ref.type == 'getglobal' then - results[#results+1] = ref - elseif ref.type == 'call' then - if ref.node.special == 'rawset' - or ref.node.special == 'rawget' then - results[#results+1] = ref - end - elseif ref.type == 'doc.field' then - results[#results+1] = ref - end - elseif mode == 'deffield' then - if ref.type == 'setfield' - or ref.type == 'tablefield' then - results[#results+1] = ref - elseif ref.type == 'setmethod' then - results[#results+1] = ref - elseif ref.type == 'setindex' - or ref.type == 'tableindex' then - results[#results+1] = ref - elseif ref.type == 'setglobal' then - results[#results+1] = ref - elseif ref.type == 'call' then - if ref.node.special == 'rawset' then - results[#results+1] = ref - end - elseif ref.type == 'doc.field' then - results[#results+1] = ref - end end end @@ -237,9 +131,9 @@ function m.status(parentStatus, interface, deep) end --- 请求对象的引用 ----@param obj parser.guide.object +---@param obj parser.guide.object ---@param interface table ----@param deep integer +---@param deep integer ---@return parser.guide.object[] ---@return integer function m.requestReference(obj, interface, deep) diff --git a/script/core/linker.lua b/script/core/linker.lua index 6002b22c..14582cc0 100644 --- a/script/core/linker.lua +++ b/script/core/linker.lua @@ -1,6 +1,10 @@ local util = require 'utility' local guide = require 'parser.guide' +---获取语法树单元的key +---@param source parser.guide.object +---@return string? key +---@return parser.guide.object? node local function getKey(source) if source.type == 'local' then return tostring(source.start), nil @@ -23,7 +27,15 @@ local function getKey(source) return ('%q'):format(source.method and source.method[1] or ''), source.node elseif source.type == 'table' then return source.start, nil + elseif source.type == 'label' then + return source.start, nil + elseif source.type == 'goto' then + if source.node then + return source.node.start, nil + end + return nil, nil end + return nil, nil end local function checkGlobal(source) @@ -40,6 +52,10 @@ local function checkLocal(source) or source.type == 'getlocal' then return true end + if source.type == 'label' + or source.type == 'goto' then + return true + end return nil end @@ -67,6 +83,10 @@ local function checkFunctionReturn(source) end local IDList = {} +---获取语法树单元的字符串ID +---@param source parser.guide.object +---@return string? id +---@return parser.guide.object? local function getID(source) if source.type == 'field' or source.type == 'method' then @@ -87,6 +107,9 @@ local function getID(source) end current = node end + if index == 0 then + return nil + end for i = index + 1, #IDList do IDList[i] = nil end diff --git a/test/basic/linker.lua b/test/basic/linker.lua index 0be93e8d..bf52c949 100644 --- a/test/basic/linker.lua +++ b/test/basic/linker.lua @@ -12,7 +12,9 @@ local function getSource(pos) or source.type == 'setglobal' or source.type == 'getglobal' or source.type == 'field' - or source.type == 'method' then + or source.type == 'method' + or source.type == 'label' + or source.type == 'goto' then return source end end) @@ -136,5 +138,17 @@ end } TEST [[ +::<?label?>:: +goto label +]] { + id = '5', + loc = true, +} -]] +TEST [[ +::label:: +goto <?label?> +]] { + id = '3', + loc = true, +} |