summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-01 16:39:52 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-01 16:39:52 +0800
commit36404de31bff1228ce1a785883918491db814676 (patch)
tree92f8f712dbe1c6a8336155ed8781bcf1c9c45d9d /server
parentcaed96510b21d6bdd9e1c4a175be7486c8c8ff5c (diff)
downloadlua-language-server-36404de31bff1228ce1a785883918491db814676.zip
支持标签
Diffstat (limited to 'server')
-rw-r--r--server/src/core/definition.lua19
-rw-r--r--server/src/vm/label.lua28
-rw-r--r--server/src/vm/source.lua4
-rw-r--r--server/src/vm/vm.lua23
4 files changed, 65 insertions, 9 deletions
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