summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-19 14:28:12 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-19 14:28:12 +0800
commit8662a6394eaaa1f0514578299627f7c4ec9808bf (patch)
tree0b2cbf45d66a670bf66e8ce220393166172cb176 /server
parente1cd2b6866daa172aa19a87019ef38e3daaa702b (diff)
downloadlua-language-server-8662a6394eaaa1f0514578299627f7c4ec9808bf.zip
还是共享一下吧
Diffstat (limited to 'server')
-rw-r--r--server/src/vm/global.lua3
-rw-r--r--server/src/vm/value.lua15
-rw-r--r--server/src/vm/vm.lua36
3 files changed, 22 insertions, 32 deletions
diff --git a/server/src/vm/global.lua b/server/src/vm/global.lua
index 8af38206..a775acd8 100644
--- a/server/src/vm/global.lua
+++ b/server/src/vm/global.lua
@@ -13,8 +13,7 @@ return function (lsp)
global = t._G
for k, v in pairs(t) do
- global:setChild(k, v)
- global:addInfo('set child', sourceMgr.dummy(), k, v)
+ global:setChild(k, v, sourceMgr.dummy())
end
end
if lsp then
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index a1ee897b..838bca15 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -86,15 +86,17 @@ function mt:getType()
return mType or 'any'
end
-function mt:rawSet(index, value)
+function mt:rawSet(index, value, source)
if not self._child then
self._child = {}
end
if self._child[index] then
self._child[index]:mergeValue(value)
+ self._child[index] = value
else
self._child[index] = value
end
+ self:addInfo('set child', source, index, value)
end
function mt:rawGet(index)
@@ -112,9 +114,9 @@ function mt:rawGet(index)
return child
end
-function mt:setChild(index, value)
+function mt:setChild(index, value, source)
self:setType('table', 0.5)
- self:rawSet(index, value)
+ self:rawSet(index, value, source)
return value
end
@@ -254,17 +256,18 @@ function mt:mergeValue(value)
self._child[k] = v
end
end
+ value._child = self._child
for srcId, info in pairs(value._info) do
local src = sourceMgr.list[srcId]
if src then
self._infoCount = self._infoCount + 1
self._info[srcId] = info
- else
- value._info[srcId] = nil
- value._infoCount = value._infoCount - 1
end
end
+ value._info = self._info
+ value._infoCount = self._infoCount
+
if value._meta then
self._meta = value._meta
end
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index 48736fe4..250863a8 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -46,14 +46,12 @@ function mt:buildTable(source)
if key.index then
local index = self:getIndex(obj)
key:set('parent', tbl)
- tbl:addInfo('set child', key, index, value)
- tbl:setChild(index, value)
+ tbl:setChild(index, value, key)
else
if key.type == 'name' then
key:set('parent', tbl)
key:set('table index', true)
- tbl:addInfo('set child', key, key[1], value)
- tbl:setChild(key[1], value)
+ tbl:setChild(key[1], value, key)
end
end
else
@@ -62,19 +60,16 @@ function mt:buildTable(source)
if index == #source then
value:eachValue(function (_, v)
n = n + 1
- tbl:addInfo('set child', obj, n, v)
- tbl:setChild(n, v)
+ tbl:setChild(n, v, obj)
end)
else
n = n + 1
local v = self:getFirstInMulti(value)
- tbl:addInfo('set child', obj, n, v)
- tbl:setChild(n, v)
+ tbl:setChild(n, v, obj)
end
else
n = n + 1
- tbl:addInfo('set child', obj, n, value)
- tbl:setChild(n, value)
+ tbl:setChild(n, value, obj)
end
-- 处理写了一半的 key = value,把name类的数组元素视为哈希键
if obj.type == 'name' then
@@ -388,8 +383,7 @@ function mt:setName(name, source, value)
local ENV = self:loadLocal('_ENV')
local ENVValue = ENV:getValue()
source:bindValue(value, 'set')
- ENVValue:addInfo('set child', source, name, value)
- ENVValue:setChild(name, value)
+ ENVValue:setChild(name, value, source)
source:set('global', true)
source:set('parentValue', ENVValue)
if self.lsp then
@@ -787,13 +781,11 @@ function mt:setOne(var, value)
if key.type == 'index' then
local index = self:getIndex(key)
key[1]:set('parent', parent)
- parent:addInfo('set child', key[1], index, value)
- parent:setChild(index, value)
+ parent:setChild(index, value, key[1])
elseif key.type == 'name' then
local index = key[1]
key:set('parent', parent)
- parent:addInfo('set child', key, index, value)
- parent:setChild(index, value)
+ parent:setChild(index, value, key)
end
key:bindValue(value, 'set')
end
@@ -922,12 +914,10 @@ function mt:doFunction(action)
source:set('object', parent)
if source.type == 'index' then
local index = self:getIndex(source)
- parent:addInfo('set child', source[1], index, value)
- parent:setChild(index, value)
+ parent:setChild(index, value, source[1])
elseif source.type == 'name' then
local index = source[1]
- parent:addInfo('set child', source, index, value)
- parent:setChild(index, value)
+ parent:setChild(index, value, source)
end
source:bindValue(value, 'set')
@@ -949,12 +939,10 @@ function mt:doFunction(action)
self:instantSource(source)
if source.type == 'index' then
local index = self:getIndex(source)
- parent:addInfo('set child', source[1], index, value)
- parent:setChild(index, value)
+ parent:setChild(index, value, source[1])
elseif source.type == 'name' then
local index = source[1]
- parent:addInfo('set child', source, index, value)
- parent:setChild(index, value)
+ parent:setChild(index, value, source)
end
source:bindValue(value, 'set')
end