diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-10-23 16:43:19 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-10-23 16:43:19 +0800 |
commit | 68541432820dfff4554375c4c424a537943a938d (patch) | |
tree | dbd34527656fa6133f80baa6088f0d67b55b6e27 /server-beta/src/searcher | |
parent | 373cc0d6b746fef04ca353d05defc7f4d6324faa (diff) | |
download | lua-language-server-68541432820dfff4554375c4c424a537943a938d.zip |
整理代码
Diffstat (limited to 'server-beta/src/searcher')
-rw-r--r-- | server-beta/src/searcher/boolean.lua | 7 | ||||
-rw-r--r-- | server-beta/src/searcher/field.lua | 4 | ||||
-rw-r--r-- | server-beta/src/searcher/getfield.lua | 8 | ||||
-rw-r--r-- | server-beta/src/searcher/getglobal.lua | 16 | ||||
-rw-r--r-- | server-beta/src/searcher/getlocal.lua | 4 | ||||
-rw-r--r-- | server-beta/src/searcher/index.lua | 10 | ||||
-rw-r--r-- | server-beta/src/searcher/init.lua | 39 | ||||
-rw-r--r-- | server-beta/src/searcher/local.lua | 10 | ||||
-rw-r--r-- | server-beta/src/searcher/method.lua | 4 | ||||
-rw-r--r-- | server-beta/src/searcher/number.lua | 7 | ||||
-rw-r--r-- | server-beta/src/searcher/select.lua | 15 | ||||
-rw-r--r-- | server-beta/src/searcher/string.lua | 7 | ||||
-rw-r--r-- | server-beta/src/searcher/table.lua | 7 | ||||
-rw-r--r-- | server-beta/src/searcher/tablefield.lua | 4 |
14 files changed, 105 insertions, 37 deletions
diff --git a/server-beta/src/searcher/boolean.lua b/server-beta/src/searcher/boolean.lua index 782b37ff..f92670e1 100644 --- a/server-beta/src/searcher/boolean.lua +++ b/server-beta/src/searcher/boolean.lua @@ -36,11 +36,8 @@ function m:eachRef(source, callback) end) end -function m:eachValue(source, callback) - callback { - uri = self.uri, - source = source, - } +function m:getValue(source) + return source end return m diff --git a/server-beta/src/searcher/field.lua b/server-beta/src/searcher/field.lua index a9b01d25..c5667b04 100644 --- a/server-beta/src/searcher/field.lua +++ b/server-beta/src/searcher/field.lua @@ -31,4 +31,8 @@ function m:eachValue(source, callback) self:eachValue(source.parent, callback) end +function m:getValue(source) + return self:getValue(source.parent) +end + return m diff --git a/server-beta/src/searcher/getfield.lua b/server-beta/src/searcher/getfield.lua index f3c3df16..2fcd2d4b 100644 --- a/server-beta/src/searcher/getfield.lua +++ b/server-beta/src/searcher/getfield.lua @@ -66,9 +66,11 @@ function m:eachField(source, key, callback) checkSMT(self, key, used, found, callback) end -function m:eachValue(source, callback) - if source.value then - self:eachValue(source.value, callback) +function m:getValue(source) + if source.type == 'setfield' + or source.type == 'setmethod' + or source.type == 'setindex' then + return source.value and self:getValue(source.value) end end diff --git a/server-beta/src/searcher/getglobal.lua b/server-beta/src/searcher/getglobal.lua index c4fd10f1..1295d769 100644 --- a/server-beta/src/searcher/getglobal.lua +++ b/server-beta/src/searcher/getglobal.lua @@ -137,8 +137,20 @@ function m:eachValue(source, callback) source = source, uri = self.uri, } - if source.value then - self:eachValue(source.value, callback) + self:eachDef(source, function (info) + local src = info.source + if src.value then + callback { + source = src.value, + uri = info.uri, + } + end + end) +end + +function m:getValue(source) + if source.type == 'setglobal' then + return source.value and self:getValue(source.value) end end diff --git a/server-beta/src/searcher/getlocal.lua b/server-beta/src/searcher/getlocal.lua index ca4e58c3..4ffc871f 100644 --- a/server-beta/src/searcher/getlocal.lua +++ b/server-beta/src/searcher/getlocal.lua @@ -16,4 +16,8 @@ function m:eachValue(source, callback) self:eachValue(source.loc, callback) end +function m:getValue(source) + return self:getValue(source.loc) +end + return m diff --git a/server-beta/src/searcher/index.lua b/server-beta/src/searcher/index.lua index f96c2dcf..f05a57e6 100644 --- a/server-beta/src/searcher/index.lua +++ b/server-beta/src/searcher/index.lua @@ -1,13 +1,3 @@ local m = {} -function m:eachValue(source, callback) - local parent = source.parent - if parent.type == 'setindex' - or parent.type == 'tableindex' then - if parent.value then - self:eachValue(parent.value, callback) - end - end -end - return m diff --git a/server-beta/src/searcher/init.lua b/server-beta/src/searcher/init.lua index a56d9a22..ae831c58 100644 --- a/server-beta/src/searcher/init.lua +++ b/server-beta/src/searcher/init.lua @@ -275,6 +275,29 @@ function mt:eachValue(source, callback) self.step = self.step - 1 end +--- 获取value +---@param source table +---@return value table +function mt:getValue(source) + local tp = source.type + local d = methods[tp] + if not d then + return + end + local f = d.getValue + if not f then + return + end + if self.step >= 100 then + error('Stack overflow!') + return + end + self.step = self.step + 1 + local value = f(self, source) + self.step = self.step - 1 + return value +end + --- 获取函数的参数 ---@param source table ---@return table arg1 @@ -290,7 +313,7 @@ function mt:callArgOf(source) return tableUnpack(args) end ---- 获取函数的返回值 +--- 获取调用函数的返回值 ---@param source table ---@return table return1 ---@return table return2 @@ -311,6 +334,20 @@ function mt:callReturnOf(source) end end +--- 获取函数定义的返回值 +---@param source table +---@param callback fun(source:table) +function mt:functionReturnOf(source, callback) + if not source or source.type ~= 'function' then + return + end + local returns = guide.getReturns(source) + for i = 1, #returns do + local src = returns[i] + callback() + end +end + --- 获取source的索引,模式与值 ---@param source table ---@return table field diff --git a/server-beta/src/searcher/local.lua b/server-beta/src/searcher/local.lua index 398a9387..0213ee58 100644 --- a/server-beta/src/searcher/local.lua +++ b/server-beta/src/searcher/local.lua @@ -27,6 +27,9 @@ function m:eachDef(source, callback) local node = method.node self:eachDef(node, callback) end + if source.value then + self:eachDef(source.value, callback) + end end function m:eachRef(source, callback) @@ -166,4 +169,11 @@ function m:eachValue(source, callback) end end +function m:getValue(source) + if source.type == 'local' + or source.type == 'setlocal' then + return source.value or source + end +end + return m diff --git a/server-beta/src/searcher/method.lua b/server-beta/src/searcher/method.lua index cc7736a3..c05fba76 100644 --- a/server-beta/src/searcher/method.lua +++ b/server-beta/src/searcher/method.lua @@ -30,4 +30,8 @@ function m:eachValue(source, callback) self:eachValue(source.parent, callback) end +function m:getValue(source) + return self:getValue(source.parent) +end + return m diff --git a/server-beta/src/searcher/number.lua b/server-beta/src/searcher/number.lua index 43f838f6..f92670e1 100644 --- a/server-beta/src/searcher/number.lua +++ b/server-beta/src/searcher/number.lua @@ -36,11 +36,8 @@ function m:eachRef(source, callback) end) end -function m:eachValue(source, callback) - callback { - source = source, - uri = self.uri, - } +function m:getValue(source) + return source end return m diff --git a/server-beta/src/searcher/select.lua b/server-beta/src/searcher/select.lua index 77480dc7..f7da7bfc 100644 --- a/server-beta/src/searcher/select.lua +++ b/server-beta/src/searcher/select.lua @@ -2,11 +2,24 @@ local guide = require 'parser.guide' local m = {} +function m:eachDef(source, callback) + local vararg = source.vararg + if vararg.type == 'call' then + local func = vararg.node + self:eachValue(func, function (info) + self:functionReturnOf(info.source, function () + + end) + end) + end +end + function m:eachValue(source, callback) local vararg = source.vararg if vararg.type == 'call' then local func = vararg.node - if self:getSpecialName(func) == 'setmetatable' then + if self:getSpecialName(func) == 'setmetatable' + and source.index == 1 then local t, mt = self:callArgOf(vararg) self:eachValue(t, callback) self:eachField(mt, 's|__index', function (info) diff --git a/server-beta/src/searcher/string.lua b/server-beta/src/searcher/string.lua index 43f838f6..94907116 100644 --- a/server-beta/src/searcher/string.lua +++ b/server-beta/src/searcher/string.lua @@ -36,11 +36,8 @@ function m:eachRef(source, callback) end) end -function m:eachValue(source, callback) - callback { - source = source, - uri = self.uri, - } +function m:getValue(source, callback) + return source end return m diff --git a/server-beta/src/searcher/table.lua b/server-beta/src/searcher/table.lua index 26c499ed..fa9a064a 100644 --- a/server-beta/src/searcher/table.lua +++ b/server-beta/src/searcher/table.lua @@ -23,11 +23,8 @@ function m:eachField(source, key, callback) end end -function m:eachValue(source, callback) - callback { - source = source, - uri = self.uri, - } +function m:getValue(source) + return source end return m diff --git a/server-beta/src/searcher/tablefield.lua b/server-beta/src/searcher/tablefield.lua index 219828d4..09456029 100644 --- a/server-beta/src/searcher/tablefield.lua +++ b/server-beta/src/searcher/tablefield.lua @@ -12,4 +12,8 @@ function m:eachValue(source, callback) end end +function m:getValue(source) + return source.value and self:getValue(source.value) or source +end + return m |