@@ -15,13 +15,17 @@ export class MacroSemantic {
15
15
private builder :SemanticTokensBuilder ;
16
16
private document : TextDocument ;
17
17
private customKeywords :CustomKeywords [ ] ;
18
-
19
- constructor ( ) { }
18
+ private prevLine = - 1 ;
19
+ private prevChar = - 1 ;
20
20
21
+ constructor ( ) { }
22
+
21
23
public doSemanticHighlighting ( document : TextDocument , macroFile : nodes . MacroFile , settings : LanguageSettings , range :Range | undefined ) : SemanticTokens {
22
24
this . builder = new SemanticTokensBuilder ( ) ;
23
25
this . document = document ;
24
26
this . customKeywords = settings . keywords ;
27
+ this . prevLine = - 1 ;
28
+ this . prevChar = - 1 ;
25
29
26
30
try {
27
31
let start :number ;
@@ -39,64 +43,62 @@ export class MacroSemantic {
39
43
return false ;
40
44
}
41
45
}
42
-
46
+
43
47
if ( candidate . symbol ) {
44
48
const symbol = candidate . symbol ;
45
49
if ( symbol . type === nodes . NodeType . Symbol ) {
46
50
switch ( symbol . valueType ) {
47
51
case nodes . NodeType . Numeric :
48
52
if ( symbol . attrib === nodes . ValueAttribute . Constant ) {
49
- this . build ( symbol , candidate . type , TokenTypes . constant ) ;
53
+ this . build ( symbol , nodes . NodeType . Symbol , TokenTypes . constant ) ;
50
54
}
51
55
else if ( symbol . attrib !== nodes . ValueAttribute . Program ) {
52
- this . build ( symbol , candidate . type , TokenTypes . number ) ;
56
+ this . build ( symbol , nodes . NodeType . Symbol , TokenTypes . number ) ;
53
57
}
54
58
break ;
55
59
case nodes . NodeType . Code :
56
- this . build ( symbol , symbol . type , TokenTypes . code ) ;
57
- break ;
60
+ this . build ( symbol , nodes . NodeType . Symbol , TokenTypes . code ) ;
61
+ break ;
58
62
case nodes . NodeType . Parameter :
59
- this . build ( symbol , symbol . type , TokenTypes . parameter ) ;
63
+ this . build ( symbol , nodes . NodeType . Symbol , TokenTypes . parameter ) ;
60
64
break ;
61
65
case nodes . NodeType . Statement :
62
66
if ( symbol . attrib === nodes . ValueAttribute . GCode || symbol . attrib === nodes . ValueAttribute . MCode ) {
63
- this . build ( symbol , symbol . type , TokenTypes . code ) ;
67
+ this . build ( symbol , nodes . NodeType . Symbol , TokenTypes . code ) ;
64
68
}
65
69
else {
66
- this . build ( symbol , symbol . type , TokenTypes . parameter ) ;
70
+ this . build ( symbol , nodes . NodeType . Symbol , TokenTypes . parameter ) ;
67
71
}
68
72
break ;
69
73
case nodes . NodeType . Address :
70
74
if ( symbol . attrib === nodes . ValueAttribute . GCode || symbol . attrib === nodes . ValueAttribute . MCode ) {
71
- this . build ( symbol , symbol . type , TokenTypes . code ) ;
75
+ this . build ( symbol , nodes . NodeType . Symbol , TokenTypes . code ) ;
72
76
}
73
77
else if ( symbol . attrib === nodes . ValueAttribute . Parameter ) {
74
- this . build ( symbol , symbol . type , TokenTypes . parameter ) ;
78
+ this . build ( symbol , nodes . NodeType . Symbol , TokenTypes . parameter ) ;
75
79
}
76
80
else {
77
- this . build ( symbol , symbol . type , TokenTypes . address ) ;
81
+ this . build ( symbol , nodes . NodeType . Symbol , TokenTypes . address ) ;
78
82
}
79
83
break ;
80
84
case nodes . NodeType . SequenceNumber :
81
- this . build ( symbol , symbol . type , TokenTypes . label ) ;
82
- break ;
85
+ this . build ( symbol , nodes . NodeType . Symbol , TokenTypes . label ) ;
86
+ break ;
83
87
case nodes . NodeType . Variable :
84
- this . build ( symbol , symbol . type , TokenTypes . macrovar ) ;
85
- break ;
86
- default :
87
- this . build ( symbol , symbol . type ) ;
88
+ this . build ( symbol , nodes . NodeType . Symbol , TokenTypes . macrovar ) ;
89
+ break ;
88
90
}
89
91
}
90
92
else if ( symbol . type === nodes . NodeType . Label ) {
91
- this . build ( candidate , candidate . type , TokenTypes . label ) ;
93
+ this . build ( symbol , nodes . NodeType . Label , TokenTypes . label ) ;
92
94
}
93
95
}
94
96
else if ( ! candidate . symbol ) {
95
97
if ( candidate . type === nodes . NodeType . Variable ) {
96
- this . build ( ( < nodes . Variable > candidate ) ?. body , candidate . type ) ;
98
+ this . build ( ( < nodes . Variable > candidate ) ?. body , nodes . NodeType . Variable ) ;
97
99
}
98
100
else if ( candidate . type === nodes . NodeType . Code ) {
99
- this . build ( candidate , candidate . type ) ;
101
+ this . build ( candidate , nodes . NodeType . Code ) ;
100
102
}
101
103
}
102
104
return true ;
@@ -124,7 +126,11 @@ export class MacroSemantic {
124
126
125
127
if ( token ) {
126
128
if ( node . type === nodes . NodeType . Symbol || node . type === nodes . NodeType . Label ) {
127
- this . builder . push ( pos . line , pos . character , node . getText ( ) . length , token , 0 ) ;
129
+ if ( this . prevLine !== pos . line || this . prevChar !== pos . character ) {
130
+ this . prevLine = pos . line ;
131
+ this . prevChar = pos . character ;
132
+ this . builder . push ( pos . line , pos . character , node . getText ( ) . length , token , 0 ) ;
133
+ }
128
134
}
129
135
else {
130
136
this . builder . push ( pos . line , pos . character , node . length , token , 0 ) ;
0 commit comments