@@ -56,6 +56,7 @@ local function trim(str)
56
56
end
57
57
58
58
local function findNearestSource (state , position )
59
+ --- @type parser.object
59
60
local source
60
61
guide .eachSourceContain (state .ast , position , function (src )
61
62
source = src
@@ -1132,32 +1133,42 @@ local function cleanEnums(enums, source)
1132
1133
return enums
1133
1134
end
1134
1135
1135
- local function checkTypingEnum (state , position , defs , str , results )
1136
+ --- @return boolean
1137
+ local function insertEnum (state , src , enums , isInArray )
1138
+ if src .type == ' doc.type.string'
1139
+ or src .type == ' doc.type.integer'
1140
+ or src .type == ' doc.type.boolean' then
1141
+ --- @cast src parser.object
1142
+ enums [# enums + 1 ] = {
1143
+ label = vm .viewObject (src , state .uri ),
1144
+ description = src .comment ,
1145
+ kind = define .CompletionItemKind .EnumMember ,
1146
+ }
1147
+ elseif src .type == ' doc.type.code' then
1148
+ enums [# enums + 1 ] = {
1149
+ label = src [1 ],
1150
+ description = src .comment ,
1151
+ kind = define .CompletionItemKind .EnumMember ,
1152
+ }
1153
+ elseif isInArray and src .type == ' doc.type.array' then
1154
+ for i , d in ipairs (vm .getDefs (src .node )) do
1155
+ insertEnum (state , d , enums , isInArray )
1156
+ end
1157
+ end
1158
+ end
1159
+
1160
+ local function checkTypingEnum (state , position , defs , str , results , isInArray )
1136
1161
local enums = {}
1137
1162
for _ , def in ipairs (defs ) do
1138
- if def .type == ' doc.type.string'
1139
- or def .type == ' doc.type.integer'
1140
- or def .type == ' doc.type.boolean' then
1141
- enums [# enums + 1 ] = {
1142
- label = vm .viewObject (def , state .uri ),
1143
- description = def .comment and def .comment .text ,
1144
- kind = define .CompletionItemKind .EnumMember ,
1145
- }
1146
- elseif def .type == ' doc.type.code' then
1147
- enums [# enums + 1 ] = {
1148
- label = def [1 ],
1149
- description = def .comment and def .comment .text ,
1150
- kind = define .CompletionItemKind .EnumMember ,
1151
- }
1152
- end
1163
+ insertEnum (state , def , enums , isInArray )
1153
1164
end
1154
1165
cleanEnums (enums , str )
1155
1166
for _ , res in ipairs (enums ) do
1156
1167
results [# results + 1 ] = res
1157
1168
end
1158
1169
end
1159
1170
1160
- local function checkEqualEnumLeft (state , position , source , results )
1171
+ local function checkEqualEnumLeft (state , position , source , results , isInArray )
1161
1172
if not source then
1162
1173
return
1163
1174
end
@@ -1167,7 +1178,7 @@ local function checkEqualEnumLeft(state, position, source, results)
1167
1178
end
1168
1179
end )
1169
1180
local defs = vm .getDefs (source )
1170
- checkTypingEnum (state , position , defs , str , results )
1181
+ checkTypingEnum (state , position , defs , str , results , isInArray )
1171
1182
end
1172
1183
1173
1184
local function checkEqualEnum (state , position , results )
@@ -1211,9 +1222,14 @@ local function checkEqualEnumInString(state, position, results)
1211
1222
end
1212
1223
checkEqualEnumLeft (state , position , parent [1 ], results )
1213
1224
end
1225
+ if (parent .type == ' tableexp' ) then
1226
+ checkEqualEnumLeft (state , position , parent .parent .parent , results , true )
1227
+ return
1228
+ end
1214
1229
if parent .type == ' local' then
1215
1230
checkEqualEnumLeft (state , position , parent , results )
1216
1231
end
1232
+
1217
1233
if parent .type == ' setlocal'
1218
1234
or parent .type == ' setglobal'
1219
1235
or parent .type == ' setfield'
@@ -1435,24 +1451,10 @@ local function tryCallArg(state, position, results)
1435
1451
if not node then
1436
1452
return
1437
1453
end
1454
+
1438
1455
local enums = {}
1439
1456
for src in node :eachObject () do
1440
- if src .type == ' doc.type.string'
1441
- or src .type == ' doc.type.integer'
1442
- or src .type == ' doc.type.boolean' then
1443
- --- @cast src parser.object
1444
- enums [# enums + 1 ] = {
1445
- label = vm .viewObject (src , state .uri ),
1446
- description = src .comment ,
1447
- kind = define .CompletionItemKind .EnumMember ,
1448
- }
1449
- elseif src .type == ' doc.type.code' then
1450
- enums [# enums + 1 ] = {
1451
- label = src [1 ],
1452
- description = src .comment ,
1453
- kind = define .CompletionItemKind .EnumMember ,
1454
- }
1455
- end
1457
+ insertEnum (state , src , enums , arg and arg .type == ' table' )
1456
1458
if src .type == ' doc.type.function' then
1457
1459
--- @cast src parser.object
1458
1460
local insertText = buildInsertDocFunction (src )
@@ -1496,6 +1498,7 @@ local function tryTable(state, position, results)
1496
1498
if source .type ~= ' table' then
1497
1499
tbl = source .parent
1498
1500
end
1501
+
1499
1502
local defs = vm .getFields (tbl )
1500
1503
for _ , field in ipairs (defs ) do
1501
1504
local name = guide .getKeyName (field )
@@ -1507,6 +1510,25 @@ local function tryTable(state, position, results)
1507
1510
checkTableLiteralField (state , position , tbl , fields , results )
1508
1511
end
1509
1512
1513
+ local function tryArray (state , position , results )
1514
+ local source = findNearestSource (state , position )
1515
+ if not source then
1516
+ return
1517
+ end
1518
+ if source .type ~= ' table' and (not source .parent or source .parent .type ~= ' table' ) then
1519
+ return
1520
+ end
1521
+ local tbl = source
1522
+ if source .type ~= ' table' then
1523
+ tbl = source .parent
1524
+ end
1525
+ if source .parent .type == ' callargs' and source .parent .parent .type == ' call' then
1526
+ return
1527
+ end
1528
+ -- { } inside when enum
1529
+ checkEqualEnumLeft (state , position , tbl , results , true )
1530
+ end
1531
+
1510
1532
local function getComment (state , position )
1511
1533
local offset = guide .positionToOffset (state , position )
1512
1534
local symbolOffset = lookBackward .findAnyOffset (state .lua , offset )
@@ -2001,6 +2023,7 @@ local function tryCompletions(state, position, triggerCharacter, results)
2001
2023
trySpecial (state , position , results )
2002
2024
tryCallArg (state , position , results )
2003
2025
tryTable (state , position , results )
2026
+ tryArray (state , position , results )
2004
2027
tryWord (state , position , triggerCharacter , results )
2005
2028
tryIndex (state , position , results )
2006
2029
trySymbol (state , position , results )
0 commit comments