Skip to content

Commit 9114843

Browse files
SiegeLordExSiegeLord
authored andcommitted
Initial implementation of hard tab indentation.
1 parent 2a61a98 commit 9114843

File tree

13 files changed

+357
-205
lines changed

13 files changed

+357
-205
lines changed

src/comment.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@
1212

1313
use std::iter;
1414

15+
use Indent;
16+
use config::Config;
1517
use string::{StringFormat, rewrite_string};
1618
use utils::make_indent;
1719

18-
pub fn rewrite_comment(orig: &str, block_style: bool, width: usize, offset: usize) -> String {
20+
pub fn rewrite_comment(orig: &str,
21+
block_style: bool,
22+
width: usize,
23+
offset: Indent,
24+
config: &Config)
25+
-> String {
1926
let s = orig.trim();
2027

2128
// Edge case: block comments. Let's not trim their lines (for now).
@@ -34,11 +41,12 @@ pub fn rewrite_comment(orig: &str, block_style: bool, width: usize, offset: usiz
3441
line_start: line_start,
3542
line_end: "",
3643
width: max_chars,
37-
offset: offset + opener.len() - line_start.len(),
44+
offset: offset + (opener.len() - line_start.len()),
3845
trim_end: true,
46+
config: config,
3947
};
4048

41-
let indent_str = make_indent(offset);
49+
let indent_str = make_indent(offset, config);
4250
let line_breaks = s.chars().filter(|&c| c == '\n').count();
4351

4452
let (_, mut s) = s.lines().enumerate()
@@ -297,24 +305,33 @@ impl<T> Iterator for CharClasses<T> where T: Iterator, T::Item: RichChar {
297305
mod test {
298306
use super::{CharClasses, CodeCharKind, contains_comment, rewrite_comment, FindUncommented};
299307

308+
use std::default::Default;
309+
310+
use Indent;
311+
300312
#[test]
301313
fn format_comments() {
302-
assert_eq!("/* test */", rewrite_comment(" //test", true, 100, 100));
303-
assert_eq!("// comment\n// on a", rewrite_comment("// comment on a", false, 10, 0));
314+
let config = Default::default();
315+
assert_eq!("/* test */", rewrite_comment(" //test", true, 100, Indent::new(0, 100),
316+
&config));
317+
assert_eq!("// comment\n// on a", rewrite_comment("// comment on a", false, 10,
318+
Indent::new(0, 0), &config));
304319

305320
assert_eq!("// A multi line comment\n // between args.",
306321
rewrite_comment("// A multi line comment\n // between args.",
307322
false,
308323
60,
309-
12));
324+
Indent::new(0, 12),
325+
&config));
310326

311327
let input = "// comment";
312328
let expected = "/* com\n \
313329
* men\n \
314330
* t */";
315-
assert_eq!(expected, rewrite_comment(input, true, 9, 69));
331+
assert_eq!(expected, rewrite_comment(input, true, 9, Indent::new(0, 69), &config));
316332

317-
assert_eq!("/* trimmed */", rewrite_comment("/* trimmed */", true, 100, 100));
333+
assert_eq!("/* trimmed */", rewrite_comment("/* trimmed */", true, 100,
334+
Indent::new(0, 100), &config));
318335
}
319336

320337
// This is probably intended to be a non-test fn, but it is not used. I'm

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ create_config! {
130130
closure_indent_style: BlockIndentStyle,
131131
single_line_if_else: bool,
132132
format_strings: bool,
133+
hard_tabs: bool,
133134
}
134135

135136
impl Default for Config {
@@ -163,6 +164,7 @@ impl Default for Config {
163164
closure_indent_style: BlockIndentStyle::Visual,
164165
single_line_if_else: false,
165166
format_strings: true,
167+
hard_tabs: false,
166168
}
167169
}
168170

0 commit comments

Comments
 (0)