Skip to content

Commit 04c6711

Browse files
committed
doc.enum
1 parent 697c935 commit 04c6711

File tree

16 files changed

+99
-9
lines changed

16 files changed

+99
-9
lines changed

script/core/completion/completion.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,7 @@ local function tryluaDocBySource(state, position, source, results)
16481648
for _, doc in ipairs(vm.getDocSets(state.uri)) do
16491649
local name = (doc.type == 'doc.class' and doc.class[1])
16501650
or (doc.type == 'doc.alias' and doc.alias[1])
1651+
or (doc.type == 'doc.enum' and doc.enum[1])
16511652
if name
16521653
and not used[name]
16531654
and matchKey(source[1], name) then
@@ -1803,6 +1804,14 @@ local function tryluaDocByErr(state, position, err, docState, results)
18031804
kind = define.CompletionItemKind.Class,
18041805
}
18051806
end
1807+
if doc.type == 'doc.enum'
1808+
and not used[doc.enum[1]] then
1809+
used[doc.enum[1]] = true
1810+
results[#results+1] = {
1811+
label = doc.enum[1],
1812+
kind = define.CompletionItemKind.Enum,
1813+
}
1814+
end
18061815
end
18071816
elseif err.type == 'LUADOC_MISS_PARAM_NAME' then
18081817
local funcs = {}

script/core/definition.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ local accept = {
5555
['doc.see.name'] = true,
5656
['doc.see.field'] = true,
5757
['doc.cast.name'] = true,
58+
['doc.enum.name'] = true,
5859
}
5960

6061
local function checkRequire(source, offset)
@@ -170,8 +171,12 @@ return function (uri, offset)
170171
if src.type == 'doc.alias' then
171172
src = src.alias
172173
end
174+
if src.type == 'doc.enum' then
175+
src = src.enum
176+
end
173177
if src.type == 'doc.class.name'
174-
or src.type == 'doc.alias.name' then
178+
or src.type == 'doc.alias.name'
179+
or src.type == 'doc.enum.name' then
175180
if source.type ~= 'doc.type.name'
176181
and source.type ~= 'doc.extends.name'
177182
and source.type ~= 'doc.see.name' then

script/core/diagnostics/duplicate-doc-alias.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ return function (uri, callback)
1717

