diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-06 17:47:10 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-06 17:47:10 +0800 |
commit | c302f165c2713fa1d3258622fcf4e7eb7ec56aca (patch) | |
tree | a915135a2c09e88e62fb53be25d8da640cf66a7f /script-beta/parser | |
parent | 8c4e91723d8a5efa4b75f6ea9307e54e9eecf667 (diff) | |
download | lua-language-server-c302f165c2713fa1d3258622fcf4e7eb7ec56aca.zip |
整理代码
Diffstat (limited to 'script-beta/parser')
-rw-r--r-- | script-beta/parser/guide.lua | 61 |
1 files changed, 21 insertions, 40 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index db3696ba..43db26fe 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -1115,7 +1115,8 @@ local function buildSimpleList(obj, max) or cur.type == 'getglobal' then list[i] = cur break - elseif cur.type == 'select' then + elseif cur.type == 'select' + or cur.type == 'table' then list[i] = cur break elseif cur.type == 'string' then @@ -1146,7 +1147,8 @@ function m.getSimple(obj, max) or obj.type == 'getglobal' or obj.type == 'tablefield' or obj.type == 'tableindex' - or obj.type == 'select' then + or obj.type == 'select' + or obj.type == 'table' then simpleList = buildSimpleList(obj, max) elseif obj.type == 'field' or obj.type == 'method' then @@ -1287,38 +1289,14 @@ function m.checkSameSimpleInValueOfTable(status, value, start, queue) end end -function m.searchFields(status, obj, key, interface, deep) - if obj.type == 'table' then - local keyName = key and ('s|' .. key) - local results = {} - for i = 1, #obj do - local field = obj[i] - if not keyName or keyName == m.getSimpleName(field) then - results[#results+1] = field - end - end - return results - elseif obj.type == 'library' then - local results = {} - if obj.fields then - for i = 1, #obj.fields do - results[i] = obj.fields[i] - end - end - return results - else - local newStatus = m.status(status, interface) - newStatus.deep = deep - local simple = m.getSimple(obj) - if not simple then - return {} - end - simple[#simple+1] = key and ('s|' .. key) or '*' - m.searchSameFields(newStatus, simple, 'field') - local results = newStatus.results - m.cleanResults(results) - return results +function m.searchFields(status, obj, key) + local simple = m.getSimple(obj) + if not simple then + return end + simple[#simple+1] = key and ('s|' .. key) or '*' + m.searchSameFields(status, simple, 'field') + m.cleanResults(status.results) end function m.getObjectValue(obj) @@ -1356,13 +1334,11 @@ function m.getObjectValue(obj) end function m.checkSameSimpleInValueInMetaTable(status, mt, start, queue) - local indexes = m.searchFields(status, mt, '__index') - if not indexes then - return - end + local newStatus = m.status(status) + m.searchFields(newStatus, mt, '__index') local refsStatus = m.status(status) - for i = 1, #indexes do - local indexValue = m.getObjectValue(indexes[i]) + for i = 1, #newStatus.results do + local indexValue = m.getObjectValue(newStatus.results[i]) if indexValue then m.searchRefs(refsStatus, indexValue, 'ref') end @@ -3644,7 +3620,12 @@ end --- 请求对象的域 function m.requestFields(obj, interface, deep) - return m.searchFields(nil, obj, nil, interface, deep) + local status = m.status(nil, interface) + status.deep = deep + + m.searchFields(status, obj) + + return status.results, status.cache.count end --- 请求对象的类型推测 |