Skip to content

Commit 1a6e210

Browse files
committed
#1255 hover for doc.enum
1 parent 4d1a35d commit 1a6e210

File tree

6 files changed

+73
-3
lines changed

6 files changed

+73
-3
lines changed

script/core/completion/completion.lua

+2
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,8 @@ local function tryluaDocCate(word, results)
15671567
'nodiscard',
15681568
'cast',
15691569
'operator',
1570+
'source',
1571+
'enum',
15701572
} do
15711573
if matchKey(word, docType) then
15721574
results[#results+1] = {

script/core/hover/description.lua

+33
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,38 @@ local function tyrDocParamComment(source)
412412
end
413413
end
414414

415+
---@param source parser.object
416+
local function tryDocEnum(source)
417+
if source.type ~= 'doc.enum' then
418+
return
419+
end
420+
local tbl = source.bindSource
421+
if not tbl then
422+
return
423+
end
424+
local md = markdown()
425+
md:add('lua', '{')
426+
for _, field in ipairs(tbl) do
427+
if field.type == 'tablefield'
428+
or field.type == 'tableindex' then
429+
if not field.value then
430+
goto CONTINUE
431+
end
432+
local key = guide.getKeyName(field)
433+
if not key then
434+
goto CONTINUE
435+
end
436+
if field.value.type == 'integer'
437+
or field.value.type == 'string' then
438+
md:add('lua', (' %s: %s = %s,'):format(key, field.value.type, field.value[1]))
439+
end
440+
::CONTINUE::
441+
end
442+
end
443+
md:add('lua', '}')
444+
return md:string()
445+
end
446+
415447
return function (source)
416448
if source.type == 'string' then
417449
return asString(source)
@@ -425,4 +457,5 @@ return function (source)
425457
or tryDocComment(source)
426458
or tryDocClassComment(source)
427459
or tryDocModule(source)
460+
or tryDocEnum(source)
428461
end

script/parser/luadoc.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,6 @@ local function bindDoc(source, binded)
16461646
or doc.type == 'doc.deprecated'
16471647
or doc.type == 'doc.version'
16481648
or doc.type == 'doc.module'
1649-
or doc.type == 'doc.enum'
16501649
or doc.type == 'doc.source' then
16511650
if source.type == 'function'
16521651
or isParam then
@@ -1700,6 +1699,10 @@ local function bindDoc(source, binded)
17001699
if source.type ~= 'function' then
17011700
goto CONTINUE
17021701
end
1702+
elseif doc.type == 'doc.enum' then
1703+
if source.type ~= 'table' then
1704+
goto CONTINUE
1705+
end
17031706
elseif doc.type ~= 'doc.comment' then
17041707
goto CONTINUE
17051708
end
@@ -1756,6 +1759,7 @@ local function bindDocsBetween(sources, binded, start, finish)
17561759
or src.type == 'setindex'
17571760
or src.type == 'setmethod'
17581761
or src.type == 'function'
1762+
or src.type == 'table'
17591763
or src.type == '...' then
17601764
if bindDoc(src, binded) then
17611765
ok = true

script/vm/global.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ local compilerGlobalSwitch = util.switch()
331331
enum:addSet(uri, source)
332332
source._globalNode = enum
333333

334-
local tbl = source.bindSource and source.bindSource.value
335-
if not tbl or tbl.type ~= 'table' then
334+
local tbl = source.bindSource
335+
if not tbl then
336336
return
337337
end
338338
source._enums = {}

script/vm/type.lua

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ local function checkEnum(parentName, child, uri)
5252
end
5353
for _, set in ipairs(parentClass:getSets(uri)) do
5454
if set.type == 'doc.enum' then
55+
if not set._enums then
56+
return false
57+
end
5558
if child.type ~= 'string'
5659
and child.type ~= 'doc.type.string'
5760
and child.type ~= 'integer'

test/crossfile/hover.lua

+28
Original file line numberDiff line numberDiff line change
@@ -1497,3 +1497,31 @@ A:
14971497
| 2 -- comment2
14981498
```]]
14991499
}
1500+
1501+
TEST {
1502+
{
1503+
path = 'a.lua',
1504+
content = [[
1505+
---@enum <?A?>
1506+
local t = {
1507+
x = 1,
1508+
y = 2,
1509+
z = 3,
1510+
}
1511+
]]
1512+
},
1513+
hover = [[
1514+
```lua
1515+
(enum) A
1516+
```
1517+
1518+
---
1519+
1520+
```lua
1521+
{
1522+
x: integer = 1,
1523+
y: integer = 2,
1524+
z: integer = 3,
1525+
}
1526+
```]]
1527+
}

0 commit comments

Comments
 (0)