diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-08-16 00:25:42 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-08-16 00:25:42 +0800 |
commit | 68ccbc65b09026c1e8246efe46690b3b6091e09c (patch) | |
tree | f4a57589fefc90db92043f03a962667149450df9 /script-beta | |
parent | 51592cb52f944d8b22ce0a7e1ac1a940a4aef735 (diff) | |
download | lua-language-server-68ccbc65b09026c1e8246efe46690b3b6091e09c.zip |
整理代码
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/parser/guide.lua | 93 |
1 files changed, 50 insertions, 43 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index faa77745..9f479f17 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -1439,47 +1439,13 @@ function m.checkSameSimpleAsSetValue(status, ref, start, queue) end end -function m.checkSameSimple(status, simple, data, mode, results, queue) - local ref = data.obj - local start = data.start - local force = data.force - local isCall = data.call - for i = start, #simple do - local sm = simple[i] - if sm ~= '*' and not force and m.getSimpleName(ref) ~= sm then - return - end - force = false - local cmode = mode - if i < #simple then - cmode = 'ref' - end - -- 穿透 self:func 与 mt:func - m.searchSameFieldsCrossMethod(status, ref, i, queue) - -- 穿透赋值 - m.searchSameFieldsInValue(status, ref, i, queue, cmode) - -- 检查形如 a = f() 的分支情况,需要业务层传入 interface.call - m.checkSameSimpleInCall(status, ref, i, queue, mode) - if cmode ~= 'def' then - -- 检查形如 { a = f } 的情况 - m.checkSameSimpleAsTableField(status, ref, i, queue) - -- 检查形如 return m 的情况 - m.checkSameSimpleAsReturn(status, ref, i, queue) - -- 检查形如 a = f 的情况 - m.checkSameSimpleAsSetValue(status, ref, i, queue) - end - if i == #simple then - break - end - -- 检查形如 a = {} 的分支情况 - m.checkSameSimpleInBranch(status, ref, i, queue) - ref = m.getNextRef(ref) - if not ref then +function m.pushResult(status, mode, ref, isCall) + local results = status.results + if mode == 'def' then + if isCall then + results[#results+1] = ref return end - isCall = false - end - if mode == 'def' then if ref.type == 'setglobal' or ref.type == 'setlocal' or ref.type == 'local' then @@ -1497,10 +1463,11 @@ function m.checkSameSimple(status, simple, data, mode, results, queue) results[#results+1] = ref end end + elseif mode == 'ref' then if isCall then results[#results+1] = ref + return end - elseif mode == 'ref' then if ref.type == 'setfield' or ref.type == 'getfield' or ref.type == 'tablefield' then @@ -1526,9 +1493,6 @@ function m.checkSameSimple(status, simple, data, mode, results, queue) results[#results+1] = ref end end - if isCall then - results[#results+1] = ref - end elseif mode == 'field' then if ref.type == 'setfield' or ref.type == 'getfield' @@ -1556,6 +1520,49 @@ function m.checkSameSimple(status, simple, data, mode, results, queue) end end +function m.checkSameSimple(status, simple, data, mode, results, queue) + local ref = data.obj + local start = data.start + local force = data.force + local isCall = data.call + for i = start, #simple do + local sm = simple[i] + if sm ~= '*' and not force and m.getSimpleName(ref) ~= sm then + return + end + force = false + local cmode = mode + if i < #simple then + cmode = 'ref' + end + -- 穿透 self:func 与 mt:func + m.searchSameFieldsCrossMethod(status, ref, i, queue) + -- 穿透赋值 + m.searchSameFieldsInValue(status, ref, i, queue, cmode) + -- 检查形如 a = f() 的分支情况,需要业务层传入 interface.call + m.checkSameSimpleInCall(status, ref, i, queue, mode) + if cmode ~= 'def' then + -- 检查形如 { a = f } 的情况 + m.checkSameSimpleAsTableField(status, ref, i, queue) + -- 检查形如 return m 的情况 + m.checkSameSimpleAsReturn(status, ref, i, queue) + -- 检查形如 a = f 的情况 + m.checkSameSimpleAsSetValue(status, ref, i, queue) + end + if i == #simple then + break + end + -- 检查形如 a = {} 的分支情况 + m.checkSameSimpleInBranch(status, ref, i, queue) + ref = m.getNextRef(ref) + if not ref then + return + end + isCall = false + end + m.pushResult(status, mode, ref, isCall) +end + function m.searchSameFields(status, simple, mode) local first = simple.first local fref = first and first.ref |