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§
- Code
Change - One committed edit, as the Renderer reported it.
- Code
Hover - A pointer came to rest over a place in the editor, or left it.
- Code
Range - A stretch of the document from
startup 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.
- 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.
- Syntax
Span - One colour run of the syntax.
- Syntax
Spans - The colour runs of one editor’s syntax, 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.
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_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.
- 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.