Skip to content

Commit 065bb29

Browse files
nixel2007claude
andcommitted
Unify directive punctuation, keyword, and parent into one highlight tag
Previously '&НаКлиенте' rendered as two adjacent spans (yellow '&' from Annotation/"&" → t.annotation, but red 'НаКлиенте' because the global 'Identifier: t.variableName' won over 'Annotation/AnnotationName' at the leaf level — @lezer/highlight resolves leaf tags first, ignoring parent matches that didn't reach down to the leaf). Same problem with every preprocessor directive: the wrapper tag never reached the inner keyword. Fix: - AnnotationName/Identifier now also tagged t.annotation so the leaf Identifier inherits the annotation colour and 'НаКлиенте' merges into the same span as '&'. - Preprocessor mapping rewritten per bsl-language-server semantics: Namespace bucket (Region, EndRegion, PreprocUseDirective + their '#' and inner keyword) so '#Область' renders as one yellow block; Macro bucket (PreprocessorIf/Elsif/Else/EndIf, PreprocessorDelete/ EndDelete/Insert/EndInsert, PreprocNativeDirective + their '#' and inner BSL-keyword surfaces) so '#Если' renders as one coral block. - Single-quoted keys in JS used so the literal '"&"' / '"#"' path syntax — required by @lezer/highlight to reference non-identifier- shaped tokens in path positions — is unambiguous. Verified by inspecting prod DOM: CodeMirror's adjacent-span merging turns each directive into a single coloured run. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 12d7b34 commit 065bb29

1 file changed

Lines changed: 30 additions & 18 deletions

File tree

src/index.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -250,28 +250,40 @@ export const bslLanguage = LRLanguage.define({
250250
"PropertyAccess/dotKeyword CallAccess/dotKeyword": t.propertyName,
251251

252252
// ---- Annotations (compiler directives like &НаКлиенте) ----
253-
// The `&` punctuation is tagged together with the annotation name so
254-
// theming treats `&НаКлиенте` as one visual unit instead of leaving
255-
// the `&` painted as ordinary punctuation.
256-
"Annotation/AnnotationName Annotation/&": t.annotation,
253+
// Every leaf token of an annotation gets `t.annotation` so the whole
254+
// `&Имя` reads as one visual unit. The `AnnotationName/Identifier`
255+
// selector is needed because @lezer/highlight resolves tags at the
256+
// leaf level — a parent-only `AnnotationName: t.annotation` would
257+
// lose against the global `Identifier: t.variableName`. The quoted
258+
// `"&"` form is the only way to reference a non-identifier-shaped
259+
// literal inside a path selector.
260+
'Annotation/AnnotationName AnnotationName/Identifier Annotation/"&"': t.annotation,
257261

258262
// ---- Preprocessor ----
259-
// bsl-language-server: #Использовать and #Область → Namespace,
260-
// other directives (#Если/#КонецЕсли/...) → Macro,
261-
// region name → Variable (we already tag Identifier → variableName).
262-
"PreprocUse PreprocNative": t.namespace,
263-
"PreprocRegion PreprocEndRegion": t.namespace,
264-
"PreprocDelete PreprocEndDelete PreprocInsert PreprocEndInsert": t.macroName,
265-
// Preprocessor #Если/.../КонецЕсли — shared BSL keyword terms,
266-
// discriminated as macros only when sitting inside a preproc directive.
267-
"PreprocessorIf/If PreprocessorIf/Then PreprocessorElsif/Elsif PreprocessorElsif/Then PreprocessorElse/Else PreprocessorEndIf/EndIf PreprocessorIf/Not PreprocessorElsif/Not PreprocessorIf/And PreprocessorElsif/And PreprocessorIf/Or PreprocessorElsif/Or": t.macroName,
268-
// `#` punctuation in every preprocessor variant is re-tagged as
269-
// processingInstruction so it sits in the same colour bucket as the
270-
// surrounding directive instead of being left as bare punctuation.
271-
"PreprocessorIf/# PreprocessorElsif/# PreprocessorElse/# PreprocessorEndIf/# Region/# EndRegion/# PreprocessorDelete/# PreprocessorEndDelete/# PreprocessorInsert/# PreprocessorEndInsert/# PreprocUseDirective/# PreprocNativeDirective/#": t.processingInstruction,
263+
// Per bsl-language-server PreprocessorSemanticTokensSupplier:
264+
// • #Использовать and #Область/#КонецОбласти → Namespace
265+
// • #Если/#ИначеЕсли/#Иначе/#КонецЕсли, #native,
266+
// #Удаление/#Вставка → Macro
267+
// • Region name → Variable (kept as variableName from the global
268+
// Identifier rule)
269+
//
270+
// For every directive variant we tag the parent wrapper, the `#`
271+
// punctuation, and the directive keyword *all* with the same tag so
272+
// each directive renders as a single visual block. The leaf selectors
273+
// (PreprocRegion etc.) are needed because @lezer/highlight resolves
274+
// at the leaf — parent-only tags lose against any leaf rule.
275+
276+
// Namespace bucket — regions and use directive.
277+
'Region EndRegion PreprocUseDirective Region/"#" EndRegion/"#" PreprocUseDirective/"#" PreprocRegion PreprocEndRegion PreprocUse': t.namespace,
278+
279+
// Macro bucket — conditional directives, native, configuration-
280+
// extension markers. The `Preprocessor*/If` etc. selectors retag
281+
// BSL control-flow terms that share their surface form with
282+
// preprocessor keywords.
283+
'PreprocessorIf PreprocessorElsif PreprocessorElse PreprocessorEndIf PreprocessorDelete PreprocessorEndDelete PreprocessorInsert PreprocessorEndInsert PreprocNativeDirective PreprocessorIf/"#" PreprocessorElsif/"#" PreprocessorElse/"#" PreprocessorEndIf/"#" PreprocessorDelete/"#" PreprocessorEndDelete/"#" PreprocessorInsert/"#" PreprocessorEndInsert/"#" PreprocNativeDirective/"#" PreprocessorIf/If PreprocessorIf/Then PreprocessorElsif/Elsif PreprocessorElsif/Then PreprocessorElse/Else PreprocessorEndIf/EndIf PreprocessorIf/Not PreprocessorElsif/Not PreprocessorIf/And PreprocessorElsif/And PreprocessorIf/Or PreprocessorElsif/Or PreprocDelete PreprocEndDelete PreprocInsert PreprocEndInsert PreprocNative': t.macroName,
284+
272285
ShebangLine: t.processingInstruction,
273286
"Region/RegionName": t.variableName,
274-
"Region EndRegion PreprocessorIf PreprocessorElsif PreprocessorElse PreprocessorEndIf PreprocessorDelete PreprocessorEndDelete PreprocessorInsert PreprocessorEndInsert PreprocUseDirective PreprocNativeDirective Shebang": t.processingInstruction,
275287

276288
// ---- Punctuation and operators ----
277289
// Punctuation literals are tagged via their wrapping named nodes

0 commit comments

Comments
 (0)