diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-21 04:04:03 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-21 04:04:03 +0800 |
commit | a19f2ee7394c5f5a10342a37497fbd7b7587316c (patch) | |
tree | 26a731c7260ec16e5f293840a6204d1b7370b3f0 /script | |
parent | 0f0ebf434687ac3b085aa0a58d7d87f65f715464 (diff) | |
download | lua-language-server-a19f2ee7394c5f5a10342a37497fbd7b7587316c.zip |
update narrow
Diffstat (limited to 'script')
-rw-r--r-- | script/vm/node.lua | 23 | ||||
-rw-r--r-- | script/vm/runner.lua | 18 |
2 files changed, 36 insertions, 5 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua index a4e22b68..81d9f335 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -123,6 +123,29 @@ function mt:copyTruly() return newNode end +---@param name string +---@return vm.node +function mt:copyWithout(name) + local newNode = vm.createNode() + if self:isOptional() then + newNode:addOptional() + end + for _, c in ipairs(self) do + if (c.type == 'global' and c.cate == 'type' and c.name == name) + or (c.type == name) + or (c.type == 'doc.type.integer' and (name == 'number' or name == 'integer')) + or (c.type == 'doc.type.boolean' and name == 'boolean') + or (c.type == 'doc.type.table' and name == 'table') + or (c.type == 'doc.type.array' and name == 'table') + or (c.type == 'doc.type.function' and name == 'function') then + goto CONTINUE + end + newNode:merge(c) + ::CONTINUE:: + end + return newNode +end + ---@return fun():vm.object function mt:eachObject() local i = 0 diff --git a/script/vm/runner.lua b/script/vm/runner.lua index 2d3309d5..3a315d5c 100644 --- a/script/vm/runner.lua +++ b/script/vm/runner.lua @@ -1,6 +1,7 @@ ---@class vm -local vm = require 'vm.vm' -local guide = require 'parser.guide' +local vm = require 'vm.vm' +local guide = require 'parser.guide' +local globalMgr = require 'vm.global-manager' ---@class vm.runner ---@field loc parser.object @@ -15,11 +16,12 @@ mt.index = 1 ---@field _hasSorted boolean ---@class vm.runner.step ----@field type 'truly' | 'as' | 'object' | 'save' | 'load' +---@field type 'truly' | 'optional' | 'add' | 'remove' | 'object' | 'save' | 'load' ---@field pos integer ---@field node? vm.node ---@field object? parser.object ---@field ref? vm.runner.step +---@field name? string ---@param filter parser.object ---@param pos integer @@ -62,7 +64,8 @@ function mt:_compileBlock(block) local parentBlock = guide.getParentBlock(block) self:_compileBlock(parentBlock) - if block.type == 'ifblock' then + if block.type == 'ifblock' + or block.type == 'elseif' then if block[1] then self:_compileNarrowByFilter(block.filter, block[1].start) end @@ -98,7 +101,12 @@ function mt:launch(callback) for _, step in ipairs(self.steps) do if step.type == 'truly' then node = node:copyTruly() - elseif step.type == 'as' then + elseif step.type == 'optional' then + node = node:copy():addOptional() + elseif step.type == 'add' then + node = node:copy():merge(globalMgr.getGlobal('type', step.name)) + elseif step.type == 'remove' then + node = node:copyWithout(step.name) elseif step.type == 'object' then node = callback(step.object, node) or node elseif step.type == 'save' then |