From 36404de31bff1228ce1a785883918491db814676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 1 Mar 2019 16:39:52 +0800 Subject: =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/core/definition.lua | 19 +++++++++++++++++++ server/src/vm/label.lua | 28 ++++++++++++++++++++++++++++ server/src/vm/source.lua | 4 +++- server/src/vm/vm.lua | 23 +++++++++++++++-------- 4 files changed, 65 insertions(+), 9 deletions(-) (limited to 'server') diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua index 6685f00d..fddd8744 100644 --- a/server/src/core/definition.lua +++ b/server/src/core/definition.lua @@ -176,6 +176,22 @@ local function parseValueSimily(vm, source, lsp) return positions end +local function parseLabel(vm, label, lsp) + local positions = {} + label:eachInfo(function (info) + if info.type == 'set' then + positions[#positions+1] = { + info.source.start, + info.source.finish, + } + end + end) + if #positions == 0 then + return nil + end + return positions +end + return function (vm, source, lsp) if not source then return nil @@ -187,4 +203,7 @@ return function (vm, source, lsp) return parseValue(vm, source:bindValue(), lsp) or parseValueSimily(vm, source, lsp) end + if source:bindLabel() then + return parseLabel(vm, source:bindLabel(), lsp) + end end diff --git a/server/src/vm/label.lua b/server/src/vm/label.lua index f8f8eb81..b82e98e8 100644 --- a/server/src/vm/label.lua +++ b/server/src/vm/label.lua @@ -1,3 +1,11 @@ +local function getDefaultSource() + return { + start = 0, + finish = 0, + uri = '', + } +end + local mt = {} mt.__index = mt mt.type = 'label' @@ -6,6 +14,26 @@ function mt:getName() return self.name end +function mt:addInfo(tp, source) + if source and not source.start then + error('Miss start: ' .. table.dump(source)) + end + self[#self+1] = { + type = tp, + source = source or getDefaultSource(), + } +end + +function mt:eachInfo(callback) + for _, info in ipairs(self) do + local res = callback(info) + if res ~= nil then + return res + end + end + return nil +end + return function (name, source) local self = setmetatable({ name = name, diff --git a/server/src/vm/source.lua b/server/src/vm/source.lua index a4839c69..5406298b 100644 --- a/server/src/vm/source.lua +++ b/server/src/vm/source.lua @@ -10,9 +10,11 @@ function mt:bindLocal(loc) end end -function mt:bindLabel(label) +function mt:bindLabel(label, action) if label then self._bindLabel = label + self._action = action + label:addInfo(action, self) else return self._bindLabel end diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 3db7900f..eeb08b76 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -688,10 +688,15 @@ end function mt:doLabel(source) local name = source[1] - self:createLabel(name, source) + local label = self:loadLabel(name) + if label then + self:bindLabel(source, label, 'set') + else + label = self:createLabel(name, source, 'set') + end end -function mt:createLabel(name, source) +function mt:createLabel(name, source, action) local label = self:bindLabel(source) if label then self:saveLabel(label) @@ -700,15 +705,17 @@ function mt:createLabel(name, source) label = createLabel(name, source) self:saveLabel(label) - self:bindLabel(source, label) + self:bindLabel(source, label, action) return label end function mt:doGoTo(source) local name = source[1] local label = self:loadLabel(name) - if not label then - label = self:createLabel(name, source) + if label then + self:bindLabel(source, label, 'get') + else + label = self:createLabel(name, source, 'get') end end @@ -1008,7 +1015,7 @@ function mt:saveLabel(label) end function mt:loadLabel(name) - return self.currentFunction:loadLocal(name) + return self.currentFunction:loadLabel(name) end function mt:loadDots(expect) @@ -1038,10 +1045,10 @@ function mt:bindLocal(source, loc) end end -function mt:bindLabel(source, label) +function mt:bindLabel(source, label, action) self:instantSource(source) if label then - source:bindLabel(label) + source:bindLabel(label, action) else return source:bindLabel() end -- cgit v1.2.3