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

LSP Protocol

Status: Current Last updated: 2026-04-16 22:12 EDT

This chapter documents all Language Server Protocol capabilities advertised by chatter-lsp. The capability set is declared in crates/chatter-lsp/src/backend/capabilities.rs via build_initialize_result(). Per-feature handlers live under backend/features/ (request-agnostic feature code) and backend/requests/ (request-dispatcher shims that pull out the parts of Backend each handler needs).

The twelve custom talkbank/* commands (also advertised through this mechanism) have their own per-endpoint reference at RPC Contracts; this chapter stays focused on the standard LSP surface.

Advertised Capabilities

The server advertises 23 standard LSP capabilities plus 12 custom commands.

Text Document Sync

CapabilityModeDescription
Text document syncIncrementalReceives incremental edits (not full document re-sends)

Text Document Features

CapabilityHandlerDescription
Hoverfeatures/hover.rsCross-tier alignment display for main, %mor, %gra, %pho, %sin tiers. Also covers headers and timing bullets.
Completionfeatures/completion.rsSpeaker codes from @Participants, tier prefixes, postcode suffixes, header names, bracket annotations. Triggers on *, %, +, @, [.
Definitionrequests/goto_definition.rsNavigate from speaker code to @Participants declaration, from dependent tier to aligned main tier word (chunks → host items via MorTier::item_index_of_chunk).
Referencesfeatures/references.rsFind all occurrences of a speaker code across @Participants, @ID headers, and main tier lines.
Document Highlightfeatures/highlights/Bidirectional cross-tier alignment highlighting. Click a word on any tier to highlight aligned items on all other tiers.
Document Symbolfeatures/document_symbol.rsTwo-level outline: transcript as Module, per-utterance String symbols labeled by speaker. Powers Cmd+Shift+O and the Outline view.
Code Actionfeatures/code_action.rsQuick fixes for 21 error codes (E241, E242, E244, E258, E259, E301, E305, E306, E308, E312, E313, E322, E323, E362, E501-E504, E506, E507, E604).
Formattingrequests/formatting.rsRe-serializes the document through the canonical CHAT serializer.
On-Type Formattingfeatures/on_type_formatting.rsAuto-inserts leading tab on continuation lines after tier prefix. Trigger character: :.
Renamefeatures/rename.rsRename speaker code across @Participants, @ID headers, and all main tier lines. Supports prepare rename.
Code Lensfeatures/code_lens.rsUtterance counts per speaker above @Participants (e.g., “CHI: 42 utterances”).
Semantic Tokenssemantic_tokens.rsFull and range-based semantic tokens. 11 token types (keyword, variable, string, comment, type, operator, number, function, tag, punctuation, error).
Diagnosticdiagnostics/Push (publishDiagnostics) and pull (textDocument/diagnostic, workspace/diagnostic) models.
Selection Rangefeatures/selection_range.rsSmart expand/shrink: word to utterance content to tier block to transcript.
Linked Editing Rangefeatures/linked_editing.rsSimultaneous editing of matching speaker codes.
Document Linkfeatures/document_link.rsMakes @Media: header values clickable links.
Folding Rangefeatures/folding_range.rsFold utterance blocks (main tier + dependent tiers) and the header block.
Inlay Hintfeatures/inlay_hints.rsAlignment count mismatch hints (e.g., [alignment: 3 main <> 2 mor]).

Workspace Features

CapabilityHandlerDescription
Workspace Symbolfeatures/workspace_symbol.rsCross-file search by speaker code and utterance content.
Did Change Configurationbackend/mod.rsResponds to settings changes from the client.

Execute Command

The server advertises 12 custom commands via workspace/executeCommand (the talkbank/* family). Per-endpoint reference: RPC Contracts. Architecture and sequence-diagram: Custom Commands.

Error contract

Feature handlers inside chatter-lsp return Result<_, LspBackendError> rather than stringly Result<_, String>. LspBackendError (backend/error.rs) is a thiserror enum with variants for tier/alignment state (MissingTier { tier: TierName }, TierAlignmentMissing { tier: TierName }, AlignmentMetadataMissing), document state (DocumentNotFound, JsonSerializeFailed(#[from] serde_json::Error)), parse state (ParseFailure { count, first_message }), executeCommand argument decoding (ArgumentMissing, ArgumentInvalid, InvalidUriParse, UriNotFilePath), regex (InvalidRegex), init failure (LanguageServicesUnavailable(#[from] BackendInitError)), external service failure (ExternalServiceFailed), and a wrapper for graph-specific failures (Graph(#[from] GraphEdgeError)).

Handlers that return typed errors get collapsed to the tower-lsp string form only at the protocol boundary (requests/*.rs). This means every feature can match on its classification without parsing free-form text.

Completion Trigger Characters

The completion provider activates on these trigger characters:

CharacterWhat it completes
*Speaker codes from @Participants
%Dependent tier prefixes (mor, gra, pho, sin, etc.)
+Postcode punctuation suffixes
@Header names (@Participants, @ID, @Languages, etc.)
[Bracket annotations

Semantic Token Types

The semantic tokens provider uses 11 token types, mapped to VS Code’s theme colors:

IndexTypeUsed For
0keywordHeaders (@Begin, @End), tier prefixes
1variableSpeaker codes (*CHI, *MOT)
2stringQuoted strings, word content
3commentComment lines
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

Semantic tokens are computed on every request (full or range-based). The TextMate grammar (chat.tmLanguage.json) provides fallback highlighting before the LSP finishes starting.

Diagnostic Tags

The server uses LSP diagnostic tags for visual de-emphasis:

TagUsed For
UnnecessaryEmpty utterances, empty colons – shown with fade-out styling
DeprecatedDeprecated CHAT constructs