summaryrefslogtreecommitdiff
path: root/script-beta/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-28 19:52:31 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-28 19:52:31 +0800
commit37bc70744d6642b964ba513bab99b8f0091483f7 (patch)
tree0e6896d97c10952c2020fb1834b5276049c75b13 /script-beta/core
parent2125c831411ad865c93434fca7d9c929231c7031 (diff)
downloadlua-language-server-37bc70744d6642b964ba513bab99b8f0091483f7.zip
eachMeta
Diffstat (limited to 'script-beta/core')
-rw-r--r--script-beta/core/hover/label.lua10
-rw-r--r--script-beta/core/hover/name.lua51
2 files changed, 44 insertions, 17 deletions
diff --git a/script-beta/core/hover/label.lua b/script-beta/core/hover/label.lua
index a424e453..774ca231 100644
--- a/script-beta/core/hover/label.lua
+++ b/script-beta/core/hover/label.lua
@@ -51,8 +51,14 @@ local function isGlobalField(source)
if source.type == 'setfield'
or source.type == 'getfield'
or source.type == 'setmethod'
- or source.type == 'getmethod'
- or source.type == 'tablefield' then
+ or source.type == 'getmethod' then
+ local node = source.node
+ if node.type == 'setglobal'
+ or node.type == 'getglobal' then
+ return true
+ end
+ return isGlobalField(node)
+ elseif source.type == 'tablefield' then
local parent = source.parent
if parent.type == 'setglobal'
or parent.type == 'getglobal' then
diff --git a/script-beta/core/hover/name.lua b/script-beta/core/hover/name.lua
index a22a8b5a..7fe5b194 100644
--- a/script-beta/core/hover/name.lua
+++ b/script-beta/core/hover/name.lua
@@ -1,36 +1,55 @@
local guide = require 'parser.guide'
local vm = require 'vm'
-local function asLocal(source)
- return guide.getName(source)
-end
-
-local function asMethod(source)
- local class = vm.eachField(source.node, function (info)
+local function getClass(source, deep)
+ if deep and 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 and (deep + 1) or 1)
+ if cl then
+ return cl
+ end
+ end)
+end
+
+local function asLocal(source)
+ local class = getClass(source)
+ if class then
+ return ('%s: %s'):format(guide.getName(source), class)
+ else
+ return guide.getName(source)
+ end
+end
+
+local function asMethod(source)
+ local class = getClass(source.node)
local node = class or guide.getName(source.node) or '?'
local method = guide.getName(source)
return ('%s:%s'):format(node, method)
end
local function asField(source)
- local class = vm.eachField(source.node, 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)
+ local class = getClass(source.node)
local node = class or guide.getName(source.node) or '?'
local method = guide.getName(source)
return ('%s.%s'):format(node, method)
end
+local function asTableField(source)
+ return guide.getName(source.field)
+end
+
local function asGlobal(source)
return guide.getName(source)
end
@@ -50,10 +69,12 @@ local function buildName(source)
return asMethod(source) or ''
end
if source.type == 'setfield'
- or source.tyoe == 'getfield'
- or source.type == 'tablefield' then
+ or source.tyoe == 'getfield' then
return asField(source) or ''
end
+ if source.type == 'tablefield' then
+ return asTableField(source) or ''
+ end
local parent = source.parent
if parent then
return buildName(parent)