summaryrefslogtreecommitdiff
path: root/server-beta/src/searcher-old/getfield.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-10-23 17:31:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-10-23 17:31:02 +0800
commit4248038716c6c2281a10af9c0a3f04c6468b1946 (patch)
tree79361f8df2cf46ab99843e84bba175ea60147da2 /server-beta/src/searcher-old/getfield.lua
parent68541432820dfff4554375c4c424a537943a938d (diff)
downloadlua-language-server-4248038716c6c2281a10af9c0a3f04c6468b1946.zip
准备换一个写法试试
Diffstat (limited to 'server-beta/src/searcher-old/getfield.lua')
-rw-r--r--server-beta/src/searcher-old/getfield.lua77
1 files changed, 77 insertions, 0 deletions
diff --git a/server-beta/src/searcher-old/getfield.lua b/server-beta/src/searcher-old/getfield.lua
new file mode 100644
index 00000000..2fcd2d4b
--- /dev/null
+++ b/server-beta/src/searcher-old/getfield.lua
@@ -0,0 +1,77 @@
+local guide = require 'parser.guide'
+local checkSMT = require 'searcher.setmetatable'
+
+local m = {}
+
+function m:eachRef(source, callback)
+ local node = source.node
+ if node.type == 'setfield'
+ or node.type == 'getfield'
+ or node.type == 'setmethod'
+ or node.type == 'getmethod'
+ or node.type == 'setindex'
+ or node.type == 'getindex' then
+ local key = guide.getKeyName(node)
+ self:eachField(node.node, key, function (info)
+ if info.mode == 'set' or info.mode == 'get' then
+ callback(info)
+ end
+ end)
+ else
+ self:eachRef(node, callback)
+ end
+end
+
+function m:eachField(source, key, callback)
+ local used = {}
+ local found = false
+ used[source] = true
+
+ self:eachRef(source, function (info)
+ local src = info.source
+ used[src] = true
+ local child, mode, value = self:childMode(src)
+ if child then
+ if key == guide.getKeyName(child) then
+ callback {
+ uri = self.uri,
+ source = child,
+ mode = mode,
+ }
+ end
+ if value then
+ info.searcher:eachField(value, key, callback)
+ end
+ return
+ end
+ if src.type == 'getglobal' then
+ local parent = src.parent
+ child, mode = info.searcher:childMode(parent)
+ if child then
+ if key == guide.getKeyName(child) then
+ callback {
+ uri = self.uri,
+ source = child,
+ mode = mode,
+ }
+ end
+ end
+ elseif src.type == 'setglobal' then
+ info.searcher:eachField(src.value, key, callback)
+ else
+ info.searcher:eachField(src, key, callback)
+ end
+ end)
+
+ checkSMT(self, key, used, found, callback)
+end
+
+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
+
+return m