summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/core/hover_name.lua80
-rw-r--r--server/test/hover/init.lua9
2 files changed, 51 insertions, 38 deletions
diff --git a/server/src/core/hover_name.lua b/server/src/core/hover_name.lua
index d8e7b043..d8afe2fc 100644
--- a/server/src/core/hover_name.lua
+++ b/server/src/core/hover_name.lua
@@ -1,49 +1,53 @@
-
return function (result, source)
local func = result.value
- local declarat = func.declarat or source
- if declarat then
- local key
- if declarat.type == 'name' then
- key = declarat[1]
- elseif declarat.type == 'string' then
- key = ('%q'):format(declarat[1])
- elseif declarat.type == 'number' or declarat.type == 'boolean' then
- key = tostring(declarat[1])
- elseif func.type == 'function' then
- key = ''
- elseif type(result.key) == 'string' then
- key = result.key
- else
- key = ''
- end
+ local declarat
+ if func.type == 'function' then
+ declarat = func.declarat or source
+ else
+ declarat = source
+ end
+ if not declarat then
+ return result.key or ''
+ end
+ local key
+ if declarat.type == 'name' then
+ key = declarat[1]
+ elseif declarat.type == 'string' then
+ key = ('%q'):format(declarat[1])
+ elseif declarat.type == 'number' or declarat.type == 'boolean' then
+ key = tostring(declarat[1])
+ elseif func.type == 'function' then
+ key = ''
+ elseif type(result.key) == 'string' then
+ key = result.key
+ else
+ key = ''
+ end
- local parentName = declarat.parentName
+ local parentName = declarat.parentName
- if not parentName then
- return key or ''
- end
+ if not parentName then
+ return key or ''
+ end
- if parentName == '?' then
- local parentType = result.parentValue and result.parentValue.type
- if parentType == 'table' then
- else
- parentName = '*' .. parentType
- end
- end
- if source.object then
- return parentName .. ':' .. key
+ if parentName == '?' then
+ local parentType = result.parentValue and result.parentValue.type
+ if parentType == 'table' then
else
- if parentName then
- if declarat.index then
- return parentName .. '[' .. key .. ']'
- else
- return parentName .. '.' .. key
- end
+ parentName = '*' .. parentType
+ end
+ end
+ if source.object then
+ return parentName .. ':' .. key
+ else
+ if parentName then
+ if declarat.index then
+ return parentName .. '[' .. key .. ']'
else
- return key
+ return parentName .. '.' .. key
end
+ else
+ return key
end
end
- return result.key or ''
end
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index 01c571d8..159264db 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -293,3 +293,12 @@ local t: {
[*function]: number = 6,
}
]]
+
+TEST[[
+local x = 1
+local y = x
+print(<?y?>)
+]]
+[[
+local y: number = 1
+]]