summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meta/template/builtin.lua2
-rw-r--r--script/core/completion/completion.lua3
-rw-r--r--script/core/hover/description.lua19
-rw-r--r--script/parser/guide.lua1
-rw-r--r--script/parser/luadoc.lua20
-rw-r--r--script/vm/compiler.lua4
-rw-r--r--script/vm/infer.lua8
-rw-r--r--script/vm/value.lua11
-rw-r--r--test/crossfile/hover.lua6
9 files changed, 46 insertions, 28 deletions
diff --git a/meta/template/builtin.lua b/meta/template/builtin.lua
index 41858096..2ef14f53 100644
--- a/meta/template/builtin.lua
+++ b/meta/template/builtin.lua
@@ -4,8 +4,6 @@
---@class any
---@class nil
---@class boolean
----@class true: boolean
----@class false: boolean
---@class number
---@class integer: number
---@class thread
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index b613a1f2..8e1ef696 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -1406,7 +1406,8 @@ local function tryCallArg(state, position, results)
local enums = {}
for src in nodeMgr.eachNode(node) do
if src.type == 'doc.type.string'
- or src.type == 'doc.type.integer' then
+ or src.type == 'doc.type.integer'
+ or src.type == 'doc.type.boolean' then
enums[#enums+1] = {
label = util.viewLiteral(src[1]),
description = src.comment,
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index cf6f0113..d3d24a75 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -156,10 +156,11 @@ local function buildEnumChunk(docType, name)
local enums = {}
local types = {}
local lines = {}
- for _, tp in ipairs(docType.types) do
+ for _, tp in ipairs(vm.getDefs(docType)) do
types[#types+1] = infer.getInfer(tp):view()
if tp.type == 'doc.type.string'
- or tp.type == 'doc.type.integer' then
+ or tp.type == 'doc.type.integer'
+ or tp.type == 'doc.type.boolean' then
enums[#enums+1] = tp
end
local comment = tryDocClassComment(tp)
@@ -352,11 +353,15 @@ local function tyrDocParamComment(source)
if source.parent.type ~= 'funcargs' then
return
end
- for _, def in ipairs(vm.getDefs(source)) do
- if def.type == 'doc.param' then
- if def.comment then
- return def.comment.text
- end
+ if not source.bindDocs then
+ return
+ end
+ for i = #source.bindDocs, 1, -1 do
+ local doc = source.bindDocs[i]
+ if doc.type == 'doc.param'
+ and doc.param[1] == source[1]
+ and doc.comment then
+ return doc.comment.text
end
end
end
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 2de1ac22..2b22d1b2 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -235,6 +235,7 @@ function m.isLiteral(obj)
or tp == 'doc.type.table'
or tp == 'doc.type.string'
or tp == 'doc.type.integer'
+ or tp == 'doc.type.boolean'
end
--- 获取字面量
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 4dbece5a..4d9de5be 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -578,11 +578,31 @@ local function parseInteger(parent)
return integer
end
+local function parseBoolean(parent)
+ local tp, content = peekToken()
+ if not tp
+ or tp ~= 'name'
+ or (content ~= 'true' and content ~= 'false') then
+ return nil
+ end
+
+ nextToken()
+ local boolean = {
+ type = 'doc.type.boolean',
+ start = getStart(),
+ finish = getFinish(),
+ parent = parent,
+ [1] = content == 'true' and true or false,
+ }
+ return boolean
+end
+
function parseTypeUnit(parent)
local result = parseFunction(parent)
or parseTable(parent)
or parseString(parent)
or parseInteger(parent)
+ or parseBoolean(parent)
or parseDots('doc.type.name', parent)
if not result then
local literal = checkToken('symbol', '`', 1)
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 57816e24..e244c6c3 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -858,10 +858,8 @@ local compilerSwitch = util.switch()
end
end)
: case 'doc.type.integer'
- : call(function (source)
- nodeMgr.setNode(source, source)
- end)
: case 'doc.type.string'
+ : case 'doc.type.boolean'
: call(function (source)
nodeMgr.setNode(source, source)
end)
diff --git a/script/vm/infer.lua b/script/vm/infer.lua
index b436f9e1..e6ca14e2 100644
--- a/script/vm/infer.lua
+++ b/script/vm/infer.lua
@@ -32,6 +32,8 @@ local inferSorted = {
['integer'] = - 97,
['function'] = - 96,
['table'] = - 95,
+ ['true'] = 1,
+ ['false'] = 2,
['nil'] = 100,
}
@@ -82,10 +84,6 @@ local viewNodeSwitch = util.switch()
return source.name
end
end)
- : case 'doc.type.integer'
- : call(function (source, infer)
- return ('%d'):format(source[1])
- end)
: case 'doc.type.name'
: call(function (source, infer)
infer._hasClass = true
@@ -117,6 +115,8 @@ local viewNodeSwitch = util.switch()
infer._hasTable = true
end)
: case 'doc.type.string'
+ : case 'doc.type.integer'
+ : case 'doc.type.boolean'
: call(function (source, infer)
return ('%q'):format(source[1])
end)
diff --git a/script/vm/value.lua b/script/vm/value.lua
index 549cee02..4141ba8a 100644
--- a/script/vm/value.lua
+++ b/script/vm/value.lua
@@ -204,14 +204,9 @@ function m.getLiterals(v)
or n.type == 'integer' then
literal = n[1]
end
- if n.type == 'global' and n.cate == 'type' then
- if n.name == 'true' then
- literal = true
- elseif n.name == 'false' then
- literal = false
- end
- end
- if n.type == 'doc.type.integer' then
+ if n.type == 'doc.type.string'
+ or n.type == 'doc.type.integer'
+ or n.type == 'doc.type.boolean' then
literal = n[1]
end
if literal ~= nil then
diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua
index b5c599eb..10124eb9 100644
--- a/test/crossfile/hover.lua
+++ b/test/crossfile/hover.lua
@@ -673,8 +673,8 @@ TEST {{ path = 'a.lua', content = '', }, {
path = 'b.lua',
content = [[
---@param a boolean # xxx
- ---| 'true' # ttt
- ---| 'false' # fff
+ ---| true # ttt
+ ---| false # fff
local function <?f?>(a)
end
]]
@@ -689,7 +689,7 @@ function f(a: boolean|true|false)
@*param* `a` — xxx
```lua
-a: boolean
+a:
| true -- ttt
| false -- fff
```]]}