diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-10-10 11:06:35 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-10-10 11:06:35 +0800 |
commit | d65825e90bc7137f50cafc36ba0972db5e6a55be (patch) | |
tree | e2f43b7ab773d925b7fc2d6158543d78282a2349 /server-beta/src/core/getglobal.lua | |
parent | 43a8d3587622c9fe55996ca22fb13c7d3897a600 (diff) | |
download | lua-language-server-d65825e90bc7137f50cafc36ba0972db5e6a55be.zip |
整理代码
Diffstat (limited to 'server-beta/src/core/getglobal.lua')
-rw-r--r-- | server-beta/src/core/getglobal.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/server-beta/src/core/getglobal.lua b/server-beta/src/core/getglobal.lua new file mode 100644 index 00000000..ffa35176 --- /dev/null +++ b/server-beta/src/core/getglobal.lua @@ -0,0 +1,49 @@ +local m = {} + +function m:def(source, callback) + local env = source.node + if env.ref then + for _, ref in ipairs(env.ref) do + if ref.type == 'setglobal' then + callback(ref, 'set') + elseif ref.type == 'getglobal' then + self:search(ref, 'special', 'def', callback) + elseif ref.type == 'getlocal' then + self:search(ref, '_G', 'def', callback) + end + end + end +end + +function m:ref(source, callback) + local env = source.node + if env.ref then + for _, ref in ipairs(env.ref) do + if ref.type == 'setglobal' then + callback(ref, 'set') + elseif ref.type == 'getglobal' then + callback(ref, 'get') + self:search(ref, 'special', 'ref', callback) + elseif ref.type == 'getlocal' then + self:search(ref, '_G', 'ref', callback) + end + end + end +end + +function m:field(source, callback) + self:search(source, 'getglobal', 'ref', function (src) + local parent = src.parent + local tp = parent.type + if tp == 'setfield' + or tp == 'getfield' + or tp == 'setmethod' + or tp == 'getmethod' + or tp == 'setindex' + or tp == 'getindex' then + callback(parent) + end + end) +end + +return m |