Skip to content

Commit 33a6d8c

Browse files
committed
Add Or_Branch_Expr to semantic tokens
1 parent 99b2b6d commit 33a6d8c

File tree

1 file changed

+48
-39
lines changed

1 file changed

+48
-39
lines changed

src/server/semantic_tokens.odin

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ package server
99

1010
import "core:fmt"
1111
import "core:log"
12-
import "core:unicode/utf8"
1312
import "core:odin/ast"
1413
import "core:odin/tokenizer"
14+
import "core:unicode/utf8"
1515

1616
import "src:common"
1717

@@ -68,7 +68,7 @@ semantic_token_modifier_names: []string = {
6868
"deprecated",
6969
"readonly",
7070
}
71-
SemanticTokenModifiers :: bit_set[SemanticTokenModifier; u32]
71+
SemanticTokenModifiers :: bit_set[SemanticTokenModifier;u32]
7272

7373
SemanticTokensClientCapabilities :: struct {
7474
requests: struct {
@@ -179,13 +179,7 @@ write_semantic_node :: proc(
179179

180180
name := common.get_ast_node_string(node, builder.src)
181181

182-
write_semantic_at_pos(
183-
builder,
184-
node.pos.offset,
185-
len(name),
186-
type,
187-
modifiers,
188-
)
182+
write_semantic_at_pos(builder, node.pos.offset, len(name), type, modifiers)
189183
}
190184

191185
write_semantic_token :: proc(
@@ -295,11 +289,7 @@ visit_node :: proc(node: ^ast.Node, builder: ^SemanticTokenBuilder) {
295289
visit_node(n.expr, builder)
296290
visit_nodes(n.args, builder)
297291
case ^Implicit_Selector_Expr:
298-
write_semantic_node(
299-
builder,
300-
n.field,
301-
.EnumMember,
302-
)
292+
write_semantic_node(builder, n.field, .EnumMember)
303293
case ^Array_Type:
304294
visit_node(n.len, builder)
305295
visit_node(n.elem, builder)
@@ -360,6 +350,9 @@ visit_node :: proc(node: ^ast.Node, builder: ^SemanticTokenBuilder) {
360350
case ^Or_Else_Expr:
361351
visit_node(n.x, builder)
362352
visit_node(n.y, builder)
353+
case ^ast.Or_Branch_Expr:
354+
visit_node(n.expr, builder)
355+
visit_node(n.label, builder)
363356
case ^Ternary_If_Expr:
364357
if n.op1.text == "if" {
365358
visit_node(n.x, builder)
@@ -394,11 +387,15 @@ visit_node :: proc(node: ^ast.Node, builder: ^SemanticTokenBuilder) {
394387
}
395388
}
396389

397-
visit_value_decl :: proc(value_decl: ast.Value_Decl, builder: ^SemanticTokenBuilder) {
390+
visit_value_decl :: proc(
391+
value_decl: ast.Value_Decl,
392+
builder: ^SemanticTokenBuilder,
393+
) {
398394
using ast
399395

400-
modifiers: SemanticTokenModifiers = value_decl.is_mutable ? {} : {.ReadOnly}
401-
396+
modifiers: SemanticTokenModifiers =
397+
value_decl.is_mutable ? {} : {.ReadOnly}
398+
402399
for name in value_decl.names {
403400
ident := name.derived.(^Ident) or_continue
404401
visit_ident(ident, ident, modifiers, builder)
@@ -438,7 +435,10 @@ visit_proc_type :: proc(node: ^ast.Proc_Type, builder: ^SemanticTokenBuilder) {
438435
}
439436
}
440437

441-
visit_enum_fields :: proc(node: ast.Enum_Type, builder: ^SemanticTokenBuilder) {
438+
visit_enum_fields :: proc(
439+
node: ast.Enum_Type,
440+
builder: ^SemanticTokenBuilder,
441+
) {
442442
using ast
443443

444444
if node.fields == nil {
@@ -457,7 +457,10 @@ visit_enum_fields :: proc(node: ast.Enum_Type, builder: ^SemanticTokenBuilder) {
457457
}
458458
}
459459

460-
visit_struct_fields :: proc(node: ast.Struct_Type, builder: ^SemanticTokenBuilder) {
460+
visit_struct_fields :: proc(
461+
node: ast.Struct_Type,
462+
builder: ^SemanticTokenBuilder,
463+
) {
461464
if node.fields == nil {
462465
return
463466
}
@@ -473,7 +476,10 @@ visit_struct_fields :: proc(node: ast.Struct_Type, builder: ^SemanticTokenBuilde
473476
}
474477
}
475478

476-
visit_bit_field_fields :: proc(node: ast.Bit_Field_Type, builder: ^SemanticTokenBuilder) {
479+
visit_bit_field_fields :: proc(
480+
node: ast.Bit_Field_Type,
481+
builder: ^SemanticTokenBuilder,
482+
) {
477483
if node.fields == nil {
478484
return
479485
}
@@ -488,7 +494,10 @@ visit_bit_field_fields :: proc(node: ast.Bit_Field_Type, builder: ^SemanticToken
488494
}
489495
}
490496

491-
visit_selector :: proc(selector: ^ast.Selector_Expr, builder: ^SemanticTokenBuilder) {
497+
visit_selector :: proc(
498+
selector: ^ast.Selector_Expr,
499+
builder: ^SemanticTokenBuilder,
500+
) {
492501
if v, ok := selector.expr.derived.(^ast.Selector_Expr); ok {
493502
visit_selector(v, builder)
494503
} else {
@@ -499,7 +508,10 @@ visit_selector :: proc(selector: ^ast.Selector_Expr, builder: ^SemanticTokenBuil
499508
visit_ident(selector.field, selector, {}, builder)
500509
}
501510

502-
visit_import_decl :: proc(decl: ^ast.Import_Decl, builder: ^SemanticTokenBuilder) {
511+
visit_import_decl :: proc(
512+
decl: ^ast.Import_Decl,
513+
builder: ^SemanticTokenBuilder,
514+
) {
503515
/*
504516
hightlight the namespace in the import declaration
505517
@@ -515,16 +527,17 @@ visit_import_decl :: proc(decl: ^ast.Import_Decl, builder: ^SemanticTokenBuilder
515527

516528
if decl.name.text != "" {
517529
write_semantic_token(builder, decl.name, .Namespace)
518-
}
519-
else if len(decl.relpath.text) > 2 {
530+
} else if len(decl.relpath.text) > 2 {
520531

521532
end := len(decl.relpath.text) - 1
522533
pos := end
523534

524535
for {
525536
if pos > 1 {
526-
ch, w := utf8.decode_last_rune_in_string(decl.relpath.text[:pos])
527-
537+
ch, w := utf8.decode_last_rune_in_string(
538+
decl.relpath.text[:pos],
539+
)
540+
528541
switch ch {
529542
case ':', '/': // break
530543
case:
@@ -538,8 +551,8 @@ visit_import_decl :: proc(decl: ^ast.Import_Decl, builder: ^SemanticTokenBuilder
538551

539552
write_semantic_at_pos(
540553
builder,
541-
decl.relpath.pos.offset+pos,
542-
end-pos,
554+
decl.relpath.pos.offset + pos,
555+
end - pos,
543556
.Namespace,
544557
)
545558
}
@@ -584,15 +597,11 @@ visit_ident :: proc(
584597
switch v in symbol.value {
585598
case SymbolPackageValue:
586599
write_semantic_node(builder, ident, .Namespace, modifiers)
587-
case SymbolStructValue,
588-
SymbolBitFieldValue:
600+
case SymbolStructValue, SymbolBitFieldValue:
589601
write_semantic_node(builder, ident, .Struct, modifiers)
590-
case SymbolEnumValue,
591-
SymbolUnionValue:
602+
case SymbolEnumValue, SymbolUnionValue:
592603
write_semantic_node(builder, ident, .Enum, modifiers)
593-
case SymbolProcedureValue,
594-
SymbolProcedureGroupValue,
595-
SymbolAggregateValue:
604+
case SymbolProcedureValue, SymbolProcedureGroupValue, SymbolAggregateValue:
596605
write_semantic_node(builder, ident, .Function, modifiers)
597606
case SymbolMatrixValue,
598607
SymbolBitSetValue,
@@ -603,11 +612,11 @@ visit_ident :: proc(
603612
SymbolMultiPointer:
604613
write_semantic_node(builder, ident, .Type, modifiers)
605614
case SymbolBasicValue, SymbolUntypedValue:
606-
// handled by static syntax analysis
615+
// handled by static syntax analysis
607616
case SymbolGenericValue:
608-
// unused
617+
// unused
609618
case:
610-
// log.errorf("Unexpected symbol value: %v", symbol.value);
611-
// panic(fmt.tprintf("Unexpected symbol value: %v", symbol.value));
619+
// log.errorf("Unexpected symbol value: %v", symbol.value);
620+
// panic(fmt.tprintf("Unexpected symbol value: %v", symbol.value));
612621
}
613622
}

0 commit comments

Comments
 (0)