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§
- Caret
Rect - Where an editor draws its caret, as the Renderer reported it.
- Code
Change - One committed edit, as the Renderer reported it.
- Code
Editor Colors - The colours of an editor’s own parts, each a role of the theme.
- Code
Hover - A pointer came to rest over a place in the editor, or left it.
- Code
Metrics - How an editor’s rows are drawn, as the Renderer measured them.
- Code
Pointer - A pointer event over a code editor, with the place in the text under the pointer.
- Code
Range - A stretch of the document from
startup to, and not including,end. - Code
Rect - A rectangle on screen, in the dp the window lays its content out in.
- Code
Scroll - 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.
- Edit
Group Result - What became of one grouped edit, as the Renderer reported it.
- Edit
Rejected - 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.
- Fold
Change - 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.
- Gutter
Decoration - One mark beside a line number, said as a line and never as a picture.
- Gutter
Decorations - 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.
- Record
Field - One field of a fixed-length record, at the byte it starts at.
- Record
Schema - A fixed-length record that travels inside a property’s blob.
- Save
Request - The reader pressed the save shortcut: Command S on macOS, Control S elsewhere.
- Selection
Change - The selection of a code editor, as the Renderer reported it.
- Selections
Change - 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
SelectionChangegoes on reporting by itself. - Syntax
Span - One colour run of the syntax.
- Syntax
Spans - The colour runs of one editor’s syntax, encoded and ready to travel.
- View
Zone - 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.
- View
Zones - The view zones of one editor, encoded and ready to travel.
- Visible
Range - The lines of a code editor that are on screen.
Enums§
- Record
Field Type - What one field of a code editor record holds.
- Word
Wrap - 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_lineand hides the lines after it up toend_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_groupwrote, in the order they were sent. - decode_
selections - Reads back the selections
encode_selectionswrote, or None where the bytes are not whole selections. - encode_
edit_ group - Encodes the edits of one grouped edit the way
EditCodeGroupcarries them, appending toout. - encode_
selections - Encodes selections the way
SetSelectionsandSelectionsChangedcarry them, each an anchor and an active end, appending toout. - escape_
snippet_ text textas 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_answeruntil the answer arrives.
Type Aliases§
- Position
Answer - 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.