Skip to content

Commit

Permalink
config: Add field for tracking lines to format
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalmarhubi committed Mar 5, 2016
1 parent c28402a commit 5103c4c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

extern crate toml;

use std::collections::HashMap;
use std::path::PathBuf;
use std::str;

use lists::{SeparatorTactic, ListTactic};

macro_rules! configuration_option_enum{
Expand Down Expand Up @@ -80,6 +84,35 @@ configuration_option_enum! { TypeDensity:
Wide,
}

pub type LineRange = (usize, usize);

// Newtype required to implement ConfigType and FromStr for the `create_config` macro.
#[derive(Clone, Debug, RustcDecodable)]
pub struct LineRanges(pub Vec<LineRange>);

impl LineRanges {
pub fn new() -> LineRanges {
LineRanges(Vec::new())
}
}

// This impl is needed by the `create_config` macro.
impl str::FromStr for LineRanges {
type Err = ();
fn from_str(_: &str) -> Result<LineRanges, ()> {
unimplemented!();
}
}

// This impl is needed by the `create_config` macro.
impl ConfigType for LineRanges {
fn get_variant_names() -> String {
String::from("<ranges>")
}
}

pub type FileLinesMap = HashMap<PathBuf, LineRanges>;

impl Density {
pub fn to_list_tactic(self) -> ListTactic {
match self {
Expand Down Expand Up @@ -300,6 +333,7 @@ macro_rules! create_config {
create_config! {
Doc verbose: bool, false, "Use verbose output";
Doc skip_children: bool, false, "Don't reformat out of line modules";
NoDoc line_ranges: LineRanges, LineRanges::new(), "Ranges of lines to format";
Doc max_width: usize, 100, "Maximum width of each line";
Doc ideal_width: usize, 80, "Ideal width of each line";
Doc tab_spaces: usize, 4, "Number of spaces per tab";
Expand Down

0 comments on commit 5103c4c

Please sign in to comment.