summaryrefslogtreecommitdiff
path: root/script-beta/core/hover/class.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-28 20:05:10 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-28 20:05:10 +0800
commit1038520109da932c2e648da6ffa9bf25d36944b8 (patch)
tree697c69fce6f50825f8c13d9cdbad8b8f5726c6e3 /script-beta/core/hover/class.lua
parent37bc70744d6642b964ba513bab99b8f0091483f7 (diff)
downloadlua-language-server-1038520109da932c2e648da6ffa9bf25d36944b8.zip
支持class
Diffstat (limited to 'script-beta/core/hover/class.lua')
-rw-r--r--script-beta/core/hover/class.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/script-beta/core/hover/class.lua b/script-beta/core/hover/class.lua
new file mode 100644
index 00000000..6d28ee8a
--- /dev/null
+++ b/script-beta/core/hover/class.lua
@@ -0,0 +1,27 @@
+local vm = require 'vm'
+
+local function getClass(source, deep)
+ if deep > 3 then
+ return nil
+ end
+ local class = vm.eachField(source, function (info)
+ if info.key == 's|type' or info.key == 's|__name' or info.key == 's|name' then
+ if info.value and info.value.type == 'string' then
+ return info.value[1]
+ end
+ end
+ end)
+ if class then
+ return class
+ end
+ return vm.eachMeta(source, function (meta)
+ local cl = getClass(meta, deep + 1)
+ if cl then
+ return cl
+ end
+ end)
+end
+
+return function (source)
+ return getClass(source, 1)
+end