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§

CaretRect
Where an editor draws its caret, as the Renderer reported it.
CodeChange
One committed edit, as the Renderer reported it.
CodeEditorColors
The colours of an editor’s own parts, each a role of the theme.
CodeHover
A pointer came to rest over a place in the editor, or left it.
CodeMetrics
How an editor’s rows are drawn, as the Renderer measured them.
CodePointer
A pointer event over a code editor, with the place in the text under the pointer.
CodeRange
A stretch of the document from start up to, and not including, end.
CodeRect
A rectangle on screen, in the dp the window lays its content out in.
CodeScroll
How far an editor is scrolled.
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.
EditGroupResult
What became of one grouped edit, as the Renderer reported it.
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.
SelectionsChange
Every selection of a code editor, as the Renderer reported it: sent while there is more than one, and once more when it comes back to one. The first is the primary selection, the one SelectionChange goes on reporting by itself.
SyntaxSpan
One colour run of the syntax.
SyntaxSpans
The colour runs of one editor’s syntax, encoded and ready to travel.
ViewZone
Room after a line that is not text: the blank rows a diff leaves on one side to line it up with the other, or a note between two lines.
ViewZones
The view zones of one editor, 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.
WordWrap
Where a code editor breaks a line too long for it onto the rows below.

Constants§

CODE_EDITOR_COLORS_LEN
Bytes of a code editor’s colour record.
CODE_EDITOR_COLORS_RECORD
The colours an application gives an editor: a role for the container, the gutter, a line number, the current line’s number and the current line. Zero leaves that part to the design system. Bytes 10 and 11 are reserved and written as zero.
CODE_EDIT_LEN
Bytes of one edit record inside a grouped edit: the range as four u32, then the text’s (offset, length).
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.
SELECTION_LEN
Bytes of one selection in a list of them: the anchor’s line and column, then the active end’s.
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.
VIEW_ZONE_LEN
Bytes of one view zone record.
VIEW_ZONE_RECORD
One view zone: the line it follows, its height in rows and the text it shows dimmed, which lies behind the records like a decoration’s.

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.
decode_edit_group
Reads back the edits encode_edit_group wrote, in the order they were sent.
decode_selections
Reads back the selections encode_selections wrote, or None where the bytes are not whole selections.
encode_edit_group
Encodes the edits of one grouped edit the way EditCodeGroup carries them, appending to out.
encode_selections
Encodes selections the way SetSelections and SelectionsChanged carry them, each an anchor and an active end, appending to out.
escape_snippet_text
text as snippet text that stands for itself: a backslash in front of every $, } and \\, so a name taken from the document cannot open a tab stop of its own when it is put inside a snippet.
position_query
Numbers one question about where a position of an editor is on screen, and keeps on_answer until the answer arrives.

Type Aliases§

PositionAnswer
What a position query is answered with: the rectangle a caret at that position would be drawn in, or None where the position is not on screen.