summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-02-26 18:01:51 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-02-26 18:01:51 +0800
commit6de46624564d9bdf3d9c0f7614e5e5e399816ca6 (patch)
tree9f32043f4b962af38022e8d01a4afc4a87b8ea48
parent26d4be116440f38edc62927cf04603a6c1a7d17b (diff)
downloadlua-language-server-6de46624564d9bdf3d9c0f7614e5e5e399816ca6.zip
还是得共享info
-rw-r--r--server/src/vm/value.lua21
-rw-r--r--server/src/vm/vm.lua14
2 files changed, 21 insertions, 14 deletions
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index 1079c206..0b163c3f 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -73,6 +73,7 @@ end
function mt:setChild(index, value)
self:rawSet(index, value)
+ return value
end
function mt:getChild(index, mark)
@@ -166,9 +167,15 @@ function mt:mergeValue(value)
self._child[k] = v
end
end
- for _, info in ipairs(value) do
- self[#self+1] = info
+ if value._info then
+ if not self._info then
+ self._info = {}
+ end
+ for _, info in ipairs(value._info) do
+ self._info[#self._info+1] = info
+ end
end
+ value._info = self._info
if value._meta then
self._meta = value._meta
end
@@ -184,14 +191,20 @@ function mt:addInfo(tp, source)
if source and not source.start then
error('Miss start: ' .. table.dump(source))
end
- self[#self+1] = {
+ if not self._info then
+ self._info = {}
+ end
+ self._info[#self._info+1] = {
type = tp,
source = source or getDefaultSource(),
}
end
function mt:eachInfo(callback)
- for _, info in ipairs(self) do
+ if not self._info then
+ return
+ end
+ for _, info in ipairs(self._info) do
local res = callback(info)
if res ~= nil then
return res
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index 7301f1e0..9eb46c58 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -355,14 +355,8 @@ function mt:getName(name, source)
end
local ENV = self:loadLocal('_ENV')
local ENVValue = ENV:getValue()
- local global = ENVValue:getChild(name)
- if global then
- return global
- else
- global = self:createValue('any')
- ENVValue:setChild(name, global)
- return global
- end
+ local global = ENVValue:getChild(name) or ENVValue:setChild(name, createValue('any', source))
+ return global
end
function mt:setName(name, source, value)
@@ -470,10 +464,10 @@ function mt:getSimple(simple, max)
elseif source.type == 'index' then
local child = source[1]
local index = self:getIndex(child)
- value = value:getChild(index) or createValue('any')
+ value = value:getChild(index) or value:setChild(index, createValue('any', source))
source:bindValue(value, 'get')
elseif source.type == 'name' then
- value = value:getChild(source[1]) or createValue('any')
+ value = value:getChild(source[1]) or value:setChild(source[1], createValue('any', source))
source:bindValue(value, 'get')
elseif source.type == ':' then
object = value