@@ -102,34 +102,38 @@ private void addDirectives(List<SemanticTokenEntry> entries, BSLParser.FileConte
102102 // excluding region start/end, native, use (handled as Namespace)
103103 private void addOtherPreprocs (List <SemanticTokenEntry > entries , BSLParser .FileContext ast ) {
104104 for (var preprocessor : Trees .<BSLParser .PreprocessorContext >findAllRuleNodes (ast , BSLParser .RULE_preprocessor )) {
105- boolean containsRegion = (preprocessor .regionStart () != null ) || (preprocessor .regionEnd () != null );
105+ var containsRegion = (preprocessor .regionStart () != null ) || (preprocessor .regionEnd () != null );
106106 if (containsRegion ) {
107107 continue ; // region handled as Namespace above
108108 }
109109
110- // Find HASH token and keyword tokens to combine them into single token
111- Token hashToken = null ;
112- boolean firstKeywordCombined = false ;
110+ addOtherPreprocs ( entries , preprocessor );
111+ }
112+ }
113113
114- for (Token token : Trees .getTokens (preprocessor )) {
115- if (token .getChannel () != Token .DEFAULT_CHANNEL ) {
116- continue ;
117- }
118- if (token .getType () == BSLLexer .HASH ) {
119- hashToken = token ;
120- } else {
121- String symbolicName = BSLLexer .VOCABULARY .getSymbolicName (token .getType ());
122- if (symbolicName != null && symbolicName .startsWith ("PREPROC_" )) {
123- // Track keyword tokens for combining with HASH
124- if (hashToken != null && !firstKeywordCombined ) {
125- // First keyword after HASH - combine them into single token
126- helper .addRange (entries , Ranges .create (hashToken , token ), SemanticTokenTypes .Macro );
127- firstKeywordCombined = true ;
128- } else {
129- // Subsequent keywords (e.g., "Сервер", "Тогда" in "#Если Сервер Тогда")
130- // or keyword without preceding HASH (shouldn't happen in valid syntax)
131- helper .addRange (entries , Ranges .create (token ), SemanticTokenTypes .Macro );
132- }
114+ private void addOtherPreprocs (List <SemanticTokenEntry > entries , BSLParser .PreprocessorContext preprocessor ) {
115+ // Find HASH token and keyword tokens to combine them into single token
116+ Token hashToken = null ;
117+ var firstKeywordCombined = false ;
118+
119+ for (Token token : Trees .getTokens (preprocessor )) {
120+ if (token .getChannel () != Token .DEFAULT_CHANNEL ) {
121+ continue ;
122+ }
123+ if (token .getType () == BSLLexer .HASH ) {
124+ hashToken = token ;
125+ } else {
126+ var symbolicName = BSLLexer .VOCABULARY .getSymbolicName (token .getType ());
127+ if (symbolicName != null && symbolicName .startsWith ("PREPROC_" )) {
128+ // Track keyword tokens for combining with HASH
129+ if (hashToken != null && !firstKeywordCombined ) {
130+ // First keyword after HASH - combine them into single token
131+ helper .addRange (entries , Ranges .create (hashToken , token ), SemanticTokenTypes .Macro );
132+ firstKeywordCombined = true ;
133+ } else {
134+ // Subsequent keywords (e.g., "Сервер", "Тогда" in "#Если Сервер Тогда")
135+ // or keyword without preceding HASH (shouldn't happen in valid syntax)
136+ helper .addRange (entries , Ranges .create (token ), SemanticTokenTypes .Macro );
133137 }
134138 }
135139 }
0 commit comments