diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-11 20:18:02 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-11 20:18:02 +0800 |
commit | 33bf4c53397253fa3ce643e88fcdd05faf005617 (patch) | |
tree | f56852cfc7fc47fa1e7730d286de3928ec6a58f7 | |
parent | febe2ee50eb8f13063e0e2f04bd40bbf38073a30 (diff) | |
download | lua-language-server-33bf4c53397253fa3ce643e88fcdd05faf005617.zip |
整理代码
-rw-r--r-- | server/src/matcher/definition.lua | 12 | ||||
-rw-r--r-- | server/src/matcher/vm.lua | 21 | ||||
-rw-r--r-- | server/test/main.lua | 2 |
3 files changed, 17 insertions, 18 deletions
diff --git a/server/src/matcher/definition.lua b/server/src/matcher/definition.lua index e8cfe4c0..57e4b237 100644 --- a/server/src/matcher/definition.lua +++ b/server/src/matcher/definition.lua @@ -10,21 +10,11 @@ local function parseResult(result) end end elseif tp == 'field' then - local mark = {} for _, info in ipairs(result.object) do - if info.type == 'set' and not mark[info.source] then - mark[info.source] = true + if info.type == 'set' then positions[#positions+1] = {info.source.start, info.source.finish} end end - if result.object.value then - for _, info in ipairs(result.object.value) do - if info.type == 'set' and not mark[info.source] then - mark[info.source] = true - positions[#positions+1] = {info.source.start, info.source.finish} - end - end - end elseif tp == 'label' then for _, info in ipairs(result.object) do if info.type == 'set' then diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua index f090d502..d84f9062 100644 --- a/server/src/matcher/vm.lua +++ b/server/src/matcher/vm.lua @@ -96,10 +96,6 @@ function mt:mergeValue(a, b, mark) end mark[a] = true mark[b] = true - for i, info in ipairs(a) do - a[i] = nil - b[#b+1] = info - end self:mergeChild(a, b, mark) for k in pairs(a) do a[k] = nil @@ -109,6 +105,20 @@ function mt:mergeValue(a, b, mark) end end +function mt:mergeField(a, b, mark) + if not mark then + mark = {} + end + for i, info in ipairs(a) do + a[i] = nil + b[#b+1] = info + end + for i, v in ipairs(b) do + a[i] = v + end + self:mergeValue(a.value, b.value, mark) +end + function mt:mergeChild(a, b, mark) if not a.child and not b.child then return @@ -122,7 +132,7 @@ function mt:mergeChild(a, b, mark) b.child = nil for k, v in pairs(other) do if child[k] then - self:mergeValue(v.value, child[k].value, mark) + self:mergeField(v, child[k], mark) else child[k] = v end @@ -146,7 +156,6 @@ function mt:setValue(var, value, source) end if source and source.start then self:addInfo(var, 'set', source) - self:addInfo(value, 'set', source) end return value end diff --git a/server/test/main.lua b/server/test/main.lua index c16346c9..c5f57ced 100644 --- a/server/test/main.lua +++ b/server/test/main.lua @@ -27,7 +27,7 @@ local function main() test 'compile' --test 'type_inference' test 'definition' - test 'find_lib' + --test 'find_lib' print('测试完成') end |