summaryrefslogtreecommitdiff
path: root/server-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-10-10 19:14:04 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-10-10 19:14:04 +0800
commitf8ae93feb7be0faba81ce72795b74bc4ec4dfe03 (patch)
tree23bf0f8347f200b2274bbec3f77a1e76960a5500 /server-beta
parentf233384eba3ef7324333e12d0ba0b7e6bfc2eddb (diff)
downloadlua-language-server-f8ae93feb7be0faba81ce72795b74bc4ec4dfe03.zip
支持 __index
Diffstat (limited to 'server-beta')
-rw-r--r--server-beta/src/core/boolean.lua4
-rw-r--r--server-beta/src/core/engineer.lua18
-rw-r--r--server-beta/src/core/field.lua11
-rw-r--r--server-beta/src/core/getglobal.lua12
-rw-r--r--server-beta/src/core/getlocal.lua4
-rw-r--r--server-beta/src/core/local.lua28
-rw-r--r--server-beta/src/core/number.lua4
-rw-r--r--server-beta/src/core/select.lua21
-rw-r--r--server-beta/src/core/string.lua4
-rw-r--r--server-beta/src/core/table.lua4
-rw-r--r--server-beta/test.lua1
11 files changed, 106 insertions, 5 deletions
diff --git a/server-beta/src/core/boolean.lua b/server-beta/src/core/boolean.lua
index 15aef9e5..07a67c51 100644
--- a/server-beta/src/core/boolean.lua
+++ b/server-beta/src/core/boolean.lua
@@ -36,4 +36,8 @@ function m:ref(source, callback)
end)
end
+function m:value(source, callback)
+ callback(source)
+end
+
return m
diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/core/engineer.lua
index 28741ecb..bfb9c98b 100644
--- a/server-beta/src/core/engineer.lua
+++ b/server-beta/src/core/engineer.lua
@@ -21,6 +21,7 @@ mt['number'] = require 'core.number'
mt['boolean'] = require 'core.boolean'
mt['string'] = require 'core.string'
mt['table'] = require 'core.table'
+mt['select'] = require 'core.select'
function mt:getSpecialName(source)
if source.type == 'getglobal' then
@@ -102,6 +103,19 @@ function mt:eachDef(source, callback)
f(self, source, callback)
end
+function mt:eachValue(source, callback)
+ local tp = source.type
+ local d = mt[tp]
+ if not d then
+ return
+ end
+ local f = d.value
+ if not f then
+ return
+ end
+ f(self, source, callback)
+end
+
function mt:childDef(source, callback)
local tp = source.type
if tp == 'setfield' then
@@ -141,6 +155,10 @@ function mt:callArgOf(source)
return tableUnpack(args)
end
+function mt:callReturnOf(source)
+
+end
+
return function (ast)
local self = setmetatable({
step = 0,
diff --git a/server-beta/src/core/field.lua b/server-beta/src/core/field.lua
index cd50d713..72845956 100644
--- a/server-beta/src/core/field.lua
+++ b/server-beta/src/core/field.lua
@@ -10,6 +10,8 @@ function m:def(source, callback)
callback(src, mode)
end
end)
+ -- 尝试 __index
+
end
function m:ref(source, callback)
@@ -22,4 +24,13 @@ function m:ref(source, callback)
end)
end
+function m:value(source, callback)
+ local parent = source.parent
+ if parent.type == 'setfield' then
+ if parent.value then
+ self:eachValue(parent.value, callback)
+ end
+ end
+end
+
return m
diff --git a/server-beta/src/core/getglobal.lua b/server-beta/src/core/getglobal.lua
index 46a9e7d2..6853d631 100644
--- a/server-beta/src/core/getglobal.lua
+++ b/server-beta/src/core/getglobal.lua
@@ -40,6 +40,18 @@ function m:ref(source, callback)
if guide.getKeyName(parent) == key then
self:childRef(parent, callback)
end
+ elseif name == 'rawset' then
+ local t, k = self:callArgOf(src.parent)
+ if self:getSpecialName(t) == '_G'
+ and guide.getKeyName(k) == key then
+ callback(src.parent, 'set')
+ end
+ elseif name == 'rawget' then
+ local t, k = self:callArgOf(src.parent)
+ if self:getSpecialName(t) == '_G'
+ and guide.getKeyName(k) == key then
+ callback(src.parent, 'get')
+ end
end
end)
end
diff --git a/server-beta/src/core/getlocal.lua b/server-beta/src/core/getlocal.lua
index a719714d..b84f3b83 100644
--- a/server-beta/src/core/getlocal.lua
+++ b/server-beta/src/core/getlocal.lua
@@ -12,4 +12,8 @@ function m:field(source, key, callback)
self:eachField(source.loc, key, callback)
end
+function m:value(source, callback)
+ self:eachValue(source.loc, callback)
+end
+
return m
diff --git a/server-beta/src/core/local.lua b/server-beta/src/core/local.lua
index b9f12259..a68b41f8 100644
--- a/server-beta/src/core/local.lua
+++ b/server-beta/src/core/local.lua
@@ -41,15 +41,15 @@ function m:ref(source, callback)
end
function m:field(source, key, callback)
- if source.ref then
- for _, ref in ipairs(source.ref) do
+ local refs = source.ref
+ if refs then
+ for i = 1, #refs do
+ local ref = refs[i]
if ref.type == 'getlocal' then
local parent = ref.parent
if key == guide.getKeyName(parent) then
self:childRef(parent, callback)
end
- elseif ref.type == 'setlocal' then
- self:eachField(ref.value, key, callback)
elseif ref.type == 'getglobal' then
-- _ENV.XXX
if key == guide.getKeyName(ref) then
@@ -68,8 +68,26 @@ function m:field(source, key, callback)
local node = method.node
self:eachField(node, key, callback)
end
+ self:eachValue(source, function (src)
+ if src ~= source then
+ self:eachField(src, key, callback)
+ end
+ end)
+end
+
+function m:value(source, callback)
+ callback(source)
+ local refs = source.ref
+ if refs then
+ for i = 1, #refs do
+ local ref = refs[i]
+ if ref.type == 'setlocal' then
+ self:eachValue(ref.value, callback)
+ end
+ end
+ end
if source.value then
- self:eachField(source.value, key, callback)
+ self:eachValue(source.value, callback)
end
end
diff --git a/server-beta/src/core/number.lua b/server-beta/src/core/number.lua
index 15aef9e5..07a67c51 100644
--- a/server-beta/src/core/number.lua
+++ b/server-beta/src/core/number.lua
@@ -36,4 +36,8 @@ function m:ref(source, callback)
end)
end
+function m:value(source, callback)
+ callback(source)
+end
+
return m
diff --git a/server-beta/src/core/select.lua b/server-beta/src/core/select.lua
new file mode 100644
index 00000000..e6e5ffe1
--- /dev/null
+++ b/server-beta/src/core/select.lua
@@ -0,0 +1,21 @@
+local guide = require 'parser.guide'
+
+local m = {}
+
+function m:value(source, callback)
+ local vararg = source.vararg
+ if vararg.type == 'call' then
+ local func = vararg.node
+ if self:getSpecialName(func) == 'setmetatable' then
+ local t, mt = self:callArgOf(vararg)
+ self:eachValue(t, callback)
+ self:eachField(mt, 's|__index', function (src, mode)
+ if mode == 'set' then
+ self:eachValue(src, callback)
+ end
+ end)
+ end
+ end
+end
+
+return m
diff --git a/server-beta/src/core/string.lua b/server-beta/src/core/string.lua
index 15aef9e5..07a67c51 100644
--- a/server-beta/src/core/string.lua
+++ b/server-beta/src/core/string.lua
@@ -36,4 +36,8 @@ function m:ref(source, callback)
end)
end
+function m:value(source, callback)
+ callback(source)
+end
+
return m
diff --git a/server-beta/src/core/table.lua b/server-beta/src/core/table.lua
index 36f4f887..3c3ae0f3 100644
--- a/server-beta/src/core/table.lua
+++ b/server-beta/src/core/table.lua
@@ -15,4 +15,8 @@ function m:field(source, key, callback)
end
end
+function m:value(source, callback)
+ callback(source)
+end
+
return m
diff --git a/server-beta/test.lua b/server-beta/test.lua
index c65a43d9..cf871599 100644
--- a/server-beta/test.lua
+++ b/server-beta/test.lua
@@ -28,6 +28,7 @@ local function loadAllLibs()
end
local function main()
+ debug.setcstacklimit(1000)
local function test(name)
local clock = os.clock()
print(('测试[%s]...'):format(name))