summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-02 10:50:58 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-02 10:50:58 +0800
commit2ca7cad6ead1b12cd899dd7ecac6b8442f499046 (patch)
tree54fc3b37dabec086697620e0d456c279cfbe4c98 /script-beta
parent9af004f6987221ea92f77118c18996d8d43ee672 (diff)
downloadlua-language-server-2ca7cad6ead1b12cd899dd7ecac6b8442f499046.zip
alias 的 hover
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/core/hover/init.lua32
-rw-r--r--script-beta/core/hover/label.lua15
2 files changed, 38 insertions, 9 deletions
diff --git a/script-beta/core/hover/init.lua b/script-beta/core/hover/init.lua
index d0873c98..3876ab58 100644
--- a/script-beta/core/hover/init.lua
+++ b/script-beta/core/hover/init.lua
@@ -79,7 +79,20 @@ local function getHoverAsValue(source)
}
end
+local function getHoverAsDocName(source)
+ local label = getLabel(source)
+ local desc = getDesc(source)
+ return {
+ label = label,
+ source = source,
+ description = desc,
+ }
+end
+
local function getHover(source)
+ if source.type == 'doc.type.name' then
+ return getHoverAsDocName(source)
+ end
vm.setSearchLevel(5)
local isFunction = vm.hasInferType(source, 'function', 'deep')
if isFunction then
@@ -90,15 +103,16 @@ local function getHover(source)
end
local accept = {
- ['local'] = true,
- ['setlocal'] = true,
- ['getlocal'] = true,
- ['setglobal'] = true,
- ['getglobal'] = true,
- ['field'] = true,
- ['method'] = true,
- ['string'] = true,
- ['number'] = true,
+ ['local'] = true,
+ ['setlocal'] = true,
+ ['getlocal'] = true,
+ ['setglobal'] = true,
+ ['getglobal'] = true,
+ ['field'] = true,
+ ['method'] = true,
+ ['string'] = true,
+ ['number'] = true,
+ ['doc.type.name'] = true,
}
local function getHoverByUri(uri, offset)
diff --git a/script-beta/core/hover/label.lua b/script-beta/core/hover/label.lua
index 6ce8ef8e..b96421b1 100644
--- a/script-beta/core/hover/label.lua
+++ b/script-beta/core/hover/label.lua
@@ -29,6 +29,19 @@ local function asDocFunction(source)
return table.concat(lines, '\n')
end
+local function asDocTypeName(source)
+ for _, doc in ipairs(vm.getDocTypes(source[1])) do
+ if doc.type == 'doc.class.name' then
+ return 'class ' .. source[1]
+ end
+ if doc.type == 'doc.alias.name' then
+ local extends = doc.parent.extends
+ -- TODO
+ return '展开为 ' .. vm.getInferType(extends)
+ end
+ end
+end
+
local function asValue(source, title)
local name = buildName(source)
local infers = vm.getInfers(source, 'deep')
@@ -175,5 +188,7 @@ return function (source, oop)
return asLibrary(source)
elseif source.type == 'doc.type.function' then
return asDocFunction(source)
+ elseif source.type == 'doc.type.name' then
+ return asDocTypeName(source)
end
end