summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server-beta/src/core/definition.lua2
-rw-r--r--server-beta/src/core/engineer.lua46
-rw-r--r--server-beta/src/core/getglobal.lua8
3 files changed, 43 insertions, 13 deletions
diff --git a/server-beta/src/core/definition.lua b/server-beta/src/core/definition.lua
index 8b8d0b8e..4d1d1288 100644
--- a/server-beta/src/core/definition.lua
+++ b/server-beta/src/core/definition.lua
@@ -5,7 +5,7 @@ return function (ast, text, offset)
local results = {}
guide.eachSourceContain(ast.ast, offset, function (source)
local searcher = engineer(ast)
- searcher:eachDef(source, function (src, mode)
+ searcher:eachDef(source, function (src)
results[#results+1] = {
uri = ast.uri,
source = source,
diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/core/engineer.lua
index 24a83151..28741ecb 100644
--- a/server-beta/src/core/engineer.lua
+++ b/server-beta/src/core/engineer.lua
@@ -1,5 +1,6 @@
-local guide = require 'parser.guide'
-local require = require
+local guide = require 'parser.guide'
+local require = require
+local tableUnpack = table.unpack
local setmetatable = setmetatable
@@ -22,15 +23,27 @@ mt['string'] = require 'core.string'
mt['table'] = require 'core.table'
function mt:getSpecialName(source)
- local node = source.node
- if node.tag ~= '_ENV' then
- return nil
- end
- local name = guide.getKeyName(source)
- if name:sub(1, 2) ~= 's|' then
+ if source.type == 'getglobal' then
+ local node = source.node
+ if node.tag ~= '_ENV' then
+ return
+ end
+ local name = guide.getKeyName(source)
+ if name:sub(1, 2) ~= 's|' then
+ return nil
+ end
+ return name:sub(3)
+ elseif source.type == 'local' then
+ if source.tag == '_ENV' then
+ return '_G'
+ end
return nil
+ elseif source.type == 'getlocal' then
+ local loc = source.loc
+ if loc.tag == '_ENV' then
+ return '_G'
+ end
end
- return name:sub(3)
end
function mt:eachSpecial(callback)
@@ -94,7 +107,7 @@ function mt:childDef(source, callback)
if tp == 'setfield' then
callback(source.field, 'set')
elseif tp == 'setmethod' then
- callback(source.field, 'set')
+ callback(source.method, 'set')
elseif tp == 'setindex' then
callback(source.index, 'set')
end
@@ -105,7 +118,7 @@ function mt:childRef(source, callback)
if tp == 'setfield' then
callback(source.field, 'set')
elseif tp == 'setmethod' then
- callback(source.field, 'set')
+ callback(source.method, 'set')
elseif tp == 'setindex' then
callback(source.index, 'set')
elseif tp == 'getfield' then
@@ -117,6 +130,17 @@ function mt:childRef(source, callback)
end
end
+function mt:callArgOf(source)
+ if not source or source.type ~= 'call' then
+ return
+ end
+ local args = source.args
+ if not args then
+ return
+ end
+ return tableUnpack(args)
+end
+
return function (ast)
local self = setmetatable({
step = 0,
diff --git a/server-beta/src/core/getglobal.lua b/server-beta/src/core/getglobal.lua
index 5cac5bdd..46a9e7d2 100644
--- a/server-beta/src/core/getglobal.lua
+++ b/server-beta/src/core/getglobal.lua
@@ -16,6 +16,12 @@ function m:def(source, callback)
if guide.getKeyName(parent) == key then
self:childDef(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
end
end)
end
@@ -44,7 +50,7 @@ function m:field(source, key, callback)
if mode == 'get' then
local parent = src.parent
if key == guide.getKeyName(parent) then
- self:childRef(parent)
+ self:childRef(parent, callback)
end
end
end)