summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server-beta/src/core/definition.lua8
-rw-r--r--server-beta/src/files.lua19
-rw-r--r--server-beta/src/seacher/boolean.lua (renamed from server-beta/src/core/boolean.lua)6
-rw-r--r--server-beta/src/seacher/field.lua (renamed from server-beta/src/core/field.lua)10
-rw-r--r--server-beta/src/seacher/getfield.lua (renamed from server-beta/src/core/getfield.lua)8
-rw-r--r--server-beta/src/seacher/getglobal.lua (renamed from server-beta/src/core/getglobal.lua)10
-rw-r--r--server-beta/src/seacher/getlocal.lua (renamed from server-beta/src/core/getlocal.lua)8
-rw-r--r--server-beta/src/seacher/goto.lua (renamed from server-beta/src/core/goto.lua)2
-rw-r--r--server-beta/src/seacher/index.lua (renamed from server-beta/src/core/index.lua)2
-rw-r--r--server-beta/src/seacher/init.lua (renamed from server-beta/src/core/engineer.lua)109
-rw-r--r--server-beta/src/seacher/label.lua (renamed from server-beta/src/core/label.lua)0
-rw-r--r--server-beta/src/seacher/local.lua (renamed from server-beta/src/core/local.lua)10
-rw-r--r--server-beta/src/seacher/method.lua (renamed from server-beta/src/core/method.lua)8
-rw-r--r--server-beta/src/seacher/methods.lua26
-rw-r--r--server-beta/src/seacher/number.lua (renamed from server-beta/src/core/number.lua)6
-rw-r--r--server-beta/src/seacher/select.lua (renamed from server-beta/src/core/select.lua)2
-rw-r--r--server-beta/src/seacher/setmetatable.lua (renamed from server-beta/src/core/setmetatable.lua)0
-rw-r--r--server-beta/src/seacher/string.lua (renamed from server-beta/src/core/string.lua)6
-rw-r--r--server-beta/src/seacher/table.lua (renamed from server-beta/src/core/table.lua)4
-rw-r--r--server-beta/src/seacher/tablefield.lua (renamed from server-beta/src/core/tablefield.lua)4
20 files changed, 153 insertions, 95 deletions
diff --git a/server-beta/src/core/definition.lua b/server-beta/src/core/definition.lua
index 039effd5..01f2586b 100644
--- a/server-beta/src/core/definition.lua
+++ b/server-beta/src/core/definition.lua
@@ -1,5 +1,4 @@
local guide = require 'parser.guide'
-local engineer = require 'core.engineer'
local workspace = require 'workspace'
local files = require 'files'
@@ -56,12 +55,11 @@ end
return function (uri, offset)
local results = {}
- local ast = files.getAst(uri)
- if not ast then
+ local searcher = files.getSearcher(uri)
+ if not searcher then
return nil
end
- local searcher = engineer(ast, uri)
- guide.eachSourceContain(ast.ast, offset, function (source)
+ guide.eachSourceContain(searcher.ast, offset, function (source)
checkRequire(searcher, source, offset, function (uri)
results[#results+1] = {
uri = uri,
diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua
index 1873637d..67a13aa8 100644
--- a/server-beta/src/files.lua
+++ b/server-beta/src/files.lua
@@ -131,12 +131,31 @@ function m.getLines(uri)
uri = uri:lower()
end
local file = m.fileMap[uri]
+ if not file then
+ return nil
+ end
if not file.lines then
file.lines = parser:lines(file.text)
end
return file.lines
end
+--- 获取搜索器
+function m.getSearcher(uri)
+ if platform.OS == 'Windows' then
+ uri = uri:lower()
+ end
+ local file = m.fileMap[uri]
+ if not file then
+ return nil
+ end
+ if not file.searcher then
+ local seacher = require 'seacher'
+ file.searcher = seacher.create(uri)
+ end
+ return file.searcher
+end
+
--- 判断文件名相等
function m.eq(a, b)
if platform.OS == 'Windows' then
diff --git a/server-beta/src/core/boolean.lua b/server-beta/src/seacher/boolean.lua
index 07a67c51..3f36ee59 100644
--- a/server-beta/src/core/boolean.lua
+++ b/server-beta/src/seacher/boolean.lua
@@ -2,7 +2,7 @@ local guide = require 'parser.guide'
local m = {}
-function m:def(source, callback)
+function m:eachDef(source, callback)
local parent = source.parent
if not parent then
return
@@ -19,7 +19,7 @@ function m:def(source, callback)
end)
end
-function m:ref(source, callback)
+function m:eachRef(source, callback)
local parent = source.parent
if not parent then
return
@@ -36,7 +36,7 @@ function m:ref(source, callback)
end)
end
-function m:value(source, callback)
+function m:eachValue(source, callback)
callback(source)
end
diff --git a/server-beta/src/core/field.lua b/server-beta/src/seacher/field.lua
index 12c13632..72e8ab59 100644
--- a/server-beta/src/core/field.lua
+++ b/server-beta/src/seacher/field.lua
@@ -1,9 +1,9 @@
local guide = require 'parser.guide'
-local checkSMT = require 'core.setmetatable'
+local checkSMT = require 'seacher.setmetatable'
local m = {}
-function m:def(source, callback)
+function m:eachDef(source, callback)
local parent = source.parent
local key = guide.getKeyName(source)
self:eachField(parent, key, function (src, mode)
@@ -13,7 +13,7 @@ function m:def(source, callback)
end)
end
-function m:ref(source, callback)
+function m:eachRef(source, callback)
local parent = source.parent
local key = guide.getKeyName(source)
self:eachField(parent, key, function (src, mode)
@@ -23,11 +23,11 @@ function m:ref(source, callback)
end)
end
-function m:field(source, key, callback)
+function m:eachField(source, key, callback)
self:eachField(source.parent, key, callback)
end
-function m:value(source, callback)
+function m:eachValue(source, callback)
self:eachValue(source.parent, callback)
end
diff --git a/server-beta/src/core/getfield.lua b/server-beta/src/seacher/getfield.lua
index fd0c8f33..7b9ac263 100644
--- a/server-beta/src/core/getfield.lua
+++ b/server-beta/src/seacher/getfield.lua
@@ -1,9 +1,9 @@
local guide = require 'parser.guide'
-local checkSMT = require 'core.setmetatable'
+local checkSMT = require 'seacher.setmetatable'
local m = {}
-function m:ref(source, callback)
+function m:eachRef(source, callback)
local node = source.node
if node.type == 'setfield'
or node.type == 'getfield'
@@ -22,7 +22,7 @@ function m:ref(source, callback)
end
end
-function m:field(source, key, callback)
+function m:eachField(source, key, callback)
local used = {}
local found = false
used[source] = true
@@ -57,7 +57,7 @@ function m:field(source, key, callback)
checkSMT(self, key, used, found, callback)
end
-function m:value(source, callback)
+function m:eachValue(source, callback)
if source.value then
self:eachValue(source.value, callback)
end
diff --git a/server-beta/src/core/getglobal.lua b/server-beta/src/seacher/getglobal.lua
index 05429c64..a6bee129 100644
--- a/server-beta/src/core/getglobal.lua
+++ b/server-beta/src/seacher/getglobal.lua
@@ -1,9 +1,9 @@
local guide = require 'parser.guide'
-local checkSMT = require 'core.setmetatable'
+local checkSMT = require 'seacher.setmetatable'
local m = {}
-function m:def(source, callback)
+function m:eachDef(source, callback)
-- _ENV
local key = guide.getKeyName(source)
self:eachField(source.node, key, function (src, mode)
@@ -27,7 +27,7 @@ function m:def(source, callback)
end)
end
-function m:ref(source, callback)
+function m:eachRef(source, callback)
-- _ENV
local key = guide.getKeyName(source)
self:eachField(source.node, key, function (src, mode)
@@ -61,7 +61,7 @@ function m:ref(source, callback)
end)
end
-function m:field(source, key, callback)
+function m:eachField(source, key, callback)
local used = {}
local found = false
used[source] = true
@@ -99,7 +99,7 @@ function m:field(source, key, callback)
checkSMT(self, key, used, found, callback)
end
-function m:value(source, callback)
+function m:eachValue(source, callback)
callback(source)
if source.value then
self:eachValue(source.value, callback)
diff --git a/server-beta/src/core/getlocal.lua b/server-beta/src/seacher/getlocal.lua
index b84f3b83..ca4e58c3 100644
--- a/server-beta/src/core/getlocal.lua
+++ b/server-beta/src/seacher/getlocal.lua
@@ -1,18 +1,18 @@
local m = {}
-function m:def(source, callback)
+function m:eachDef(source, callback)
self:eachDef(source.loc, callback)
end
-function m:ref(source, callback)
+function m:eachRef(source, callback)
self:eachRef(source.loc, callback)
end
-function m:field(source, key, callback)
+function m:eachField(source, key, callback)
self:eachField(source.loc, key, callback)
end
-function m:value(source, callback)
+function m:eachValue(source, callback)
self:eachValue(source.loc, callback)
end
diff --git a/server-beta/src/core/goto.lua b/server-beta/src/seacher/goto.lua
index 4652f8be..36f373d2 100644
--- a/server-beta/src/core/goto.lua
+++ b/server-beta/src/seacher/goto.lua
@@ -2,7 +2,7 @@ local guide = require 'parser.guide'
local m = {}
-function m:def(source, callback)
+function m:eachDef(source, callback)
local name = source[1]
local label = guide.getLabel(source, name)
if label then
diff --git a/server-beta/src/core/index.lua b/server-beta/src/seacher/index.lua
index 812fca78..f96c2dcf 100644
--- a/server-beta/src/core/index.lua
+++ b/server-beta/src/seacher/index.lua
@@ -1,6 +1,6 @@
local m = {}
-function m:value(source, callback)
+function m:eachValue(source, callback)
local parent = source.parent
if parent.type == 'setindex'
or parent.type == 'tableindex' then
diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/seacher/init.lua
index 8404bee5..5584c83f 100644
--- a/server-beta/src/core/engineer.lua
+++ b/server-beta/src/seacher/init.lua
@@ -1,39 +1,11 @@
-local guide = require 'parser.guide'
-local require = require
-local tableUnpack = table.unpack
-local error = error
-
+local guide = require 'parser.guide'
+local files = require 'files'
+local methods = require 'seacher.methods'
+local tableUnpack = table.unpack
+local error = error
local setmetatable = setmetatable
_ENV = nil
----@class engineer
-local mt = {}
-mt.__index = mt
-mt.type = 'engineer'
-
-mt['local'] = require 'core.local'
-mt['getlocal'] = require 'core.getlocal'
-mt['setlocal'] = mt['getlocal']
-mt['getglobal'] = require 'core.getglobal'
-mt['setglobal'] = mt['getglobal']
-mt['getfield'] = require 'core.getfield'
-mt['setfield'] = mt['getfield']
-mt['tablefield'] = require 'core.tablefield'
-mt['getmethod'] = mt['getfield']
-mt['setmethod'] = mt['getfield']
-mt['getindex'] = mt['getfield']
-mt['setindex'] = mt['getfield']
-mt['field'] = require 'core.field'
-mt['method'] = require 'core.method'
-mt['index'] = require 'core.index'
-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'
-mt['goto'] = require 'core.goto'
-mt['label'] = require 'core.label'
-
local specials = {
['_G'] = true,
['rawset'] = true,
@@ -44,6 +16,12 @@ local specials = {
['loadfile'] = true,
}
+---@class seacher
+local mt = {}
+mt.__index = mt
+mt.__name = 'seacher'
+
+--- 获取特殊对象的名字
function mt:getSpecialName(source)
local spName = self.cache.specialName[source]
if spName ~= nil then
@@ -82,6 +60,8 @@ function mt:getSpecialName(source)
return spName
end
+--- 遍历特殊对象
+---@param callback fun(name:string, source:table)
function mt:eachSpecial(callback)
local cache = self.cache.special
if cache then
@@ -109,6 +89,10 @@ function mt:eachSpecial(callback)
end
end
+--- 遍历元素
+---@param source table
+---@param key string
+---@param callback fun(field:table, mode:string)
function mt:eachField(source, key, callback)
local cache = self.cache.field[source]
if cache and cache[key] then
@@ -118,11 +102,11 @@ function mt:eachField(source, key, callback)
return
end
local tp = source.type
- local d = mt[tp]
+ local d = methods[tp]
if not d then
return
end
- local f = d.field
+ local f = d.eachField
if not f then
return
end
@@ -150,6 +134,9 @@ function mt:eachField(source, key, callback)
self.step = self.step - 1
end
+--- 遍历引用
+---@param source table
+---@param callback fun(def:table, mode:string)
function mt:eachRef(source, callback)
local cache = self.cache.ref[source]
if cache then
@@ -159,11 +146,11 @@ function mt:eachRef(source, callback)
return
end
local tp = source.type
- local d = mt[tp]
+ local d = methods[tp]
if not d then
return
end
- local f = d.ref
+ local f = d.eachRef
if not f then
return
end
@@ -188,6 +175,9 @@ function mt:eachRef(source, callback)
self.step = self.step - 1
end
+--- 遍历定义
+---@param source table
+---@param callback fun(def:table, mode:string)
function mt:eachDef(source, callback)
local cache = self.cache.def[source]
if cache then
@@ -197,11 +187,11 @@ function mt:eachDef(source, callback)
return
end
local tp = source.type
- local d = mt[tp]
+ local d = methods[tp]
if not d then
return
end
- local f = d.def
+ local f = d.eachDef
if not f then
return
end
@@ -226,6 +216,9 @@ function mt:eachDef(source, callback)
self.step = self.step - 1
end
+--- 遍历value
+---@param source table
+---@param callback fun(value:table)
function mt:eachValue(source, callback)
local cache = self.cache.value[source]
if cache then
@@ -235,11 +228,11 @@ function mt:eachValue(source, callback)
return
end
local tp = source.type
- local d = mt[tp]
+ local d = methods[tp]
if not d then
return
end
- local f = d.value
+ local f = d.eachValue
if not f then
return
end
@@ -264,6 +257,10 @@ function mt:eachValue(source, callback)
self.step = self.step - 1
end
+--- 获取函数的参数
+---@param source table
+---@return table arg1
+---@return table arg2
function mt:callArgOf(source)
if not source or source.type ~= 'call' then
return
@@ -275,6 +272,10 @@ function mt:callArgOf(source)
return tableUnpack(args)
end
+--- 获取函数的返回值
+---@param source table
+---@return table return1
+---@return table return2
function mt:callReturnOf(source)
if not source or source.type ~= 'call' then
return
@@ -292,6 +293,11 @@ function mt:callReturnOf(source)
end
end
+--- 获取source的索引,模式与值
+---@param source table
+---@return table field
+---@return string mode
+---@return table value
function mt:childMode(source)
if source.type == 'getfield' then
return source.field, 'get'
@@ -313,11 +319,18 @@ function mt:childMode(source)
return nil, nil
end
-return function (ast, uri)
- local self = setmetatable({
- step = 0,
- ast = ast.ast,
- uri = uri,
+---@class engineer
+local m = {}
+
+--- 新建搜索器
+---@param uri string
+---@return seacher
+function m.create(uri)
+ local ast = files.getAst(uri)
+ local searcher = setmetatable({
+ step = 0,
+ ast = ast.ast,
+ uri = uri,
cache = {
def = {},
ref = {},
@@ -326,5 +339,7 @@ return function (ast, uri)
specialName = {},
},
}, mt)
- return self
+ return searcher
end
+
+return m
diff --git a/server-beta/src/core/label.lua b/server-beta/src/seacher/label.lua
index f05a57e6..f05a57e6 100644
--- a/server-beta/src/core/label.lua
+++ b/server-beta/src/seacher/label.lua
diff --git a/server-beta/src/core/local.lua b/server-beta/src/seacher/local.lua
index 6c9488f4..302d49da 100644
--- a/server-beta/src/core/local.lua
+++ b/server-beta/src/seacher/local.lua
@@ -1,9 +1,9 @@
local guide = require 'parser.guide'
-local checkSMT = require 'core.setmetatable'
+local checkSMT = require 'seacher.setmetatable'
local m = {}
-function m:def(source, callback)
+function m:eachDef(source, callback)
if source.tag ~= 'self' then
callback(source, 'local')
end
@@ -21,7 +21,7 @@ function m:def(source, callback)
end
end
-function m:ref(source, callback)
+function m:eachRef(source, callback)
if source.tag ~= 'self' then
callback(source, 'local')
end
@@ -41,7 +41,7 @@ function m:ref(source, callback)
end
end
-function m:field(source, key, callback)
+function m:eachField(source, key, callback)
local used = {}
used[source] = true
local found = false
@@ -99,7 +99,7 @@ function m:field(source, key, callback)
checkSMT(self, key, used, found, callback)
end
-function m:value(source, callback)
+function m:eachValue(source, callback)
callback(source)
local refs = source.ref
if refs then
diff --git a/server-beta/src/core/method.lua b/server-beta/src/seacher/method.lua
index a5005587..52c00358 100644
--- a/server-beta/src/core/method.lua
+++ b/server-beta/src/seacher/method.lua
@@ -2,7 +2,7 @@ local guide = require 'parser.guide'
local m = {}
-function m:def(source, callback)
+function m:eachDef(source, callback)
local node = source.parent.node
local key = guide.getKeyName(source)
self:eachField(node, key, function (src, mode)
@@ -12,7 +12,7 @@ function m:def(source, callback)
end)
end
-function m:ref(source, callback)
+function m:eachRef(source, callback)
local node = source.parent.node
local key = guide.getKeyName(source)
self:eachField(node, key, function (src, mode)
@@ -22,11 +22,11 @@ function m:ref(source, callback)
end)
end
-function m:field(source, key, callback)
+function m:eachField(source, key, callback)
self:eachField(source.parent, key, callback)
end
-function m:value(source, callback)
+function m:eachValue(source, callback)
self:eachValue(source.parent, callback)
end
diff --git a/server-beta/src/seacher/methods.lua b/server-beta/src/seacher/methods.lua
new file mode 100644
index 00000000..a23350bf
--- /dev/null
+++ b/server-beta/src/seacher/methods.lua
@@ -0,0 +1,26 @@
+local methods = {}
+
+methods['local'] = require 'seacher.local'
+methods['getlocal'] = require 'seacher.getlocal'
+methods['setlocal'] = methods['getlocal']
+methods['getglobal'] = require 'seacher.getglobal'
+methods['setglobal'] = methods['getglobal']
+methods['getfield'] = require 'seacher.getfield'
+methods['setfield'] = methods['getfield']
+methods['tablefield'] = require 'seacher.tablefield'
+methods['getmethod'] = methods['getfield']
+methods['setmethod'] = methods['getfield']
+methods['getindex'] = methods['getfield']
+methods['setindex'] = methods['getfield']
+methods['field'] = require 'seacher.field'
+methods['method'] = require 'seacher.method'
+methods['index'] = require 'seacher.index'
+methods['number'] = require 'seacher.number'
+methods['boolean'] = require 'seacher.boolean'
+methods['string'] = require 'seacher.string'
+methods['table'] = require 'seacher.table'
+methods['select'] = require 'seacher.select'
+methods['goto'] = require 'seacher.goto'
+methods['label'] = require 'seacher.label'
+
+return methods
diff --git a/server-beta/src/core/number.lua b/server-beta/src/seacher/number.lua
index 07a67c51..3f36ee59 100644
--- a/server-beta/src/core/number.lua
+++ b/server-beta/src/seacher/number.lua
@@ -2,7 +2,7 @@ local guide = require 'parser.guide'
local m = {}
-function m:def(source, callback)
+function m:eachDef(source, callback)
local parent = source.parent
if not parent then
return
@@ -19,7 +19,7 @@ function m:def(source, callback)
end)
end
-function m:ref(source, callback)
+function m:eachRef(source, callback)
local parent = source.parent
if not parent then
return
@@ -36,7 +36,7 @@ function m:ref(source, callback)
end)
end
-function m:value(source, callback)
+function m:eachValue(source, callback)
callback(source)
end
diff --git a/server-beta/src/core/select.lua b/server-beta/src/seacher/select.lua
index e6e5ffe1..bbdf1234 100644
--- a/server-beta/src/core/select.lua
+++ b/server-beta/src/seacher/select.lua
@@ -2,7 +2,7 @@ local guide = require 'parser.guide'
local m = {}
-function m:value(source, callback)
+function m:eachValue(source, callback)
local vararg = source.vararg
if vararg.type == 'call' then
local func = vararg.node
diff --git a/server-beta/src/core/setmetatable.lua b/server-beta/src/seacher/setmetatable.lua
index 978d165c..978d165c 100644
--- a/server-beta/src/core/setmetatable.lua
+++ b/server-beta/src/seacher/setmetatable.lua
diff --git a/server-beta/src/core/string.lua b/server-beta/src/seacher/string.lua
index 07a67c51..3f36ee59 100644
--- a/server-beta/src/core/string.lua
+++ b/server-beta/src/seacher/string.lua
@@ -2,7 +2,7 @@ local guide = require 'parser.guide'
local m = {}
-function m:def(source, callback)
+function m:eachDef(source, callback)
local parent = source.parent
if not parent then
return
@@ -19,7 +19,7 @@ function m:def(source, callback)
end)
end
-function m:ref(source, callback)
+function m:eachRef(source, callback)
local parent = source.parent
if not parent then
return
@@ -36,7 +36,7 @@ function m:ref(source, callback)
end)
end
-function m:value(source, callback)
+function m:eachValue(source, callback)
callback(source)
end
diff --git a/server-beta/src/core/table.lua b/server-beta/src/seacher/table.lua
index 7b7b7a78..851ee791 100644
--- a/server-beta/src/core/table.lua
+++ b/server-beta/src/seacher/table.lua
@@ -2,7 +2,7 @@ local guide = require 'parser.guide'
local m = {}
-function m:field(source, key, callback)
+function m:eachField(source, key, callback)
for i = 1, #source do
local src = source[i]
if key == guide.getKeyName(src) then
@@ -15,7 +15,7 @@ function m:field(source, key, callback)
end
end
-function m:value(source, callback)
+function m:eachValue(source, callback)
callback(source)
end
diff --git a/server-beta/src/core/tablefield.lua b/server-beta/src/seacher/tablefield.lua
index cfc6bace..219828d4 100644
--- a/server-beta/src/core/tablefield.lua
+++ b/server-beta/src/seacher/tablefield.lua
@@ -1,12 +1,12 @@
local m = {}
-function m:field(source, key, callback)
+function m:eachField(source, key, callback)
if source.value then
self:eachField(source.value, key, callback)
end
end
-function m:value(source, callback)
+function m:eachValue(source, callback)
if source.value then
self:eachValue(source.value, callback)
end