diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-18 20:07:07 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-18 20:07:07 +0800 |
commit | 92e1b16ba3e6749602f2ea2dcb64a73f11653caa (patch) | |
tree | 5feed39fa9ed5536dcfb38766fc58427f68d6348 /server/src | |
parent | 0680944ab40753dede0f3b7150b283db4715f502 (diff) | |
download | lua-language-server-92e1b16ba3e6749602f2ea2dcb64a73f11653caa.zip |
field支持 Emmy.class
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/emmy/manager.lua | 4 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 6 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 3 | ||||
-rw-r--r-- | server/src/vm/emmy.lua | 16 | ||||
-rw-r--r-- | server/src/vm/local.lua | 7 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 65 |
6 files changed, 73 insertions, 28 deletions
diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua index 99b46420..df9094cd 100644 --- a/server/src/emmy/manager.lua +++ b/server/src/emmy/manager.lua @@ -57,10 +57,14 @@ function mt:addClass(source) return list[source.id] end +function mt:createType(source) +end + function mt:remove() end return function () + ---@class emmyMgr local self = setmetatable({ _class = {}, }, mt) diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index 3b397c0d..35118d35 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -629,8 +629,10 @@ local Defs = { end if isField then table[#table+1] = arg - wantField = false - start = arg.finish + 1 + if arg.finish then + wantField = false + start = arg.finish + 1 + end else wantField = true start = arg diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index 6743ed89..97d60402 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -338,7 +338,7 @@ ArgList <- (DOTS / Name / Sp {} COMMA)* Table <- Sp ({} TL TableFields? DirtyTR) -> Table -TableFields <- (TableSep {} / TableField)+ +TableFields <- (Emmy / TableSep {} / TableField)+ TableSep <- COMMA / SEMICOLON TableField <- NewIndex / NewField / Exp NewIndex <- Sp ({} BL DirtyExp DirtyBR NeedAssign DirtyExp) @@ -362,6 +362,7 @@ LabelEnd <- {} -> LabelEnd -- 纯占位,修改了 `relabel.lua` 使重复定义不抛错 Action <- !END . Set <- END +Emmy <- '---@' ]] grammar 'Action' [[ diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua index 6e5c2b13..67c620a8 100644 --- a/server/src/vm/emmy.lua +++ b/server/src/vm/emmy.lua @@ -1,15 +1,29 @@ local mt = require 'vm.manager' +function mt:clearEmmy() + self._emmy = nil +end + +function mt:getEmmy() + local emmy = self._emmy + self._emmy = nil + return emmy +end + function mt:doEmmyClass(action) local emmyMgr = self.emmyMgr self:instantSource(action) local class = emmyMgr:addClass(action) - self.emmy = class + self._emmy = class action:set('emmy.class', class) end function mt:doEmmyType(action) local emmyMgr = self.emmyMgr + self:instantSource(action) + local type = emmyMgr:createType() + self._emmy = type + action:set('emmy.type', type) end function mt:doEmmyIncomplete(action) diff --git a/server/src/vm/local.lua b/server/src/vm/local.lua index e75ed149..d047b106 100644 --- a/server/src/vm/local.lua +++ b/server/src/vm/local.lua @@ -111,6 +111,13 @@ function mt:shadow(old) end group[#group+1] = self self._shadow = group + + if not self:getSource() then + log.debug('not self:getSource()', table.dump(self)) + end + if not old.close then + log.debug('not old.close', table.dump(old)) + end old:close(self:getSource().start - 1) end diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index e2fd6abc..12467f02 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -41,12 +41,14 @@ function mt:buildTable(source) end local n = 0 for index, obj in ipairs(source) do + local emmy = self:getEmmy() if obj.type == 'pair' then local value = self:getFirstInMulti(self:getExp(obj[2])) local key = obj[1] self:instantSource(obj) self:instantSource(key) key:bindValue(value, 'set') + value:setEmmy(emmy) if key.index then local index = self:getIndex(obj) key:set('parent', tbl) @@ -58,6 +60,8 @@ function mt:buildTable(source) tbl:setChild(key[1], value, key) end end + elseif obj.type:sub(1, 4) == 'emmy' then + self:doEmmy(obj) else local value = self:getExp(obj) if value.type == 'multi' then @@ -776,10 +780,11 @@ function mt:doGoTo(source) end end -function mt:setOne(var, value) +function mt:setOne(var, value, emmy) if not value then value = valueMgr.create('nil', self:getDefaultSource()) end + value:setEmmy(emmy) self:instantSource(var) if var.type == 'name' then self:setName(var[1], var, value) @@ -803,6 +808,7 @@ function mt:setOne(var, value) end function mt:doSet(action) + local emmy = self:getEmmy() if not action[2] then return end @@ -822,11 +828,12 @@ function mt:doSet(action) local i = 0 self:forList(vars, function (var) i = i + 1 - self:setOne(var, values[i]) + self:setOne(var, values[i], emmy) end) end function mt:doLocal(action) + local emmy = self:getEmmy() self:instantSource(action) local vars = action[1] local exps = action[2] @@ -849,9 +856,8 @@ function mt:doLocal(action) if values then value = values[i] end - self:createLocal(key[1], key, value) + self:createLocal(key[1], key, value, emmy) end) - self.emmy = nil end function mt:doIf(action) @@ -994,6 +1000,28 @@ function mt:doLocalFunction(action) end end +function mt:doEmmy(action) + local tp = action.type + if tp == 'emmyClass' then + self:doEmmyClass(action) + elseif tp == 'emmyType' then + self:doEmmyType(action) + elseif tp == 'emmyAlias' then + elseif tp == 'emmyParam' then + elseif tp == 'emmyReturn' then + elseif tp == 'emmyField' then + elseif tp == 'emmyGeneric' then + elseif tp == 'emmyVararg' then + elseif tp == 'emmyLanguage' then + elseif tp == 'emmyArrayType' then + elseif tp == 'emmyTableType' then + elseif tp == 'emmyFunctionType' then + elseif tp == 'emmySee' then + elseif tp == 'emmyIncomplete' then + self:doEmmyIncomplete(action) + end +end + function mt:doAction(action) if not action then -- Skip @@ -1008,6 +1036,10 @@ function mt:doAction(action) end end local tp = action.type + if tp:sub(1, 4) == 'emmy' then + self:doEmmy(action) + return + end if tp == 'do' then self:doDo(action) elseif tp == 'break' then @@ -1039,27 +1071,11 @@ function mt:doAction(action) self:doFunction(action) elseif tp == 'localfunction' then self:doLocalFunction(action) - elseif tp == 'emmyClass' then - self:doEmmyClass(action) - elseif tp == 'emmyType' then - self:doEmmyType(action) - elseif tp == 'emmyAlias' then - elseif tp == 'emmyParam' then - elseif tp == 'emmyReturn' then - elseif tp == 'emmyField' then - elseif tp == 'emmyGeneric' then - elseif tp == 'emmyVararg' then - elseif tp == 'emmyLanguage' then - elseif tp == 'emmyArrayType' then - elseif tp == 'emmyTableType' then - elseif tp == 'emmyFunctionType' then - elseif tp == 'emmySee' then - elseif tp == 'emmyIncomplete' then - self:doEmmyIncomplete(action) else self:getExp(action) action:set('as action', true) end + self:clearEmmy() end function mt:doActions(actions) @@ -1161,20 +1177,20 @@ function mt:bindLabel(source, label, action) end end -function mt:createLocal(key, source, value) +function mt:createLocal(key, source, value, emmy) local loc = self:bindLocal(source) if not value then value = self:createValue('nil', source) end if loc then loc:setValue(value) - loc:setEmmy(self.emmy) + loc:setEmmy(emmy) self:saveLocal(key, loc) return loc end loc = localMgr.create(key, source, value) - loc:setEmmy(self.emmy) + loc:setEmmy(emmy) self:saveLocal(key, loc) self:bindLocal(source, loc, 'local') value:addInfo('local', source) @@ -1281,6 +1297,7 @@ return function (ast, lsp, uri) main = nil, env = nil, emmy = nil, + ---@type emmyMgr emmyMgr = lsp and lsp.emmy or emmyMgr(), lsp = lsp, uri = uri or '', |