Expand description
A general code formatter that relies on Tree-sitter for language parsing.
In order for a language to be supported, there must be a Tree-sitter grammar available, and there must be a query file that dictates how that language is to be formatted. We include query files for some languages.
More details can be found on GitHub.
Structs§
- Coverage
Data - Language
- A Language contains all the information Topiary requires to format that specific languages.
- Scope
Information - Syntax
Node - Topiary
Query - Topiary often needs both the tree-sitter
Queryand the original content belonging to the file from which the query was parsed. This struct is a simple convenience wrapper that combines theQuerywith its original string.
Enums§
- Atom
- An atom represents a small piece of the output. We turn Tree-sitter nodes into atoms, and we add white-space atoms where appropriate. The final list of atoms is rendered to the output.
- Capitalisation
- Formatter
Error - The various errors the formatter may return.
- IoError
- A subtype of
FormatterError::Io - Operation
- Operations that can be performed by the formatter.
- Scope
Condition - Used in
Atom::ScopedConditionalto apply the containing Atoms only if the matched node spans a single line or multiple lines - Visualisation
- Supported visualisation formats
Functions§
- apply_
query - Applies a query to an input content and returns a collection of atoms.
- check_
query_ coverage - Check if the input tests all patterns in the query, by successively disabling all patterns. If disabling a pattern does not decrease the number of matches, then that pattern originally matched nothing in the input.
- formatter
- The function that takes an input and formats, or visualises an output.
- formatter_
str - The function that takes a string slice and formats, or visualises an output.
- formatter_
tree - The function that takes a tree and formats, or visualises an output.
- parse
- Parses some string into a syntax tree, given a tree-sitter grammar.
Type Aliases§
- Formatter
Result - A convenience wrapper around
std::result::Result<T, FormatterError>.