Skip to main content

Module config

Module config 

Source
Expand description

.clang-format: the YAML subset clang-format itself accepts, and the style it resolves to.

§What is supported, and what happens to the rest

Supported: key: value (scalars, booleans, integers, quoted strings), nested maps (BraceWrapping:) and inline sequences ([a, b]), # comments, ----separated documents (each may carry a Language:), and BasedOnStyle: <preset>.

Anything else — anchors, multi-line scalars, flow maps — is a hard error with the line number, not a silent ignore. That is the same rule .cppls.toml follows: a file a user writes by hand gets a real parser, and the part that is not supported is named rather than skipped.

§The style is an array, not a map

188 options, every one with a default, and a formatting rule asks for one of them hundreds of times per kilobyte — space::between alone consults four or five per gap. A BTreeMap<String, String> makes each of those a string comparison and a parse::<i64>(); that is why the first version of this module was the wrong shape to build the rest of the formatter on.

So the store is

Option              an enum, `#[repr(usize)]`, one variant per clang-format key ([`crate::options`])
Style.values        Vec<Value>, indexed by `option as usize` — one bounds-checked index per query
Value               Flag(bool) | Number(i64) | Text(Cow<'static, str>) | Unset

The value is parsed once, when the configuration is read, never at a query. The string form survives in exactly two places: reading a document (StyleOption::from_key, a binary search over a sorted table) and printing -dump-config. A misspelt key is still an error with its line number, because the loader looks the key up before it stores anything.

Structs§

ConfigError
Why a .clang-format could not be read.
Style
A resolved style: every option of the chosen preset, overridden by the .clang-format that was read.

Enums§

Value
One option’s value, parsed at load time so that no query parses anything.

Functions§

canonical_preset
The canonical spelling of a preset name, as clang-format accepts it (case-insensitive).
find_config
The nearest .clang-format at or above file, as the path it was found at and its text.
parse
Read a .clang-format document on top of base (None = the LLVM default).
style_for_file
The style of a file: the nearest .clang-format at or above it, or the default style when there is none.