summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/matcher/hover.lua44
-rw-r--r--server/test/hover/init.lua36
2 files changed, 77 insertions, 3 deletions
diff --git a/server/src/matcher/hover.lua b/server/src/matcher/hover.lua
index 99e09e46..9c06829d 100644
--- a/server/src/matcher/hover.lua
+++ b/server/src/matcher/hover.lua
@@ -348,6 +348,40 @@ local function findClass(result)
return nil
end
+local function unpackTable(result)
+ local child = result.value and result.value.child
+ if not child then
+ return '{}'
+ end
+ local lines = {'{'}
+ for key, field in pairs(child) do
+ local kType = type(key)
+ if kType == 'table' then
+ key = ('[*%s]'):format(key.type)
+ else
+ if kType ~= 'string' then
+ key = ('[%s]'):format(key)
+ end
+ end
+
+ local value = field.value
+ if not value then
+ lines[#lines+1] = (' %s: %s,'):format(key, 'any')
+ goto CONTINUE
+ end
+
+ local vType = type(value.value)
+ if vType == 'boolean' or vType == 'integer' or vType == 'number' or vType == 'string' then
+ lines[#lines+1] = (' %s: %s = %q,'):format(key, value.type, value.value)
+ else
+ lines[#lines+1] = (' %s: %s,'):format(key, value.type)
+ end
+ ::CONTINUE::
+ end
+ lines[#lines+1] = '}'
+ return table.concat(lines, '\r\n')
+end
+
local function getValueHover(name, valueType, result, source, lib)
if not lib then
local class = findClass(result)
@@ -377,10 +411,14 @@ local function getValueHover(name, valueType, result, source, lib)
end
local text
- if value == nil then
- text = ('%s %s: %s'):format(tp, name, valueType)
+ if valueType == 'table' then
+ text = ('%s %s: %s'):format(tp, name, unpackTable(result))
else
- text = ('%s %s: %s = %s'):format(tp, name, valueType, value)
+ if value == nil then
+ text = ('%s %s: %s'):format(tp, name, valueType)
+ else
+ text = ('%s %s: %s = %s'):format(tp, name, valueType, value)
+ end
end
return {
label = text,
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index ceaca791..17913039 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -257,3 +257,39 @@ TEST [[
(<?'xxx'?>):sub()
]]
(nil)
+
+TEST [[
+local <?t?> = {
+ a = 1,
+ b = 2,
+ c = 3,
+}
+]]
+[[
+local t: {
+ a: number = 1,
+ b: number = 2,
+ c: number = 3,
+}
+]]
+
+TEST [[
+local <?t?> = {
+ a = 1,
+ [1] = 2,
+ [true] = 3,
+ [5.5] = 4,
+ [{}] = 5,
+ [function () end] = 6,
+}
+]]
+[[
+local t: {
+ a: number = 1,
+ [1]: number = 2,
+ [true]: number = 3,
+ [5.5]: number = 4,
+ [*table]: number = 5,
+ [*function]: number = 6,
+}
+]]