1818
local cache = {}
1919
for _, doc in ipairs(state.ast.docs) do
20-
if doc.type == 'doc.alias' then
20+
if doc.type == 'doc.alias'
21+
or doc.type == 'doc.enum' then
2122
local name = guide.getKeyName(doc)
2223
if not name then
2324
return
@@ -28,7 +29,8 @@ return function (uri, callback)
2829
cache[name] = {}
2930
for _, otherDoc in ipairs(docs) do
3031
if otherDoc.type == 'doc.alias'
31-
or otherDoc.type == 'doc.class' then
32+
or otherDoc.type == 'doc.class'
33+
or otherDoc.type == 'doc.enum' then
3234
cache[name][#cache[name]+1] = {
3335
start = otherDoc.start,
3436
finish = otherDoc.finish,

script/core/folding.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ local care = {
152152
hideLastLine = true,
153153
}
154154
results[#results+1] = folding
155-
end
155+
end,
156156
}
157157

158158
---@async

script/core/hover/description.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ end
164164
local function tryDocClassComment(source)
165165
for _, def in ipairs(vm.getDefs(source)) do
166166
if def.type == 'doc.class'
167-
or def.type == 'doc.alias' then
167+
or def.type == 'doc.alias'
168+
or def.type == 'doc.enum' then
168169
local comment = getBindComment(def)
169170
if comment then
170171
return comment
@@ -361,6 +362,10 @@ local function tryDocComment(source)
361362
local enums = buildEnumChunk(source, source.alias[1], guide.getUri(source))
362363
md:add('lua', enums)
363364
end
365+
if source.type == 'doc.enum' then
366+
local enums = buildEnumChunk(source, source.enum[1], guide.getUri(source))
367+
md:add('lua', enums)
368+
end
364369
local result = md:string()
365370
if result == '' then
366371
return nil

script/core/hover/label.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ local function asDocTypeName(source)
3535
if doc.type == 'doc.alias' then
3636
return '(alias) ' .. doc.alias[1] .. ' ' .. lang.script('HOVER_EXTENDS', vm.getInfer(doc.extends):view(guide.getUri(source)))
3737
end
38+
if doc.type == 'doc.enum' then
39+
return '(enum) ' .. doc.enum[1] .. ' ' .. lang.script('HOVER_EXTENDS', vm.getInfer(doc.extends):view(guide.getUri(source)))
40+
end
3841
end
3942
end
4043

script/core/reference.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ local accept = {
5050
['doc.class.name'] = true,
5151
['doc.extends.name'] = true,
5252
['doc.alias.name'] = true,
53+
['doc.enum.name'] = true,
5354
}
5455

5556
---@async
@@ -102,12 +103,17 @@ return function (uri, position)
102103
if src.type == 'doc.alias' then
103104
src = src.alias
104105
end
106+
if src.type == 'doc.enum' then
107+
src = src.enum
108+
end
105109
if src.type == 'doc.class.name'
106110
or src.type == 'doc.alias.name'
111+
or src.type == 'doc.enum.name'
107112
or src.type == 'doc.type.name'
108113
or src.type == 'doc.extends.name' then
109114
if source.type ~= 'doc.type.name'
110115
and source.type ~= 'doc.class.name'
116+
and source.type ~= 'doc.enum.name'
111117
and source.type ~= 'doc.extends.name'
112118
and source.type ~= 'doc.see.name' then
113119
goto CONTINUE

script/core/rename.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ local function ofDocTypeName(source, newname, callback)
231231
if doc.type == 'doc.alias' then
232232
callback(doc, doc.alias.start, doc.alias.finish, newname)
233233
end
234+
if doc.type == 'doc.enum' then
235+
callback(doc, doc.enum.start, doc.enum.finish, newname)
236+
end
234237
end
235238
for _, doc in ipairs(global:getGets(uri)) do
236239
if doc.type == 'doc.type.name' then
@@ -276,7 +279,8 @@ local function rename(source, newname, callback)
276279
return ofGlobal(source, newname, callback)
277280
elseif source.type == 'doc.class.name'
278281
or source.type == 'doc.type.name'
279-
or source.type == 'doc.alias.name' then
282+
or source.type == 'doc.alias.name'
283+
or source.type == 'doc.enum.name' then
280284
return ofDocTypeName(source, newname, callback)
281285
elseif source.type == 'doc.param.name' then
282286
return ofDocParamName(source, newname, callback)
@@ -310,6 +314,7 @@ local function prepareRename(source)
310314
or source.type == 'doc.class.name'
311315
or source.type == 'doc.type.name'
312316
or source.type == 'doc.alias.name'
317+
or source.type == 'doc.enum.name'
313318
or source.type == 'doc.param.name' then
314319
return source, source[1]
315320
elseif source.type == 'string'
@@ -350,6 +355,7 @@ local accept = {
350355
['doc.type.name'] = true,
351356
['doc.alias.name'] = true,
352357
['doc.param.name'] = true,
358+
['doc.enum.name'] = true,
353359
}
354360

355361
local m = {}

script/core/semantic-tokens.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ local Care = util.switch()
449449
end
450450
end)
451451
: case 'doc.alias.name'
452+
: case 'doc.enum.name'
452453
: call(function (source, options, results)
453454
if not options.annotation then
454455
return

script/core/type-definition.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ local accept = {
5252
['doc.class.name'] = true,
5353
['doc.extends.name'] = true,
5454
['doc.alias.name'] = true,
55+
['doc.enum.name'] = true,
5556
['doc.see.name'] = true,
5657
['doc.see.field'] = true,
5758
}
@@ -145,6 +146,9 @@ return function (uri, offset)
145146
if src.type == 'doc.alias' then
146147
src = src.alias
147148
end
149+
if src.type == 'doc.enum' then
150+
src = src.enum
151+
end
148152
if src.type == 'doc.class.name'
149153
or src.type == 'doc.alias.name'
150154
or src.type == 'doc.type.function'

0 commit comments

Comments
 (0)