@@ -124,7 +124,7 @@ Rustfmt is basically a pretty printer - that is, its mode of operation is to
124
124
take an AST (abstract syntax tree) and print it in a nice way (including staying
125
125
under the maximum permitted width for a line). In order to get that AST, we
126
126
first have to parse the source text, we use the Rust compiler's parser to do
127
- that (see [ src/ lib.rs] ( src/lib.rs ) ). We shy away from doing anything too fancy, such as
127
+ that (see [ lib.rs in rustfmt-lib ] ( rustfmt-core/rustfmt-lib/ src/lib.rs) ). We shy away from doing anything too fancy, such as
128
128
algebraic approaches to pretty printing, instead relying on an heuristic
129
129
approach, 'manually' crafting a string for each AST node. This results in quite
130
130
a lot of code, but it is relatively simple.
@@ -164,19 +164,19 @@ At a higher level, Rustfmt has machinery so that we account for text between
164
164
'top level' items. Then we can reproduce that text pretty much verbatim. We only
165
165
count spans we actually reformat, so if we can't format a span it is not missed
166
166
completely but is reproduced in the output without being formatted. This is
167
- mostly handled in [ src/ missed_spans.rs] ( src/missed_spans.rs ) . See also ` FmtVisitor::last_pos ` in
168
- [ src/ visitor.rs] ( src/visitor.rs ) .
167
+ mostly handled in [ missed_spans.rs] ( rustfmt-core/rustfmt-lib/ src/missed_spans.rs) . See also ` FmtVisitor::last_pos ` in
168
+ [ visitor.rs] ( rustfmt-core/rustfmt-lib/ src/visitor.rs) .
169
169
170
170
171
171
#### Some important elements
172
172
173
173
At the highest level, Rustfmt uses a ` Visitor ` implementation called ` FmtVisitor `
174
- to walk the AST. This is in [ src/ visitor.rs] ( src/visitor.rs ) . This is really just used to walk
174
+ to walk the AST. This is in [ visitor.rs] ( rustfmt-core/rustfmt-lib/ src/visitor.rs) . This is really just used to walk
175
175
items, rather than the bodies of functions. We also cover macros and attributes
176
176
here. Most methods of the visitor call out to ` Rewrite ` implementations that
177
177
then walk their own children.
178
178
179
- The ` Rewrite ` trait is defined in [ src/ rewrite.rs] ( src/rewrite.rs ) . It is implemented for many
179
+ The ` Rewrite ` trait is defined in [ rewrite.rs] ( rustfmt-core/rustfmt-lib/ src/rewrite.rs) . It is implemented for many
180
180
things that can be rewritten, mostly AST nodes. It has a single function,
181
181
` rewrite ` , which is called to rewrite ` self ` into an ` Option<String> ` . The
182
182
arguments are ` width ` which is the horizontal space we write into and ` offset `
@@ -234,15 +234,15 @@ Much of the syntax in Rust is lists: lists of arguments, lists of fields, lists
234
234
array elements, etc. We have some generic code to handle lists, including how to
235
235
space them in horizontal and vertical space, indentation, comments between
236
236
items, trailing separators, etc. However, since there are so many options, the
237
- code is a bit complex. Look in [ src/ lists.rs] ( src/lists.rs ) . ` write_list ` is the key function,
237
+ code is a bit complex. Look in [ lists.rs] ( rustfmt-core/rustfmt-lib/ src/lists.rs) . ` write_list ` is the key function,
238
238
and ` ListFormatting ` the key structure for configuration. You'll need to make a
239
239
` ListItems ` for input, this is usually done using ` itemize_list ` .
240
240
241
241
##### Configuration
242
242
243
243
Rustfmt strives to be highly configurable. Often the first part of a patch is
244
244
creating a configuration option for the feature you are implementing. All
245
- handling of configuration options is done in [ src/config/mod .rs] ( src/ config/mod .rs) . Look for the
245
+ handling of configuration options is done in [ lib .rs in rustfmt-config ] ( rustfmt-core/rustfmt- config/src/lib .rs) . Look for the
246
246
` create_config! ` macro at the end of the file for all the options. The rest of
247
247
the file defines a bunch of enums used for options, and the machinery to produce
248
248
the config struct and parse a config file, etc. Checking an option is done by
0 commit comments