diff options
author | Aleksey Kladov <[email protected]> | 2018-12-20 19:13:16 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-12-20 19:43:06 +0000 |
commit | 23b040962ff299feeef1f967bc2d5ba92b01c2bc (patch) | |
tree | bad7cb6bc8614a8c1ef19b90925dfcb5a8c57284 /crates/ra_editor | |
parent | 8d7e8a175e6067e4956a23cfd0c1baf003678734 (diff) |
fold curly blocks
Diffstat (limited to 'crates/ra_editor')
-rw-r--r-- | crates/ra_editor/src/folding_ranges.rs | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs index a4add8702..da542ecf0 100644 --- a/crates/ra_editor/src/folding_ranges.rs +++ b/crates/ra_editor/src/folding_ranges.rs | |||
@@ -10,6 +10,7 @@ use ra_syntax::{ | |||
10 | pub enum FoldKind { | 10 | pub enum FoldKind { |
11 | Comment, | 11 | Comment, |
12 | Imports, | 12 | Imports, |
13 | Block, | ||
13 | } | 14 | } |
14 | 15 | ||
15 | #[derive(Debug)] | 16 | #[derive(Debug)] |
@@ -62,6 +63,8 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> { | |||
62 | match kind { | 63 | match kind { |
63 | COMMENT => Some(FoldKind::Comment), | 64 | COMMENT => Some(FoldKind::Comment), |
64 | USE_ITEM => Some(FoldKind::Imports), | 65 | USE_ITEM => Some(FoldKind::Imports), |
66 | NAMED_FIELD_DEF_LIST | FIELD_PAT_LIST | ITEM_LIST | EXTERN_ITEM_LIST | USE_TREE_LIST | ||
67 | | BLOCK | ENUM_VARIANT_LIST => Some(FoldKind::Block), | ||
65 | _ => None, | 68 | _ => None, |
66 | } | 69 | } |
67 | } | 70 | } |
@@ -205,7 +208,7 @@ mod tests { | |||
205 | 208 | ||
206 | // But this is not | 209 | // But this is not |
207 | 210 | ||
208 | fn main() { | 211 | fn main() <fold>{ |
209 | <fold>// We should | 212 | <fold>// We should |
210 | // also | 213 | // also |
211 | // fold | 214 | // fold |
@@ -214,10 +217,11 @@ fn main() { | |||
214 | //! because it has another flavor</fold> | 217 | //! because it has another flavor</fold> |
215 | <fold>/* As does this | 218 | <fold>/* As does this |
216 | multiline comment */</fold> | 219 | multiline comment */</fold> |
217 | }"#; | 220 | }</fold>"#; |
218 | 221 | ||
219 | let fold_kinds = &[ | 222 | let fold_kinds = &[ |
220 | FoldKind::Comment, | 223 | FoldKind::Comment, |
224 | FoldKind::Block, | ||
221 | FoldKind::Comment, | 225 | FoldKind::Comment, |
222 | FoldKind::Comment, | 226 | FoldKind::Comment, |
223 | FoldKind::Comment, | 227 | FoldKind::Comment, |
@@ -228,16 +232,16 @@ fn main() { | |||
228 | #[test] | 232 | #[test] |
229 | fn test_fold_imports() { | 233 | fn test_fold_imports() { |
230 | let text = r#" | 234 | let text = r#" |
231 | <fold>use std::{ | 235 | <fold>use std::<fold>{ |
232 | str, | 236 | str, |
233 | vec, | 237 | vec, |
234 | io as iop | 238 | io as iop |
235 | };</fold> | 239 | }</fold>;</fold> |
236 | 240 | ||
237 | fn main() { | 241 | fn main() <fold>{ |
238 | }"#; | 242 | }</fold>"#; |
239 | 243 | ||
240 | let folds = &[FoldKind::Imports]; | 244 | let folds = &[FoldKind::Imports, FoldKind::Block, FoldKind::Block]; |
241 | do_check(text, folds); | 245 | do_check(text, folds); |
242 | } | 246 | } |
243 | 247 | ||
@@ -255,10 +259,10 @@ use std::collections::HashMap; | |||
255 | // Some random comment | 259 | // Some random comment |
256 | use std::collections::VecDeque; | 260 | use std::collections::VecDeque; |
257 | 261 | ||
258 | fn main() { | 262 | fn main() <fold>{ |
259 | }"#; | 263 | }</fold>"#; |
260 | 264 | ||
261 | let folds = &[FoldKind::Imports, FoldKind::Imports]; | 265 | let folds = &[FoldKind::Imports, FoldKind::Imports, FoldKind::Block]; |
262 | do_check(text, folds); | 266 | do_check(text, folds); |
263 | } | 267 | } |
264 | 268 | ||
@@ -272,16 +276,22 @@ use std::io as iop;</fold> | |||
272 | <fold>use std::mem; | 276 | <fold>use std::mem; |
273 | use std::f64;</fold> | 277 | use std::f64;</fold> |
274 | 278 | ||
275 | <fold>use std::collections::{ | 279 | <fold>use std::collections::<fold>{ |
276 | HashMap, | 280 | HashMap, |
277 | VecDeque, | 281 | VecDeque, |
278 | };</fold> | 282 | }</fold>;</fold> |
279 | // Some random comment | 283 | // Some random comment |
280 | 284 | ||
281 | fn main() { | 285 | fn main() <fold>{ |
282 | }"#; | 286 | }</fold>"#; |
283 | 287 | ||
284 | let folds = &[FoldKind::Imports, FoldKind::Imports, FoldKind::Imports]; | 288 | let folds = &[ |
289 | FoldKind::Imports, | ||
290 | FoldKind::Imports, | ||
291 | FoldKind::Imports, | ||
292 | FoldKind::Block, | ||
293 | FoldKind::Block, | ||
294 | ]; | ||
285 | do_check(text, folds); | 295 | do_check(text, folds); |
286 | } | 296 | } |
287 | 297 | ||