Skip to content

Commit 5103c4c

Browse files
committed
config: Add field for tracking lines to format
Refs https://github.com/nrc/rustfmt/issues/434
1 parent c28402a commit 5103c4c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/config.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
extern crate toml;
1212

13+
use std::collections::HashMap;
14+
use std::path::PathBuf;
15+
use std::str;
16+
1317
use lists::{SeparatorTactic, ListTactic};
1418

1519
macro_rules! configuration_option_enum{
@@ -80,6 +84,35 @@ configuration_option_enum! { TypeDensity:
8084
Wide,
8185
}
8286

87+
pub type LineRange = (usize, usize);
88+
89+
// Newtype required to implement ConfigType and FromStr for the `create_config` macro.
90+
#[derive(Clone, Debug, RustcDecodable)]
91+
pub struct LineRanges(pub Vec<LineRange>);
92+
93+
impl LineRanges {
94+
pub fn new() -> LineRanges {
95+
LineRanges(Vec::new())
96+
}
97+
}
98+
99+
// This impl is needed by the `create_config` macro.
100+
impl str::FromStr for LineRanges {
101+
type Err = ();
102+
fn from_str(_: &str) -> Result<LineRanges, ()> {
103+
unimplemented!();
104+
}
105+
}
106+
107+
// This impl is needed by the `create_config` macro.
108+
impl ConfigType for LineRanges {
109+
fn get_variant_names() -> String {
110+
String::from("<ranges>")
111+
}
112+
}
113+
114+
pub type FileLinesMap = HashMap<PathBuf, LineRanges>;
115+
83116
impl Density {
84117
pub fn to_list_tactic(self) -> ListTactic {
85118
match self {
@@ -300,6 +333,7 @@ macro_rules! create_config {
300333
create_config! {
301334
Doc verbose: bool, false, "Use verbose output";
302335
Doc skip_children: bool, false, "Don't reformat out of line modules";
336+
NoDoc line_ranges: LineRanges, LineRanges::new(), "Ranges of lines to format";
303337
Doc max_width: usize, 100, "Maximum width of each line";
304338
Doc ideal_width: usize, 80, "Ideal width of each line";
305339
Doc tab_spaces: usize, 4, "Number of spaces per tab";

0 commit comments

Comments
 (0)