2015-05-23 22:25:36 +12:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
extern crate toml;
|
|
|
|
|
2015-07-16 10:44:43 +12:00
|
|
|
use {NewlineStyle, BraceStyle, ReturnIndent, StructLitStyle};
|
2015-09-01 17:06:41 +12:00
|
|
|
use lists::{SeparatorTactic, ListTactic};
|
2015-06-09 01:42:29 +02:00
|
|
|
use issues::ReportTactic;
|
|
|
|
|
2015-07-20 23:29:25 +02:00
|
|
|
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
|
|
|
pub enum BlockIndentStyle {
|
|
|
|
// Same level as parent.
|
|
|
|
Inherit,
|
|
|
|
// One level deeper than parent.
|
|
|
|
Tabbed,
|
|
|
|
// Aligned with block open.
|
|
|
|
Visual,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_enum_decodable!(BlockIndentStyle, Inherit, Tabbed, Visual);
|
|
|
|
|
2015-09-01 17:06:41 +12:00
|
|
|
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
|
|
|
pub enum Density {
|
|
|
|
// Fit as much on one line as possible.
|
|
|
|
Compressed,
|
|
|
|
// Use more lines.
|
|
|
|
Tall,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_enum_decodable!(Density, Compressed, Tall);
|
|
|
|
|
|
|
|
impl Density {
|
|
|
|
pub fn to_list_tactic(self) -> ListTactic {
|
|
|
|
match self {
|
|
|
|
Density::Compressed => ListTactic::Mixed,
|
|
|
|
Density::Tall => ListTactic::HorizontalVertical,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-19 21:41:19 +02:00
|
|
|
macro_rules! create_config {
|
|
|
|
($($i:ident: $ty:ty),+ $(,)*) => (
|
|
|
|
#[derive(RustcDecodable, Clone)]
|
|
|
|
pub struct Config {
|
|
|
|
$(pub $i: $ty),+
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Config {
|
|
|
|
pub fn from_toml(toml: &str) -> Config {
|
|
|
|
let parsed = toml.parse().unwrap();
|
|
|
|
match toml::decode(parsed) {
|
|
|
|
Some(decoded) => decoded,
|
|
|
|
None => {
|
|
|
|
println!("Decoding config file failed. Config:\n{}", toml);
|
|
|
|
let parsed: toml::Value = toml.parse().unwrap();
|
|
|
|
println!("\n\nParsed:\n{:?}", parsed);
|
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-23 22:25:36 +12:00
|
|
|
|
2015-08-19 21:41:19 +02:00
|
|
|
pub fn override_value(&mut self, key: &str, val: &str) {
|
|
|
|
match key {
|
|
|
|
$(
|
|
|
|
stringify!($i) => {
|
|
|
|
self.$i = val.parse::<$ty>().unwrap();
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
_ => panic!("Bad config key!")
|
|
|
|
}
|
2015-07-16 10:44:43 +12:00
|
|
|
}
|
|
|
|
}
|
2015-08-19 21:41:19 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
create_config! {
|
|
|
|
max_width: usize,
|
|
|
|
ideal_width: usize,
|
|
|
|
leeway: usize,
|
|
|
|
tab_spaces: usize,
|
|
|
|
newline_style: NewlineStyle,
|
|
|
|
fn_brace_style: BraceStyle,
|
|
|
|
fn_return_indent: ReturnIndent,
|
|
|
|
fn_args_paren_newline: bool,
|
2015-09-02 08:56:37 +12:00
|
|
|
fn_args_density: Density,
|
2015-09-02 09:41:08 +12:00
|
|
|
fn_args_layout: StructLitStyle,
|
2015-09-01 17:22:00 +12:00
|
|
|
fn_arg_indent: BlockIndentStyle,
|
2015-09-01 19:36:00 +12:00
|
|
|
where_density: Density, // Should we at least try to put the where clause on the same line as
|
|
|
|
// the rest of the function decl?
|
2015-09-01 18:38:12 +12:00
|
|
|
where_indent: BlockIndentStyle, // Visual will be treated like Tabbed
|
2015-09-01 18:53:16 +12:00
|
|
|
where_layout: ListTactic,
|
2015-09-01 19:04:41 +12:00
|
|
|
where_pred_indent: BlockIndentStyle,
|
2015-09-01 18:20:17 +12:00
|
|
|
generics_indent: BlockIndentStyle,
|
2015-08-19 21:41:19 +02:00
|
|
|
struct_trailing_comma: SeparatorTactic,
|
|
|
|
struct_lit_trailing_comma: SeparatorTactic,
|
|
|
|
struct_lit_style: StructLitStyle,
|
|
|
|
enum_trailing_comma: bool,
|
|
|
|
report_todo: ReportTactic,
|
|
|
|
report_fixme: ReportTactic,
|
|
|
|
reorder_imports: bool, // Alphabetically, case sensitive.
|
|
|
|
expr_indent_style: BlockIndentStyle,
|
2015-08-19 22:39:45 +02:00
|
|
|
closure_indent_style: BlockIndentStyle,
|
2015-08-25 21:46:58 +02:00
|
|
|
single_line_if_else: bool,
|
2015-09-01 08:14:52 -04:00
|
|
|
format_strings: bool,
|
2015-05-23 22:25:36 +12:00
|
|
|
}
|
2015-07-31 19:21:44 -04:00
|
|
|
|
|
|
|
impl Default for Config {
|
|
|
|
|
|
|
|
fn default() -> Config {
|
|
|
|
Config {
|
|
|
|
max_width: 100,
|
|
|
|
ideal_width: 80,
|
|
|
|
leeway: 5,
|
|
|
|
tab_spaces: 4,
|
|
|
|
newline_style: NewlineStyle::Unix,
|
|
|
|
fn_brace_style: BraceStyle::SameLineWhere,
|
|
|
|
fn_return_indent: ReturnIndent::WithArgs,
|
|
|
|
fn_args_paren_newline: true,
|
2015-09-02 08:56:37 +12:00
|
|
|
fn_args_density: Density::Tall,
|
2015-09-02 09:41:08 +12:00
|
|
|
fn_args_layout: StructLitStyle::Visual,
|
2015-09-01 17:22:00 +12:00
|
|
|
fn_arg_indent: BlockIndentStyle::Visual,
|
2015-09-01 19:36:00 +12:00
|
|
|
where_density: Density::Tall,
|
2015-09-01 18:38:12 +12:00
|
|
|
where_indent: BlockIndentStyle::Tabbed,
|
2015-09-01 18:53:16 +12:00
|
|
|
where_layout: ListTactic::Vertical,
|
2015-09-01 19:04:41 +12:00
|
|
|
where_pred_indent: BlockIndentStyle::Visual,
|
2015-09-01 18:20:17 +12:00
|
|
|
generics_indent: BlockIndentStyle::Visual,
|
2015-07-31 19:21:44 -04:00
|
|
|
struct_trailing_comma: SeparatorTactic::Vertical,
|
|
|
|
struct_lit_trailing_comma: SeparatorTactic::Vertical,
|
2015-09-02 09:41:08 +12:00
|
|
|
struct_lit_style: StructLitStyle::Block,
|
2015-07-31 19:21:44 -04:00
|
|
|
enum_trailing_comma: true,
|
|
|
|
report_todo: ReportTactic::Always,
|
|
|
|
report_fixme: ReportTactic::Never,
|
|
|
|
reorder_imports: false,
|
|
|
|
expr_indent_style: BlockIndentStyle::Tabbed,
|
|
|
|
closure_indent_style: BlockIndentStyle::Visual,
|
|
|
|
single_line_if_else: false,
|
2015-09-01 08:14:52 -04:00
|
|
|
format_strings: true,
|
2015-07-31 19:21:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|