Skip to main content

Module code

Module code 

Source
Expand description

A code editor’s document as the Host sees it.

The Renderer owns the text. It owns the caret, the selection, the scroll position, the undo history and the composition an input method is building, for the same reason a text field owns them: a round trip to this side per keystroke would add a frame of latency to every key. What the Host gets is each committed edit, in order, with the version of the document it produced, which is exactly what a language server or an extension host needs to follow along.

What the Host says back is said as ranges. Colour runs for the syntax and decorations for diagnostics, lenses, hover anchors and inline suggestions, each a blob of fixed-length records carrying the document version its ranges were written against. The Renderer moves them along with whatever the reader typed since, so a list that took a language server a second to compute still lands on the text it was about.

Positions are a line and a column counted from zero, and a column counts UTF-16 code units. That is the unit a language server and VS Code count in, and any other unit would make every application recount every range on the way through. A line ends at \n, \r\n or a lone \r, which is also the language server’s rule.

Structs§

CodeChange
One committed edit, as the Renderer reported it.
CodeHover
A pointer came to rest over a place in the editor, or left it.
CodeRange
A stretch of the document from start up to, and not including, end.
Decoration
One thing drawn over the document, said as a range and never as a picture.
Decorations
The decorations over one editor, encoded and ready to travel.
EditRejected
A Host edit the Renderer did not apply, because the reader had changed the same place since the version the edit was written against.
Fold
One stretch of lines the reader can fold.
FoldChange
The reader folded or unfolded a stretch of a code editor.
Folds
The stretches of one editor that can be folded, encoded and ready to travel.
GutterDecoration
One mark beside a line number, said as a line and never as a picture.
GutterDecorations
The marks beside the line numbers of one editor, encoded and ready to travel.
Position
A place in the document: a line and a column, both from zero, the column in UTF-16 code units.
RecordField
One field of a fixed-length record, at the byte it starts at.
RecordSchema
A fixed-length record that travels inside a property’s blob.
SaveRequest
The reader pressed the save shortcut: Command S on macOS, Control S elsewhere.
SelectionChange
The selection of a code editor, as the Renderer reported it.
SyntaxSpan
One colour run of the syntax.
SyntaxSpans
The colour runs of one editor’s syntax, encoded and ready to travel.
VisibleRange
The lines of a code editor that are on screen.

Enums§

RecordFieldType
What one field of a code editor record holds.

Constants§

DECORATION_LEN
Bytes of one decoration record.
DECORATION_RECORD
One decoration: a version, a kind, a severity and a colour role, a range, the id the application gave it, and the text a lens or a suggestion shows. Bytes 10 and 11 are reserved and written as zero.
FOLD_LEN
Bytes of one fold record.
FOLD_RECORD
One stretch of lines that can be folded: a version, the line it starts on, the last line it covers and whether it is folded now. Folding keeps start_line and hides the lines after it up to end_line.
GUTTER_DECORATION_LEN
Bytes of one gutter decoration record.
GUTTER_DECORATION_RECORD
One mark beside the line numbers: a version, the line, what it looks like, an optional colour role, the id the application gave it and the character a glyph shows. Bytes 24 to 27 are reserved and written as zero.
SYNTAX_SPAN_LEN
Bytes of one syntax colour run record.
SYNTAX_SPAN_RECORD
One colour run of the syntax: a version, a range and the paint it is drawn in.

Functions§

byte_offset
Where a position falls in text, as a byte offset, or None where the document has no such place: a line past the last one, a column past the end of its line, or a column that would split a character written as two UTF-16 units.