Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Syntax Highlighting

Status: Current Last updated: 2026-03-30 13:40 EDT

The extension provides two layers of syntax highlighting for CHAT files: a TextMate grammar for immediate fallback coloring, and LSP semantic tokens for context-aware precision. Together they make CHAT transcripts readable at a glance, with distinct colors for headers, speaker codes, annotations, morphology, and other structural elements.

Two Highlighting Layers

TextMate Grammar (Fallback)

The TextMate grammar (syntaxes/chat.tmLanguage.json) provides basic token coloring that activates instantly when you open a .cha file, before the language server has finished starting. It uses pattern-matching rules to identify CHAT constructs by their textual form.

LSP Semantic Tokens (Context-Aware)

Once the language server is running, it provides semantic tokens that override the TextMate grammar with more precise coloring based on the parsed AST. For example, the semantic layer can distinguish specific POS tags in morphology, identify error-coded tokens, and differentiate between header types that look similar as raw text.

The language server advertises 11 semantic token types:

IndexToken TypeUsed For
0keywordHeaders (@Begin, @End, @UTF8), tier prefixes
1variableSpeaker codes (*CHI, *MOT, *INV)
2stringQuoted strings, word content
3commentComment lines (%com:)
4typeType annotations, complex structures
5operatorPostcodes, morphological separators (|, -, +, &)
6numberTiming values, indices
7functionDependent tier prefixes, special markers
8tagTier labels, annotation markers
9punctuationTerminators (. ? !), special punctuation
10errorSyntax errors, malformed tokens

Range-based semantic tokens are supported, computing tokens only for the visible range. This reduces work for large files.

Color Categories

The following table summarizes how CHAT elements are colored in the editor. Exact colors depend on your VS Code color theme, but the semantic categories are consistent:

ElementExamplesColor Category
Required headers@UTF8, @Begin, @EndBlue / bold keyword
Metadata headers@Participants, @ID, @LanguagesBlue / keyword
General headers@Date, @Location, custom headersBlue / keyword
Speaker codes*CHI:, *MOT:, *INV:Bold / variable color (distinct from headers)
Dependent tier prefixes%mor:, %gra:, %pho:Italic / function color
Utterance terminators. ? ! +/. +...Red / punctuation
Annotations[= text], [: alt], [*], [+ post]Green / string-operator
Scoped groups<word word>Bracket highlighting
Retrace markers[/], [//], [//?]Operator color
Actions and events&=laughs, &ClapsCyan / tag
Pauses(0.5), (.)Gray / number
Omissions0wordSpecial styling
Morphologyn|cookie, v|go-PROGPOS / stem / affix coloring
Grammar relations1|2|DET, 3|0|ROOTIndex / relation coloring
Comments%com: linesComment color (typically gray-green)

On-Type Formatting

When you type : on a *SPEAKER: or %tier: line, a tab character is automatically inserted after the colon. This matches the CHAT format convention where a tab always follows the colon on speaker and tier lines. No manual tab insertion is needed.

This behavior is provided by the language server’s textDocument/onTypeFormatting handler and works in real time as you type.

Document Formatting

Format the entire document to canonical CHAT style with Shift+Alt+F (or your configured format shortcut), or via the Command Palette (Format Document).

The formatter normalizes:

  • Whitespace and indentation
  • Header ordering
  • Speaker code formatting
  • Tier indentation (tabs after colons)
  • Line endings

If the document is already in canonical form, no changes are applied. You can also enable Format on Save via VS Code’s editor.formatOnSave setting to automatically normalize the file every time you save.

The formatting operation is backed by the language server’s textDocument/formatting handler, which serializes the document through the canonical CHAT serializer. This ensures the output matches the authoritative CHAT format exactly.