summaryrefslogtreecommitdiff
path: root/server/src/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-24 17:34:49 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-24 17:34:49 +0800
commit59bf8e7692711e59a06b1b6bd93778eb73a85ce1 (patch)
treee8ff6dad4f17f17717df46f2882c449f2650c5eb /server/src/core
parentceb30f6413cf1132ab7fb20355aa4f5a61edc7b6 (diff)
downloadlua-language-server-59bf8e7692711e59a06b1b6bd93778eb73a85ce1.zip
addInfo
Diffstat (limited to 'server/src/core')
-rw-r--r--server/src/core/definition.lua8
-rw-r--r--server/src/core/implementation.lua8
-rw-r--r--server/src/core/value.lua29
-rw-r--r--server/src/core/vm.lua16
4 files changed, 44 insertions, 17 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua
index 44f4813a..3507d02b 100644
--- a/server/src/core/definition.lua
+++ b/server/src/core/definition.lua
@@ -29,7 +29,7 @@ end
local function parseResultAcrossUri(positions, vm, result)
-- 跨越文件时,遍历的是值的绑定信息
- for _, info in ipairs(result.value) do
+ result.value:eachInfo(function (info)
if info.type == 'set' and info.source.uri == result.value.uri then
positions[1] = {
info.source.start,
@@ -37,9 +37,9 @@ local function parseResultAcrossUri(positions, vm, result)
info.source.uri,
}
end
- end
+ end)
if #positions == 0 then
- for _, info in ipairs(result.value) do
+ result.value:eachInfo(function (info)
if info.type == 'return' and info.source.uri == result.value.uri then
positions[1] = {
info.source.start,
@@ -47,7 +47,7 @@ local function parseResultAcrossUri(positions, vm, result)
info.source.uri,
}
end
- end
+ end)
end
if #positions == 0 then
positions[1] = {
diff --git a/server/src/core/implementation.lua b/server/src/core/implementation.lua
index d3681652..c0cd0f76 100644
--- a/server/src/core/implementation.lua
+++ b/server/src/core/implementation.lua
@@ -28,7 +28,7 @@ end
local function parseResultAcrossUri(positions, vm, result)
-- 跨越文件时,遍历的是值的绑定信息
- for _, info in ipairs(result.value) do
+ result.value:eachInfo(function (info)
if info.type == 'set' and info.source.uri == result.value.uri then
positions[1] = {
info.source.start,
@@ -36,9 +36,9 @@ local function parseResultAcrossUri(positions, vm, result)
info.source.uri,
}
end
- end
+ end)
if #positions == 0 then
- for _, info in ipairs(result.value) do
+ result.value:eachInfo(function (info)
if info.type == 'return' and info.source.uri == result.value.uri then
positions[1] = {
info.source.start,
@@ -46,7 +46,7 @@ local function parseResultAcrossUri(positions, vm, result)
info.source.uri,
}
end
- end
+ end)
end
if #positions == 0 then
positions[1] = {
diff --git a/server/src/core/value.lua b/server/src/core/value.lua
index 9943d282..f4aed441 100644
--- a/server/src/core/value.lua
+++ b/server/src/core/value.lua
@@ -79,6 +79,35 @@ function mt:eachField(callback)
end
end
+function mt:addInfo(tp, source)
+ if source and not source.start then
+ error('Miss start: ' .. table.dump(source))
+ end
+ if not self._info then
+ self._info = {}
+ end
+ local uri = source and source.uri or ''
+ if not self._info[uri] then
+ self._info[uri] = {}
+ end
+ self._info[uri][#self._info[uri]+1] = {
+ type = tp,
+ source = source or DefaultSource,
+ }
+ return self
+end
+
+function mt:eachInfo(callback)
+ if not self._info then
+ return
+ end
+ for _, infos in pairs(self._info) do
+ for i = 1, #infos do
+ callback(infos[i])
+ end
+ end
+end
+
return function (tp, source, value)
if tp == '...' then
error('Value type cant be ...')
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua
index a4535786..f2d80b4c 100644
--- a/server/src/core/vm.lua
+++ b/server/src/core/vm.lua
@@ -333,7 +333,7 @@ function mt:setValue(var, value, source)
value = value or self:createValue('any', source)
if source and source.start then
self:addInfo(var, 'set', source)
- self:addInfo(value, 'set', source)
+ value:addInfo('set', source)
end
if var.value then
if value.type == 'any' then
@@ -762,11 +762,9 @@ function mt:getLibChild(value, lib, parentType)
local fValue = self:getLibValue(fLib, parentType)
self:setValue(fField, fValue)
end
- if value.child then
- for k, v in pairs(value.child) do
- self.libraryChild[lib][k] = v
- end
- end
+ value:eachField(function (k, v)
+ self.libraryChild[lib][k] = v
+ end)
value.child = self.libraryChild[lib]
end
end
@@ -1205,17 +1203,17 @@ function mt:doReturn(action)
value[1] = self:createValue('any', exp)
end
for x, v in ipairs(value) do
- self:addInfo(v, 'return', exp)
+ v:addInfo('return', exp)
self:setFunctionReturn(self:getCurrentFunction(), i + x - 1, v)
end
break
else
local v = value[1] or self:createValue('nil', exp)
- self:addInfo(v, 'return', exp)
+ v:addInfo('return', exp)
self:setFunctionReturn(self:getCurrentFunction(), i, v)
end
else
- self:addInfo(value, 'return', exp)
+ value:addInfo('return', exp)
self:setFunctionReturn(self:getCurrentFunction(), i, value)
end
end