Expand description
What an editor asks the front end, and the answers, once.
docs/04-compiler-architecture.md §4.6 fixes
the rule this module exists to keep: “One binary serves beck build, beck check, beck lsp
and beck explain; there is no separate language server implementation to drift.” Until now
that was true of the compiler and not of the editor: beck lsp held the indexing, the
positions and the word-under-the-caret rule, and anything else wanting them — a playground with
a <textarea> in it (docs/98 §98.9) — had to
write them a second time.
So the answers live here, where beck-cli and a wasm32-unknown-unknown module can both reach
them, and neither renders anything of its own:
| Answer | What produces it |
|---|---|
tokens — highlighting | beck_syntax::lexer::lex and beck_syntax::lexer::KEYWORDS |
Editor::marks — inline diagnostics | the diagnostics the checker pushed |
Editor::hover — a signature | crate::iface::render_item, the one beck iface writes |
Editor::completions — the names in scope | the checked program’s own definition table |
Editor::definition — where a name is declared | the span the checker recorded |
§Why the whole file, every time
An Editor is one compile. docs/64 §64.6
is why that is defensible today: the worst file in this tree costs 4.7 ms through parse, expand
and check, and the median costs 0.75 ms. tokens deliberately does not need one — a file
being typed into is usually a file that does not compile, and highlighting that waited for a
clean parse would go out whenever it was most wanted.
Structs§
- Completion
- One thing an editor can offer to finish the word being typed.
- Editor
- One document, analysed: what the front end made of the text the editor last sent.
- Hint
- One thing the compiler worked out and the source does not say.
- Index
- The names an analysis found, kept without the analysis.
- Mark
- One diagnostic, as an editor draws it: a byte range, a code and the text a terminal would print.
- Occurrence
- One place a name appears in the document.
- Symbol
- One name an editor can ask about.
- Token
- One coloured run: a byte range and what it is.
Enums§
- Completion
Kind - Hint
Kind - Refusal
- Why a rename will not happen.
- Symbol
Kind - Token
Kind - What a run of source is, for the purpose of colouring it.
Functions§
- byte_
of_ utf16 - The inverse: a UTF-16 offset back to a byte offset.
- byte_
offset - The inverse of
utf16_position: a line and UTF-16 character back to a byte offset. - marks
- Diagnostics as an editor draws them, for a caller that has the diagnostics and not an
Editor— the playground’s analysis has already compiled the text and is not going to do it twice. - message_
of - The message an editor shows, with the notes the terminal renderer would have printed.
- tokens
- Every coloured run in
text, in source order, non-overlapping. - utf16_
offset - A byte offset as a UTF-16 offset from the start of the text.
- utf16_
position - A byte offset as a zero-based line and UTF-16 character offset.
- word_at
- The identifier the cursor is inside or immediately after.