diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-24 21:16:16 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-24 21:16:16 +0800 |
commit | 669e20ef2cdfa8d7763f7e7bcd405986e665e526 (patch) | |
tree | 391a0ec38ffc144de1538590e3e190349f9f5582 /server/src/vm | |
parent | 6daad9f42b8c3003a538a0667e5242536aa95eac (diff) | |
download | lua-language-server-669e20ef2cdfa8d7763f7e7bcd405986e665e526.zip |
更新emmyParam
Diffstat (limited to 'server/src/vm')
-rw-r--r-- | server/src/vm/emmy.lua | 27 | ||||
-rw-r--r-- | server/src/vm/function.lua | 26 | ||||
-rw-r--r-- | server/src/vm/value.lua | 7 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 1 |
4 files changed, 60 insertions, 1 deletions
diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua index a2a38553..5406aab1 100644 --- a/server/src/vm/emmy.lua +++ b/server/src/vm/emmy.lua @@ -2,6 +2,7 @@ local mt = require 'vm.manager' function mt:clearEmmy() self._emmy = nil + self._emmyParams = nil end function mt:doEmmy(action) @@ -13,6 +14,7 @@ function mt:doEmmy(action) elseif tp == 'emmyAlias' then self:doEmmyAlias(action) elseif tp == 'emmyParam' then + self:doEmmyParam(action) elseif tp == 'emmyReturn' then elseif tp == 'emmyField' then elseif tp == 'emmyGeneric' then @@ -33,6 +35,19 @@ function mt:getEmmy() return emmy end +function mt:addEmmyParam(param) + if not self._emmyParams then + self._emmyParams = {} + end + self._emmyParams[#self._emmyParams+1] = param +end + +function mt:getEmmyParams() + local params = self._emmyParams + self._emmyParams = nil + return params +end + function mt:doEmmyClass(action) ---@type emmyMgr local emmyMgr = self.emmyMgr @@ -83,6 +98,18 @@ function mt:doEmmyAlias(action) end end +function mt:doEmmyParam(action) + ---@type emmyMgr + local emmyMgr = self.emmyMgr + self:instantSource(action) + self:instantSource(action[1]) + local type = self:doEmmyType(action[2]) + local param = emmyMgr:addParam(action, type) + action:set('emmy.param', param) + self._emmy = nil + self:addEmmyParam(param) +end + function mt:doEmmyIncomplete(action) self:instantSource(action) end diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua index 7df9c3ea..dff5952d 100644 --- a/server/src/vm/function.lua +++ b/server/src/vm/function.lua @@ -275,13 +275,33 @@ function mt:setArgs(values) end end +function mt:findEmmyParamByName(name) + local params = self._emmyParams + if not params then + return nil + end + for i = #params, 1, -1 do + local param = params[i] + if param:getName() == name then + return param + end + end + return nil +end + function mt:createArg(vm, arg) vm:instantSource(arg) arg:set('arg', true) if arg.type == 'name' then - local loc = localMgr.create(arg[1], arg, valueMgr.create('nil', arg)) + local emmyParam = self:findEmmyParamByName(arg[1]) + local value = valueMgr.create('nil', arg) + if emmyParam then + value:setEmmy(emmyParam:bindType()) + end + local loc = localMgr.create(arg[1], arg, value) self:saveUpvalue(arg[1], loc) self.args[#self.args+1] = loc + elseif arg.type == '...' then self._dots = createMulti() end @@ -360,6 +380,10 @@ function mt:markGlobal() end end +function mt:setEmmyParams(params) + self._emmyParams = params +end + local function create(source) if not source then error('Function need source') diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index 8a0b0861..9f9b6b7c 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -289,6 +289,13 @@ function mt:mergeType(value) if not value then return end + if self._emmy and not value._emmy then + value._emmy = self._emmy + return + elseif not self._emmy and value._emmy then + self._emmy = value._emmy + return + end if value._type then for tp, rate in pairs(value._type) do self:setType(tp, rate) diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index a6d5f9ea..b37ff153 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -1063,6 +1063,7 @@ end function mt:createFunction(source) local value = self:createValue('function', source) local func = functionMgr.create(source) + func:setEmmyParams(self:getEmmyParams()) value:setFunction(func) value:setType('function', 1.0) if source:getUri() == self.uri then |