diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-08-12 15:11:57 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-08-12 15:11:57 +0800 |
commit | 75c8974c57b509bf9342e1d03a594ede2380e46c (patch) | |
tree | 703039bb618daa3c9ad98bd4a08807d176161831 /script-beta | |
parent | d97702c96c818e10cad9d82e0ab779c5e16090d1 (diff) | |
download | lua-language-server-75c8974c57b509bf9342e1d03a594ede2380e46c.zip |
更新
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/parser/guide.lua | 13 | ||||
-rw-r--r-- | script-beta/vm/guideInterface.lua | 26 |
2 files changed, 23 insertions, 16 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index d276d822..88c81414 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -1209,7 +1209,7 @@ function m.searchSameFieldsCrossMethod(status, ref, start, queue) end end -function m.checkSameSimpleInCall(status, ref, start, queue) +function m.checkSameSimpleInCall(status, ref, start, queue, mode) if not status.interface.call then return end @@ -1217,7 +1217,7 @@ function m.checkSameSimpleInCall(status, ref, start, queue) if not func then return end - local objs = status.interface.call(func, args, index) + local objs = status.interface.call(func, args, index, mode) if objs then for _, obj in ipairs(objs) do queue[#queue+1] = { @@ -1280,7 +1280,7 @@ function m.checkSameSimple(status, simple, data, mode, results, queue) -- 穿透赋值 m.searchSameFieldsInValue(status, ref, i, queue) -- 检查形如 a = f() 的分支情况,需要业务层传入 interface.call - m.checkSameSimpleInCall(status, ref, i, queue) + m.checkSameSimpleInCall(status, ref, i, queue, mode) if i == #simple then break end @@ -1418,7 +1418,7 @@ function m.searchSameFields(status, simple, mode) start = 1, } if first then - m.checkSameSimpleInCall(status, first, 1, queue) + m.checkSameSimpleInCall(status, first, 1, queue, mode) end end for i = 1, 999 do @@ -1460,6 +1460,9 @@ function m.getCallerCrossFiles(status, main) end function m.searchRefsAsFunctionReturn(status, obj, mode) + if mode == 'def' then + return + end status.results[#status.results+1] = obj -- 搜索所在函数 local currentFunc = m.getParentFunction(obj) @@ -1512,7 +1515,7 @@ function m.searchRefsAsFunctionReturn(status, obj, mode) end -- 搜索调用者的引用 for i = 1, #selects do - m.searchRefs(status, selects[i]) + m.searchRefs(status, selects[i], 'ref') end end diff --git a/script-beta/vm/guideInterface.lua b/script-beta/vm/guideInterface.lua index f598e788..d68e637f 100644 --- a/script-beta/vm/guideInterface.lua +++ b/script-beta/vm/guideInterface.lua @@ -5,7 +5,7 @@ local guide = require 'parser.guide' local m = {} -function m.searchFileReturn(results, ast, index) +function m.searchFileReturn(results, ast, index, mode) local returns = ast.returns if not returns then return @@ -16,18 +16,22 @@ function m.searchFileReturn(results, ast, index) if exp.type == 'table' then vm.mergeResults(results, { exp }) else - local newRes = vm.getRefs(exp) + local newRes + if mode == 'ref' then + newRes = vm.getRefs(exp) + else + newRes = vm.getDefs(exp) + end if #newRes > 0 then vm.mergeResults(results, newRes) - else - vm.mergeResults(results, { exp }) end + vm.mergeResults(results, { exp }) end end end end -function m.require(args, index) +function m.require(args, index, mode) local reqName = args[1] and args[1][1] if not reqName then return nil @@ -39,14 +43,14 @@ function m.require(args, index) if not files.eq(myUri, uri) then local ast = files.getAst(uri) if ast then - m.searchFileReturn(results, ast.ast, index) + m.searchFileReturn(results, ast.ast, index, mode) end end end return results end -function m.dofile(args, index) +function m.dofile(args, index, mode) local reqName = args[1] and args[1][1] if not reqName then return @@ -58,7 +62,7 @@ function m.dofile(args, index) if not files.eq(myUri, uri) then local ast = files.getAst(uri) if ast then - m.searchFileReturn(results, ast.ast, index) + m.searchFileReturn(results, ast.ast, index, mode) end end end @@ -67,16 +71,16 @@ end vm.interface = {} -function vm.interface.call(func, args, index) +function vm.interface.call(func, args, index, mode) local lib = vm.getLibrary(func) if not lib then return nil end if lib.name == 'require' and index == 1 then - return m.require(args, index) + return m.require(args, index, mode) end if lib.name == 'dofile' then - return m.dofile(args, index) + return m.dofile(args, index, mode) end end |