Skip to content

Commit d99c23a

Browse files
committed
#1061 completion for doc.type.code
1 parent bc92c4d commit d99c23a

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

changelog.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# changelog
22

3+
## 3.3.0
4+
* `NEW` `LuaDoc` supports `` `CODE` ``
5+
```lua
6+
---@type `CONST.X` | `CONST.Y`
7+
local x
8+
9+
if x == -- suggest `CONST.X` and `CONST.Y` here
10+
```
11+
312
## 3.2.5
413
`2022-6-9`
514
* `NEW` provide config docs in `LUA_LANGUAGE_SERVER/doc/`

script/core/completion/completion.lua

+12
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,12 @@ local function checkTypingEnum(state, position, defs, str, results)
11361136
description = def.comment and def.comment.text,
11371137
kind = define.CompletionItemKind.EnumMember,
11381138
}
1139+
elseif def.type == 'doc.type.code' then
1140+
enums[#enums+1] = {
1141+
label = def[1],
1142+
description = def.comment and def.comment.text,
1143+
kind = define.CompletionItemKind.EnumMember,
1144+
}
11391145
end
11401146
end
11411147
cleanEnums(enums, str)
@@ -1425,6 +1431,12 @@ local function tryCallArg(state, position, results)
14251431
description = src.comment,
14261432
kind = define.CompletionItemKind.EnumMember,
14271433
}
1434+
elseif src.type == 'doc.type.code' then
1435+
enums[#enums+1] = {
1436+
label = src[1],
1437+
description = src.comment,
1438+
kind = define.CompletionItemKind.EnumMember,
1439+
}
14281440
end
14291441
if src.type == 'doc.type.function' then
14301442
local insertText = buildInsertDocFunction(src)

script/core/hover/description.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ local function buildEnumChunk(docType, name)
155155
types[#types+1] = vm.getInfer(tp):view(guide.getUri(docType))
156156
if tp.type == 'doc.type.string'
157157
or tp.type == 'doc.type.integer'
158-
or tp.type == 'doc.type.boolean' then
158+
or tp.type == 'doc.type.boolean'
159+
or tp.type == 'doc.type.code' then
159160
enums[#enums+1] = tp
160161
end
161162
local comment = tryDocClassComment(tp)

script/parser/guide.lua

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ function m.isLiteral(obj)
252252
or tp == 'doc.type.string'
253253
or tp == 'doc.type.integer'
254254
or tp == 'doc.type.boolean'
255+
or tp == 'doc.type.code'
255256
end
256257

257258
--- 获取字面量

test/completion/common.lua

+34
Original file line numberDiff line numberDiff line change
@@ -3348,3 +3348,37 @@ local xyz
33483348
kind = define.CompletionItemKind.Variable,
33493349
}
33503350
}
3351+
3352+
TEST [[
3353+
---@type `CONST.X` | `CONST.Y`
3354+
local x
3355+
3356+
if x == <??>
3357+
]]
3358+
{
3359+
{
3360+
label = 'CONST.X',
3361+
kind = define.CompletionItemKind.EnumMember,
3362+
},
3363+
{
3364+
label = 'CONST.Y',
3365+
kind = define.CompletionItemKind.EnumMember,
3366+
},
3367+
}
3368+
3369+
TEST [[
3370+
---@param x `CONST.X` | `CONST.Y`
3371+
local function f(x) end
3372+
3373+
f(<??>)
3374+
]]
3375+
{
3376+
{
3377+
label = 'CONST.X',
3378+
kind = define.CompletionItemKind.EnumMember,
3379+
},
3380+
{
3381+
label = 'CONST.Y',
3382+
kind = define.CompletionItemKind.EnumMember,
3383+
},
3384+
}

0 commit comments

Comments
 (0)