summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-10-10 11:41:58 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-10-10 11:41:58 +0800
commit51216d347b59e33fcad96400ddae262971ede712 (patch)
tree7274d335ca0ad09d9b5883db316b2a4b7ad20b64
parentd65825e90bc7137f50cafc36ba0972db5e6a55be (diff)
downloadlua-language-server-51216d347b59e33fcad96400ddae262971ede712.zip
更新
-rw-r--r--server-beta/src/core/boolean.lua4
-rw-r--r--server-beta/src/core/definition.lua2
-rw-r--r--server-beta/src/core/engineer.lua60
-rw-r--r--server-beta/src/core/getglobal.lua37
-rw-r--r--server-beta/src/core/getlocal.lua8
-rw-r--r--server-beta/src/core/local.lua23
-rw-r--r--server-beta/src/core/number.lua4
-rw-r--r--server-beta/src/core/string.lua4
8 files changed, 62 insertions, 80 deletions
diff --git a/server-beta/src/core/boolean.lua b/server-beta/src/core/boolean.lua
index acc4436e..c27f6579 100644
--- a/server-beta/src/core/boolean.lua
+++ b/server-beta/src/core/boolean.lua
@@ -1,11 +1,11 @@
local m = {}
function m:def(source, callback)
- self:asindex(source, 'def', callback)
+ self:asIndex(source, 'def', callback)
end
function m:ref(source, callback)
- self:asindex(source, 'ref', callback)
+ self:asIndex(source, 'ref', callback)
end
return m
diff --git a/server-beta/src/core/definition.lua b/server-beta/src/core/definition.lua
index 087ef948..8b8d0b8e 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:eachRef(source, 'def', function (src, mode)
+ searcher:eachDef(source, function (src, mode)
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 76a360cc..efc88828 100644
--- a/server-beta/src/core/engineer.lua
+++ b/server-beta/src/core/engineer.lua
@@ -53,7 +53,7 @@ mt['table'] = require 'core.table'
-- end
--end
-function mt:asindex(source, mode, callback)
+function mt:asIndex(source, mode, callback)
local parent = source.parent
if not parent then
return
@@ -75,55 +75,39 @@ function mt:getSpecial(source)
return name
end
-function mt:search(source, method, mode, callback)
- local f = mt[method]
+function mt:eachField(source, key, callback)
+ local tp = source.type
+ local d = mt[tp]
+ if not d then
+ return
+ end
+ local f = d.field
if not f then
return
end
- f(self, source, mode, callback)
+ f(self, source, key, callback)
end
-function mt:eachField(node, key, mode, callback)
- self:eachRef(node, 'field', function (src)
- if not key or key == guide.getKeyName(src) then
- if mode == 'def' then
- if src.type == 'setfield'
- or src.type == 'tablefield' then
- callback(src.field, 'set')
- elseif src.type == 'setindex'
- or src.type == 'tableindex' then
- callback(src.index, 'set')
- elseif src.type == 'setmethod' then
- callback(src.method, 'set')
- end
- elseif mode == 'ref' then
- if src.type == 'setfield'
- or src.type == 'tablefield' then
- callback(src.field, 'set')
- elseif src.type == 'setindex'
- or src.type == 'tableindex' then
- callback(src.index, 'set')
- elseif src.type == 'setmethod' then
- callback(src.method, 'set')
- elseif src.type == 'getfield' then
- callback(src.field, 'get')
- elseif src.type == 'getindex' then
- callback(src.index, 'get')
- elseif src.type == 'getmethod' then
- callback(src.method, 'get')
- end
- end
- end
- end)
+function mt:eachRef(source, callback)
+ local tp = source.type
+ local d = mt[tp]
+ if not d then
+ return
+ end
+ local f = d.ref
+ if not f then
+ return
+ end
+ f(self, source, callback)
end
-function mt:eachRef(source, mode, callback)
+function mt:eachDef(source, callback)
local tp = source.type
local d = mt[tp]
if not d then
return
end
- local f = d[mode]
+ local f = d.def
if not f then
return
end
diff --git a/server-beta/src/core/getglobal.lua b/server-beta/src/core/getglobal.lua
index ffa35176..6c14cc70 100644
--- a/server-beta/src/core/getglobal.lua
+++ b/server-beta/src/core/getglobal.lua
@@ -1,34 +1,25 @@
+local guide = require 'parser.guide'
+
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
+ -- _ENV
+ local key = guide.getKeyName(source)
+ self:eachField(source.node, key, function (src, mode)
+ if mode == 'set' then
+ callback(src, mode)
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
+ -- _ENV
+ local key = guide.getKeyName(source)
+ self:eachField(source.node, key, function (src, mode)
+ if mode == 'set' or mode == 'get' then
+ callback(src, mode)
end
- end
+ end)
end
function m:field(source, callback)
diff --git a/server-beta/src/core/getlocal.lua b/server-beta/src/core/getlocal.lua
index 89a35c30..a719714d 100644
--- a/server-beta/src/core/getlocal.lua
+++ b/server-beta/src/core/getlocal.lua
@@ -1,15 +1,15 @@
local m = {}
function m:def(source, callback)
- self:search(source.loc, 'local', 'def', callback)
+ self:eachDef(source.loc, callback)
end
function m:ref(source, callback)
- self:search(source.loc, 'local', 'ref', callback)
+ self:eachRef(source.loc, callback)
end
-function m:field(source, callback)
- self:search(source.loc, 'local', 'field', callback)
+function m:field(source, key, callback)
+ self:eachField(source.loc, key, callback)
end
return m
diff --git a/server-beta/src/core/local.lua b/server-beta/src/core/local.lua
index d3a391ad..79b16770 100644
--- a/server-beta/src/core/local.lua
+++ b/server-beta/src/core/local.lua
@@ -38,22 +38,29 @@ function m:ref(source, callback)
end
end
-function m:field(source, callback)
+function m:field(source, key, callback)
if source.ref then
for _, ref in ipairs(source.ref) do
if ref.type == 'getlocal' then
local parent = ref.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)
+ if tp == 'setfield'
+ or tp == 'setmethod'
+ or tp == 'setindex' then
+ callback(parent, 'set')
+ elseif tp == 'getfield'
+ or tp == 'getmethod'
+ or tp == 'getindex' then
+ callback(parent, 'get')
end
elseif ref.type == 'setlocal' then
self:eachRef(ref.value, 'field', callback)
+ elseif ref.type == 'getglobal' then
+ -- _ENV.XXX
+ callback(ref, 'get')
+ elseif ref.type == 'setglobal' then
+ -- _ENV.XXX = XXX
+ callback(ref, 'set')
end
end
end
diff --git a/server-beta/src/core/number.lua b/server-beta/src/core/number.lua
index acc4436e..c27f6579 100644
--- a/server-beta/src/core/number.lua
+++ b/server-beta/src/core/number.lua
@@ -1,11 +1,11 @@
local m = {}
function m:def(source, callback)
- self:asindex(source, 'def', callback)
+ self:asIndex(source, 'def', callback)
end
function m:ref(source, callback)
- self:asindex(source, 'ref', callback)
+ self:asIndex(source, 'ref', callback)
end
return m
diff --git a/server-beta/src/core/string.lua b/server-beta/src/core/string.lua
index acc4436e..c27f6579 100644
--- a/server-beta/src/core/string.lua
+++ b/server-beta/src/core/string.lua
@@ -1,11 +1,11 @@
local m = {}
function m:def(source, callback)
- self:asindex(source, 'def', callback)
+ self:asIndex(source, 'def', callback)
end
function m:ref(source, callback)
- self:asindex(source, 'ref', callback)
+ self:asIndex(source, 'ref', callback)
end
return m