diff options
Diffstat (limited to 'crates/ide/src/expand_macro.rs')
-rw-r--r-- | crates/ide/src/expand_macro.rs | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/crates/ide/src/expand_macro.rs b/crates/ide/src/expand_macro.rs index 9eeabbeda..be0ee03bf 100644 --- a/crates/ide/src/expand_macro.rs +++ b/crates/ide/src/expand_macro.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | use std::iter; | ||
2 | |||
1 | use hir::Semantics; | 3 | use hir::Semantics; |
2 | use ide_db::RootDatabase; | 4 | use ide_db::RootDatabase; |
3 | use syntax::{ | 5 | use syntax::{ |
@@ -91,24 +93,42 @@ fn insert_whitespaces(syn: SyntaxNode) -> String { | |||
91 | let is_last = | 93 | let is_last = |
92 | |f: fn(SyntaxKind) -> bool, default| -> bool { last.map(f).unwrap_or(default) }; | 94 | |f: fn(SyntaxKind) -> bool, default| -> bool { last.map(f).unwrap_or(default) }; |
93 | 95 | ||
94 | res += &match token.kind() { | 96 | match token.kind() { |
95 | k if is_text(k) && is_next(|it| !it.is_punct(), true) => token.text().to_string() + " ", | 97 | k if is_text(k) && is_next(|it| !it.is_punct(), true) => { |
98 | res.push_str(token.text()); | ||
99 | res.push(' '); | ||
100 | } | ||
96 | L_CURLY if is_next(|it| it != R_CURLY, true) => { | 101 | L_CURLY if is_next(|it| it != R_CURLY, true) => { |
97 | indent += 1; | 102 | indent += 1; |
98 | let leading_space = if is_last(is_text, false) { " " } else { "" }; | 103 | if is_last(is_text, false) { |
99 | format!("{}{{\n{}", leading_space, " ".repeat(indent)) | 104 | res.push(' '); |
105 | } | ||
106 | res.push_str("{\n"); | ||
107 | res.extend(iter::repeat(" ").take(2 * indent)); | ||
100 | } | 108 | } |
101 | R_CURLY if is_last(|it| it != L_CURLY, true) => { | 109 | R_CURLY if is_last(|it| it != L_CURLY, true) => { |
102 | indent = indent.saturating_sub(1); | 110 | indent = indent.saturating_sub(1); |
103 | format!("\n{}}}", " ".repeat(indent)) | 111 | res.push('\n'); |
112 | res.extend(iter::repeat(" ").take(2 * indent)); | ||
113 | res.push_str("}"); | ||
104 | } | 114 | } |
105 | R_CURLY => format!("}}\n{}", " ".repeat(indent)), | 115 | R_CURLY => { |
106 | T![;] => format!(";\n{}", " ".repeat(indent)), | 116 | res.push_str("}\n"); |
107 | T![->] => " -> ".to_string(), | 117 | res.extend(iter::repeat(" ").take(2 * indent)); |
108 | T![=] => " = ".to_string(), | 118 | } |
109 | T![=>] => " => ".to_string(), | 119 | LIFETIME_IDENT if is_next(|it| it == IDENT, true) => { |
110 | _ => token.text().to_string(), | 120 | res.push_str(token.text()); |
111 | }; | 121 | res.push(' '); |
122 | } | ||
123 | T![;] => { | ||
124 | res.push_str(";\n"); | ||
125 | res.extend(iter::repeat(" ").take(2 * indent)); | ||
126 | } | ||
127 | T![->] => res.push_str(" -> "), | ||
128 | T![=] => res.push_str(" = "), | ||
129 | T![=>] => res.push_str(" => "), | ||
130 | _ => res.push_str(token.text()), | ||
131 | } | ||
112 | 132 | ||
113 | last = Some(token.kind()); | 133 | last = Some(token.kind()); |
114 | } | 134 | } |