summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-25 11:02:06 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-25 11:02:06 +0800
commitf956fc7f9ee8e2c4595b3fa843ebfaa41f97469e (patch)
tree6011233555b333aee34269191ee1053319b856d2 /server/src
parent8860d44ef8b00355f87ccdeb82b143e999ee912e (diff)
downloadlua-language-server-f956fc7f9ee8e2c4595b3fa843ebfaa41f97469e.zip
更新库的支持
Diffstat (limited to 'server/src')
-rw-r--r--server/src/core/value.lua11
-rw-r--r--server/src/core/vm.lua23
2 files changed, 20 insertions, 14 deletions
diff --git a/server/src/core/value.lua b/server/src/core/value.lua
index 1641ea5e..a8b054b5 100644
--- a/server/src/core/value.lua
+++ b/server/src/core/value.lua
@@ -66,6 +66,17 @@ function mt:rawGetField(name, source)
return field
end
+function mt:getChild()
+ if not self._child then
+ self._child = {}
+ end
+ return self._child
+end
+
+function mt:setChild(child)
+ self._child = child
+end
+
function mt:getField(name, source)
local field = self:rawGetField(name, source)
if not field then
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua
index 054e111f..b2e8ff7d 100644
--- a/server/src/core/vm.lua
+++ b/server/src/core/vm.lua
@@ -4,6 +4,8 @@ local createValue = require 'core.value'
local DefaultSource = { start = 0, finish = 0 }
local GlobalValue
+local LibraryValue = {}
+local LibraryChild = {}
-- 根据赋值顺序决定遍历顺序的表
local function orderTable()
@@ -752,26 +754,23 @@ end
function mt:getLibChild(value, lib, parentType)
if lib.child then
- if self.libraryChild[lib] then
- value.child = self.libraryChild[lib]
+ if LibraryChild[lib] then
+ value:setChild(LibraryChild[lib])
return
end
- self.libraryChild[lib] = {}
+ -- 要先声明缓存,以免死循环
+ LibraryChild[lib] = value:getChild()
for fName, fLib in pairs(lib.child) do
local fField = value:createField(fName)
local fValue = self:getLibValue(fLib, parentType)
self:setValue(fField, fValue)
end
- value:eachField(function (k, v)
- self.libraryChild[lib][k] = v
- end)
- value.child = self.libraryChild[lib]
end
end
function mt:getLibValue(lib, parentType, v)
- if self.libraryValue[lib] then
- return self.libraryValue[lib]
+ if LibraryValue[lib] then
+ return LibraryValue[lib]
end
local tp = lib.type
local value
@@ -815,7 +814,7 @@ function mt:getLibValue(lib, parentType, v)
else
value = self:createValue(tp or 'any')
end
- self.libraryValue[lib] = value
+ LibraryValue[lib] = value
value.lib = lib
value.parentType = parentType
@@ -1485,8 +1484,6 @@ local function compile(ast, lsp, uri)
globals= {},
main = nil,
},
- libraryValue = {},
- libraryChild = {},
lsp = lsp,
uri = uri,
}, mt)
@@ -1499,8 +1496,6 @@ local function compile(ast, lsp, uri)
vm.scope = nil
vm.chunk = nil
- vm.libraryValue = nil
- vm.libraryChild = nil
return vm
end