diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-10 11:27:31 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-10 11:27:31 +0800 |
commit | fdc9a81f6f220a9fab4087a6a4d3eb7c346498e6 (patch) | |
tree | 0e936062e747005da62e25f0866f7c0819c90d7b /server | |
parent | be6e0ee6d31d79005691b982c02e7699a7ae3762 (diff) | |
download | lua-language-server-fdc9a81f6f220a9fab4087a6a4d3eb7c346498e6.zip |
函数和表
Diffstat (limited to 'server')
-rw-r--r-- | server/src/matcher/compile.lua | 44 | ||||
-rw-r--r-- | server/src/matcher/type_inference.lua | 7 | ||||
-rw-r--r-- | server/test/type_inference/init.lua | 39 |
3 files changed, 80 insertions, 10 deletions
diff --git a/server/src/matcher/compile.lua b/server/src/matcher/compile.lua index c6ccedfe..de9f914b 100644 --- a/server/src/matcher/compile.lua +++ b/server/src/matcher/compile.lua @@ -253,6 +253,7 @@ end function mt:searchTable(exp) local tbl = { type = 'table', + valuetype = 'table', childs = {}, } for _, obj in ipairs(exp) do @@ -314,7 +315,7 @@ function mt:searchExp(exp) elseif tp == '...' then self:checkDots(exp) elseif tp == 'function' then - self:searchFunction(exp) + return self:searchFunction(exp) elseif tp == 'table' then return self:searchTable(exp) end @@ -338,11 +339,11 @@ function mt:setValue(var, value) end if not group[var] then var.group = group - group[var] = group + group[var] = var end if not group[value] then value.group = group - group[value] = group + group[value] = value end if value.childs then var.childs = value.childs @@ -412,9 +413,11 @@ function mt:markSet(simple, value) local var = self:getVar(simple[1], simple) self:addInfo(var, 'set', simple) self:setValue(var, value) + return var else local var = self:markSimple(simple) self:setValue(var, value) + return var end end @@ -424,13 +427,16 @@ function mt:markLocal(name, value) -- 创建一个局部变量 local var = self:createLocal(str, name) self:setValue(var, value) + return var elseif name.type == '...' then local dots = self:createDots() self:addInfo(dots, 'local', name) self.env.dots = dots + return dots elseif name.type == ':' then -- 创建一个局部变量 - self:createLocal('self', name) + local var = self:createLocal('self', name) + return var end end @@ -537,29 +543,47 @@ function mt:searchRepeat(action) end function mt:searchFunction(func) + local obj = { + type = 'function', + valuetype = 'function', + args = {}, + actions = {}, + } self.env:push() self.env:cut 'dots' self.env.label = {} if func.name then - self:markSet(func.name) + obj.name = self:markSet(func.name, obj) end self:forList(func.arg, function (arg) - self:markLocal(arg) + obj.args[#obj.args+1] = self:markLocal(arg) end) - self:searchActions(func) + for _, action in ipairs(func) do + obj.actions[#obj.actions+1] = self:searchAction(action) + end self.env:pop() + return obj end function mt:searchLocalFunction(func) + local obj = { + type = 'function', + valuetype = 'function', + args = {}, + actions = {}, + } if func.name then - self:markLocal(func.name) + obj.name = self:markLocal(func.name, obj) end self.env:push() self:forList(func.arg, function (arg) - self:markLocal(arg) + obj.args[#obj.args+1] = self:markLocal(arg) end) - self:searchActions(func) + for _, action in ipairs(func) do + obj.actions[#obj.actions+1] = self:searchAction(action) + end self.env:pop() + return obj end function mt:markLabel(label) diff --git a/server/src/matcher/type_inference.lua b/server/src/matcher/type_inference.lua index 59874a7e..e689c482 100644 --- a/server/src/matcher/type_inference.lua +++ b/server/src/matcher/type_inference.lua @@ -24,6 +24,13 @@ function mt:searchVar(var) if self.lock[var] then return end + if not var.group and next(var.childs) then + var.valuetype = 'table' + var.group = { + type = 'table', + } + return + end self.lock[var] = true self:searchGroup(var.group) self.lock[var] = nil diff --git a/server/test/type_inference/init.lua b/server/test/type_inference/init.lua index 913228bb..c4446a51 100644 --- a/server/test/type_inference/init.lua +++ b/server/test/type_inference/init.lua @@ -34,3 +34,42 @@ local <?var?> = true TEST 'number' [[ local <?var?> = 1 ]] + +TEST 'string' [[ +local var = '111' +t.<?x?> = var +]] + +TEST 'string' [[ +local <?var?> +var = '111' +]] + +TEST 'function' [[ +function <?xx?>() +end +]] + +TEST 'function' [[ +local function <?xx?>() +end +]] + +TEST 'function' [[ +local <?xx?> +xx = function () +end +]] + +TEST 'table' [[ +local <?t?> = {} +]] + +TEST 'table' [[ +local <?t?> +t = {} +]] + +TEST 'table' [[ +<?t?>.x = 1 +]] |