summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-17 15:02:42 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-17 15:02:42 +0800
commit8ddc5f60a24adb1ef8ac578965190a3e23e180c3 (patch)
treec2e51ce5983451b9f7ad26247a1e335fa0941902 /script-beta
parent1bb4040b7ff975f20ec151d6b97ecf6e044bfb2a (diff)
downloadlua-language-server-8ddc5f60a24adb1ef8ac578965190a3e23e180c3.zip
将 doc.type.array 与 doc.type.generic 视为独立对象
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/parser/guide.lua31
-rw-r--r--script-beta/parser/luadoc.lua61
2 files changed, 55 insertions, 37 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index a3e18863..9939dce6 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -937,10 +937,6 @@ local function stepRefOfDocType(status, obj, mode)
or obj.type == 'doc.type.name'
or obj.type == 'doc.alias.name'
or obj.type == 'doc.extends.name' then
- if obj.array
- or obj.generic then
- return results
- end
local name = obj[1]
if not name or not status.interface.docType then
return results
@@ -2581,7 +2577,9 @@ function m.viewInferType(infers)
local infer = infers[i]
if infer.source.type == 'doc.class'
or infer.source.type == 'doc.class.name'
- or infer.source.type == 'doc.type.name' then
+ or infer.source.type == 'doc.type.name'
+ or infer.source.type == 'doc.type.array'
+ or infer.source.type == 'doc.type.generic' then
if infer.type ~= 'any' then
hasDoc = true
break
@@ -2594,6 +2592,8 @@ function m.viewInferType(infers)
if infer.source.type == 'doc.class'
or infer.source.type == 'doc.class.name'
or infer.source.type == 'doc.type.name'
+ or infer.source.type == 'doc.type.array'
+ or infer.source.type == 'doc.type.generic'
or infer.source.type == 'doc.type.enum' then
local tp = infer.type or 'any'
if not mark[tp] then
@@ -2812,6 +2812,14 @@ local function getDocTypeUnitName(status, unit, genericCallback)
typeName = getDocAliasExtends(status, unit[1]) or unit[1]
elseif unit.type == 'doc.type.function' then
typeName = 'function'
+ elseif unit.type == 'doc.type.array' then
+ typeName = getDocTypeUnitName(status, unit.node, genericCallback) .. '[]'
+ elseif unit.type == 'doc.type.generic' then
+ typeName = ('%s<%s, %s>'):format(
+ getDocTypeUnitName(status, unit.node, genericCallback),
+ m.viewInferType(m.getDocTypeNames(status, unit.key, genericCallback)),
+ m.viewInferType(m.getDocTypeNames(status, unit.value, genericCallback))
+ )
end
if unit.typeGeneric then
if genericCallback then
@@ -2821,15 +2829,6 @@ local function getDocTypeUnitName(status, unit, genericCallback)
typeName = ('<%s>'):format(typeName)
end
end
- if unit.array then
- typeName = typeName .. '[]'
- elseif unit.generic then
- typeName = ('%s<%s, %s>'):format(
- typeName,
- m.viewInferType(m.getDocTypeNames(status, unit.key)),
- m.viewInferType(m.getDocTypeNames(status, unit.value))
- )
- end
return typeName
end
@@ -3018,11 +3017,11 @@ function m.inferCheckFieldDoc(status, source)
local ok
for _, infer in ipairs(newStatus.results) do
local src = infer.source
- if src.array then
+ if src.type == 'doc.type.array' then
ok = true
status.results[#status.results+1] = {
type = infer.type:gsub('%[%]$', ''),
- source = source,
+ source = src.node,
}
end
end
diff --git a/script-beta/parser/luadoc.lua b/script-beta/parser/luadoc.lua
index 06edf24c..8117e060 100644
--- a/script-beta/parser/luadoc.lua
+++ b/script-beta/parser/luadoc.lua
@@ -244,27 +244,45 @@ local function nextSymbolOrError(symbol)
return false
end
-local function parseTypeUnitGeneric(typeUnit)
+local function parseTypeUnitArray(node)
+ if not checkToken('symbol', '[]', 1) then
+ return nil
+ end
+ nextToken()
+ local result = {
+ type = 'doc.type.array',
+ start = node.start,
+ finish = getFinish(),
+ node = node,
+ }
+ return result
+end
+
+local function parseTypeUnitGeneric(node)
if not checkToken('symbol', '<', 1) then
return nil
end
if not nextSymbolOrError('<') then
return nil
end
- local key = parseType(typeUnit)
+ local key = parseType(node)
if not key or not nextSymbolOrError(',') then
return nil
end
- local value = parseType(typeUnit)
+ local value = parseType(node)
if not value then
return nil
end
nextSymbolOrError('>')
- typeUnit.generic= true
- typeUnit.key = key
- typeUnit.value = value
- typeUnit.finish = getFinish()
- return typeUnit
+ local result = {
+ type = 'doc.type.generic',
+ start = node.start,
+ finish = getFinish(),
+ node = node,
+ key = key,
+ value = value,
+ }
+ return result
end
local function parseTypeUnitFunction()
@@ -343,30 +361,31 @@ local function parseTypeUnitFunction()
end
local function parseTypeUnit(parent, content)
- local typeUnit
+ local result
if content == 'fun' then
- typeUnit = parseTypeUnitFunction()
+ result = parseTypeUnitFunction()
end
- if not typeUnit then
- typeUnit = {
+ if not result then
+ result = {
type = 'doc.type.name',
start = getStart(),
finish = getFinish(),
[1] = content,
}
end
- if not typeUnit then
+ if not result then
return nil
end
- typeUnit.parent = parent
- if checkToken('symbol', '[]', 1) then
- nextToken()
- typeUnit.array = true
- typeUnit.finish = getFinish()
- else
- parseTypeUnitGeneric(typeUnit)
+ result.parent = parent
+ while true do
+ local newResult = parseTypeUnitArray(result)
+ or parseTypeUnitGeneric(result)
+ if not newResult then
+ break
+ end
+ result = newResult
end
- return typeUnit
+ return result
end
local function parseResume()