diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-11-30 16:16:12 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-11-30 16:16:12 +0800 |
commit | 931ec71a8cdf6e5c6f80cf3d90a1c3be494028ee (patch) | |
tree | 0790db5ff7915c8f36dcb94151f2125775d3ee2e /server/src/matcher/definition.lua | |
parent | b46ef6acee507e9e111c08d0506e48dd29cb40b8 (diff) | |
download | lua-language-server-931ec71a8cdf6e5c6f80cf3d90a1c3be494028ee.zip |
支持表里的值
Diffstat (limited to 'server/src/matcher/definition.lua')
-rw-r--r-- | server/src/matcher/definition.lua | 62 |
1 files changed, 54 insertions, 8 deletions
diff --git a/server/src/matcher/definition.lua b/server/src/matcher/definition.lua index 163d4eea..2a816cf0 100644 --- a/server/src/matcher/definition.lua +++ b/server/src/matcher/definition.lua @@ -154,13 +154,16 @@ function mt:searchUnary(exp) end function mt:searchTable(exp) + local tbl = {} for _, obj in ipairs(exp) do if obj.type == 'pair' then - self:searchExp(obj[2]) + local res = self:searchExp(obj[2]) + self:markField(tbl, obj[1], res) else self:searchExp(obj) end end + return tbl end function mt:searchExp(exp) @@ -182,8 +185,9 @@ function mt:searchExp(exp) elseif tp == 'function' then self:searchFunction(exp) elseif tp == 'table' then - self:searchTable(exp) + return self:searchTable(exp) end + return nil end function mt:searchReturn(action) @@ -192,6 +196,21 @@ function mt:searchReturn(action) end end +function mt:addChild(var, child) + if not var or not child then + return + end + for str, info in pairs(child) do + local obj, grandson = info[1], info[2] + local child_var = self:addField(var, str, obj) + self:addVarInfo(child_var, { + type = 'set', + source = obj, + }) + self:addChild(child_var, grandson) + end +end + function mt:markSimple(simple) local name = simple[1] local var = self:getVar(name[1], name) @@ -228,7 +247,22 @@ function mt:markSimple(simple) end end -function mt:markSet(simple) +function mt:markField(parent, obj, child) + local tp = obj.type + if tp == 'name' then + if not obj.index then + parent[obj[1]] = {obj, child} + end + else + if obj.index then + if obj.type == 'string' or obj.type == 'number' or obj.type == 'boolean' then + parent[obj[1]] = {obj, child} + end + end + end +end + +function mt:markSet(simple, child) if simple.type == 'name' then local var = self:getVar(simple[1], simple) self:addVarInfo(var, { @@ -236,18 +270,20 @@ function mt:markSet(simple) source = simple, }) self:checkVar(var, simple) + self:addChild(var, child) else self:searchSimple(simple) self:markSimple(simple) end end -function mt:markLocal(name) +function mt:markLocal(name, child) if name.type == 'name' then local str = name[1] -- 创建一个局部变量 local var = self:createLocal(str, name) self:checkVar(var, name) + self:addChild(var, child) elseif name.type == '...' then self.env.dots = name elseif name.type == ':' then @@ -272,24 +308,34 @@ end function mt:markSets(action) local keys = action[1] local values = action[2] + local results = {} -- 要先计算赋值 + local i = 0 self:forList(values, function (value) - self:searchExp(value) + i = i + 1 + results[i] = self:searchExp(value) end) + local i = 0 self:forList(keys, function (key) - self:markSet(key) + i = i + 1 + self:markSet(key, results[i]) end) end function mt:markLocals(action) local keys = action[1] local values = action[2] + local results = {} -- 要先计算赋值 + local i = 0 self:forList(values, function (value) - self:searchExp(value) + i = i + 1 + results[i] = self:searchExp(value) end) + local i = 0 self:forList(keys, function (key) - self:markLocal(key) + i = i + 1 + self:markLocal(key, results[i]) end) end |