Skip to main content

Module table

Module table 

Source
Expand description

The three vocabularies that are not declarations: keywords, snippets and directives.

Everything else in completion is derived from the program — a scope’s bindings, an index’s facts, a class’s members. These three are the language’s own, and they are here rather than in the client because the client cannot know which of them fits: a keyword list offered after a . is noise, while is not a name, and a snippet’s placeholders are only worth inserting where a statement may be written.

KEYWORDS    the language's spelling, with the shape it fits (a statement, a type, a specifier)
SNIPPETS    a construct and its body, so that `if` writes the braces and puts the cursor in them
DIRECTIVES  the preprocessor's own names, offered after a `#`

§Why the tables are keyed by &'static str and read linearly

There are eighty-odd keywords, twenty snippets and fourteen directives. A completion is a keystroke, the prefix is what filters them, and a linear scan of a hundred short strings is not a cost worth a data structure — while a HashMap would be one more thing to keep in step. The tables are const, so they are in the binary and cost nothing to build.

§Where the line is drawn on snippets

Only constructs whose body a reader would otherwise type by hand: the control-flow statements, a class, a namespace, a function, a template, a main. Not “every declaration form” — a snippet for int x = 0; saves three keystrokes and gets in the way of the far more common case of completing a name that happens to start with i. A snippet earns its place by writing a shape (braces, a clause, a placeholder) rather than a spelling.

Structs§

DirectiveName
One preprocessor directive.
Keyword
One keyword, and the shape it fits.
Snippet
A snippet: a construct, its body, and what to call it.

Enums§

KeywordUse
Which of a keyword’s several shapes a cursor is in.

Constants§

BUILTIN_TYPES
The built-in type names that are not keywords.
DIRECTIVES
Every standard directive, offered after a #.
KEYWORDS
Every C++ keyword the lexer knows, with the shape it fits.
SNIPPETS
The snippets, in the order a reader is most likely to want them.

Functions§

a_snippet_writes_this
Is a snippet already covering this spelling, so that the bare keyword would be a second identical item?
keywords_for
The keywords a cursor in this shape may be writing, in table order.
snippets_for
The snippets a cursor may be writing. See Snippet::starts_a_statement.