summaryrefslogtreecommitdiff
path: root/server/src/matcher/definition.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-03 20:29:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-03 20:29:02 +0800
commit1a78d51e0580bfb19d07353bc7228bad37639839 (patch)
tree3646032cec4d2f1e02813461cca0031535f5a832 /server/src/matcher/definition.lua
parentab8fe19a04e3ee945401b0de0c4c62050801f1b3 (diff)
downloadlua-language-server-1a78d51e0580bfb19d07353bc7228bad37639839.zip
换个方法实现metatable
Diffstat (limited to 'server/src/matcher/definition.lua')
-rw-r--r--server/src/matcher/definition.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/server/src/matcher/definition.lua b/server/src/matcher/definition.lua
index 41556745..794788e8 100644
--- a/server/src/matcher/definition.lua
+++ b/server/src/matcher/definition.lua
@@ -37,6 +37,26 @@ local function findResult(results, pos)
return nil
end
+local function tryMeta(var)
+ local keys = {}
+ repeat
+ if var.childs.meta then
+ local metavar = var.childs.meta
+ for i = #keys, 1, -1 do
+ local key = keys[i]
+ metavar = metavar.childs[key]
+ if not metavar then
+ return nil
+ end
+ end
+ return metavar
+ end
+ keys[#keys+1] = var.key
+ var = var.parent
+ until not var
+ return nil
+end
+
local function parseResult(result)
local positions = {}
local tp = result.type
@@ -54,6 +74,14 @@ local function parseResult(result)
positions[#positions+1] = {info.source.start, info.source.finish}
end
end
+ local metavar = tryMeta(var)
+ if metavar then
+ for _, info in ipairs(metavar) do
+ if info.type == 'set' then
+ positions[#positions+1] = {info.source.start, info.source.finish}
+ end
+ end
+ end
else
error('unknow var.type:' .. var.type)
end