Skip to content

Commit 85a9019

Browse files
committed
update semantic tokens
1 parent 72954de commit 85a9019

File tree

3 files changed

+127
-17
lines changed

3 files changed

+127
-17
lines changed

script/core/semantic-tokens.lua

Lines changed: 122 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -373,32 +373,125 @@ local Care = util.switch()
373373
type = define.TokenTypes.number,
374374
}
375375
end)
376-
: case 'doc.return.name'
376+
: case 'doc.class.name'
377377
: call(function (source, options, results)
378378
results[#results+1] = {
379-
start = source.start,
380-
finish = source.finish,
381-
type = define.TokenTypes.parameter,
379+
start = source.start,
380+
finish = source.finish,
381+
type = define.TokenTypes.class,
382+
modifieres = define.TokenModifiers.declaration,
382383
}
383384
end)
384-
: case 'doc.tailcomment'
385+
: case 'doc.extends.name'
385386
: call(function (source, options, results)
386387
results[#results+1] = {
387-
start = source.start,
388-
finish = source.finish,
389-
type = define.TokenTypes.comment,
388+
start = source.start,
389+
finish = source.finish,
390+
type = define.TokenTypes.class,
390391
}
391392
end)
392393
: case 'doc.type.name'
393394
: call(function (source, options, results)
394395
if source.typeGeneric then
396+
results[#results+1] = {
397+
start = source.start,
398+
finish = source.finish,
399+
type = define.TokenTypes.type,
400+
modifieres = define.TokenModifiers.modification,
401+
}
402+
else
395403
results[#results+1] = {
396404
start = source.start,
397405
finish = source.finish,
398-
type = define.TokenTypes.macro,
406+
type = define.TokenTypes.type,
407+
}
408+
end
409+
end)
410+
: case 'doc.alias.name'
411+
: call(function (source, options, results)
412+
results[#results+1] = {
413+
start = source.start,
414+
finish = source.finish,
415+
type = define.TokenTypes.macro,
416+
}
417+
end)
418+
: case 'doc.param.name'
419+
: call(function (source, options, results)
420+
results[#results+1] = {
421+
start = source.start,
422+
finish = source.finish,
423+
type = define.TokenTypes.parameter,
424+
}
425+
end)
426+
: case 'doc.field'
427+
: call(function (source, options, results)
428+
if source.visible then
429+
results[#results+1] = {
430+
start = source.start,
431+
finish = source.start + #source.visible,
432+
type = define.TokenTypes.keyword,
399433
}
400434
end
401435
end)
436+
: case 'doc.field.name'
437+
: call(function (source, options, results)
438+
results[#results+1] = {
439+
start = source.start,
440+
finish = source.finish,
441+
type = define.TokenTypes.property,
442+
modifieres = define.TokenModifiers.declaration,
443+
}
444+
end)
445+
: case 'doc.return.name'
446+
: call(function (source, options, results)
447+
results[#results+1] = {
448+
start = source.start,
449+
finish = source.finish,
450+
type = define.TokenTypes.parameter,
451+
}
452+
end)
453+
: case 'doc.generic.name'
454+
: call(function (source, options, results)
455+
results[#results+1] = {
456+
start = source.start,
457+
finish = source.finish,
458+
type = define.TokenTypes.type,
459+
modifieres = define.TokenModifiers.modification,
460+
}
461+
end)
462+
: case 'doc.type.function'
463+
: call(function (source, options, results)
464+
results[#results+1] = {
465+
start = source.start,
466+
finish = source.start + #'fun',
467+
type = define.TokenTypes.keyword,
468+
}
469+
if source.async then
470+
results[#results+1] = {
471+
start = source.asyncPos,
472+
finish = source.asyncPos + #'async',
473+
type = define.TokenTypes.keyword,
474+
modifieres = define.TokenModifiers.async,
475+
}
476+
end
477+
end)
478+
: case 'doc.type.arg.name'
479+
: call(function (source, options, results)
480+
results[#results+1] = {
481+
start = source.start,
482+
finish = source.finish,
483+
type = define.TokenTypes.parameter,
484+
modifieres = define.TokenModifiers.declaration,
485+
}
486+
end)
487+
: case 'doc.tailcomment'
488+
: call(function (source, options, results)
489+
results[#results+1] = {
490+
start = source.start,
491+
finish = source.finish,
492+
type = define.TokenTypes.comment,
493+
}
494+
end)
402495
: case 'nonstandardSymbol.comment'
403496
: call(function (source, options, results)
404497
results[#results+1] = {
@@ -559,11 +652,26 @@ return function (uri, start, finish)
559652
end)
560653

561654
for _, comm in ipairs(state.comms) do
562-
results[#results+1] = {
563-
start = comm.start,
564-
finish = comm.finish,
565-
type = define.TokenTypes.comment,
566-
}
655+
if comm.type == 'comment.short'
656+
and comm.text:sub(1, 2) == '-@' then
657+
results[#results+1] = {
658+
start = comm.start,
659+
finish = comm.start + 3,
660+
type = define.TokenTypes.comment,
661+
}
662+
results[#results+1] = {
663+
start = comm.start + 3,
664+
finish = comm.start + 2 + #comm.text:match '%S+',
665+
type = define.TokenTypes.comment,
666+
modifieres = define.TokenModifiers.documentation,
667+
}
668+
else
669+
results[#results+1] = {
670+
start = comm.start,
671+
finish = comm.finish,
672+
type = define.TokenTypes.comment,
673+
}
674+
end
567675
end
568676

569677
if #results == 0 then

script/parser/guide.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ local childMap = {
141141
['doc.type.function'] = {'#args', '#returns', 'comment'},
142142
['doc.type.ltable'] = {'#fields', 'comment'},
143143
['doc.type.literal'] = {'node'},
144-
['doc.type.arg'] = {'extends'},
144+
['doc.type.arg'] = {'name', 'extends'},
145145
['doc.type.field'] = {'extends'},
146146
['doc.overload'] = {'overload', 'comment'},
147147
['doc.see'] = {'name', 'field'},

script/parser/luadoc.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ local function parseTypeUnitFunction()
368368
type = 'doc.type.arg',
369369
parent = typeUnit,
370370
}
371-
arg.name = parseName('doc.type.name', arg)
372-
or parseDots('doc.type.name', arg)
371+
arg.name = parseName('doc.type.arg.name', arg)
372+
or parseDots('doc.type.arg.name', arg)
373373
if not arg.name then
374374
pushWarning {
375375
type = 'LUADOC_MISS_ARG_NAME',
@@ -484,13 +484,15 @@ local parseTypeUnit
484484

485485
local function parseDocFunction(parent, content)
486486
if content == 'async' then
487+
local pos = getStart()
487488
local tp, cont = peekToken()
488489
if tp == 'name' then
489490
if cont == 'fun' then
490491
nextToken()
491492
local func = parseTypeUnit(parent, cont)
492493
if func then
493494
func.async = true
495+
func.asyncPos = pos
494496
return func
495497
end
496498
end

0 commit comments

Comments
 (0)