summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-30 21:18:14 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-30 21:18:14 +0800
commit47e17129cd6d21eec1e8d9d402481153d4c8e0a3 (patch)
treeed1fc7ce90a707542432a2f545f3398a1cfac5a3 /script
parent8785f527f209607a3efe6c2762f6096b9cb14853 (diff)
downloadlua-language-server-47e17129cd6d21eec1e8d9d402481153d4c8e0a3.zip
support alias
Diffstat (limited to 'script')
-rw-r--r--script/core/completion.lua6
-rw-r--r--script/parser/guide.lua29
2 files changed, 25 insertions, 10 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 5ee73ad4..5d32e659 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -857,7 +857,8 @@ end
local function checkTypingEnum(ast, text, offset, infers, str, results)
local enums = {}
for _, infer in ipairs(infers) do
- if infer.source.type == 'doc.type.enum' then
+ if infer.source.type == 'doc.type.enum'
+ or infer.source.type == 'doc.resume' then
enums[#enums+1] = {
label = infer.source[1],
description = infer.source.comment and infer.source.comment.text,
@@ -916,6 +917,9 @@ local function checkEqualEnumInString(ast, text, offset, results)
return source[1]
end
end
+ if not source.start then
+ return
+ end
if source.start <= offset
and source.finish >= offset then
local parent = source.parent
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index bc82ec57..1b4213b1 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -2828,13 +2828,16 @@ function m.inferCheckLiteral(status, source)
end
end
-local function getDocAliasExtends(status, name)
+local function getDocAliasExtends(status, typeUnit)
if not status.interface.docType then
return nil
end
- for _, doc in ipairs(status.interface.docType(name)) do
+ if typeUnit.type ~= 'doc.type.name' then
+ return nil
+ end
+ for _, doc in ipairs(status.interface.docType(typeUnit[1])) do
if doc.type == 'doc.alias.name' then
- return m.viewInferType(m.getDocTypeNames(status, doc.parent.extends))
+ return doc.parent.extends
end
end
return nil
@@ -2843,7 +2846,7 @@ end
local function getDocTypeUnitName(status, unit, genericCallback)
local typeName
if unit.type == 'doc.type.name' then
- typeName = getDocAliasExtends(status, unit[1]) or unit[1]
+ typeName = unit[1]
elseif unit.type == 'doc.type.function' then
typeName = 'function'
elseif unit.type == 'doc.type.array' then
@@ -2872,11 +2875,19 @@ function m.getDocTypeNames(status, doc, genericCallback)
return results
end
for _, unit in ipairs(doc.types) do
- local typeName = getDocTypeUnitName(status, unit, genericCallback)
- results[#results+1] = {
- type = typeName,
- source = unit,
- }
+ local alias = getDocAliasExtends(status, unit)
+ if alias then
+ local aliasResults = m.getDocTypeNames(status, alias, genericCallback)
+ for _, res in ipairs(aliasResults) do
+ results[#results+1] = res
+ end
+ else
+ local typeName = getDocTypeUnitName(status, unit, genericCallback)
+ results[#results+1] = {
+ type = typeName,
+ source = unit,
+ }
+ end
end
for _, enum in ipairs(doc.enums) do
results[#results+1] = {