aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_editor/src/folding_ranges.rs40
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs7
-rw-r--r--crates/test_utils/src/lib.rs1
3 files changed, 30 insertions, 18 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::{
10pub enum FoldKind { 10pub 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
208fn main() { 211fn 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
237fn main() { 241fn 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
256use std::collections::VecDeque; 260use std::collections::VecDeque;
257 261
258fn main() { 262fn 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;
273use std::f64;</fold> 277use 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
281fn main() { 285fn 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
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 572ae7fb5..801966304 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -446,8 +446,9 @@ pub fn handle_folding_range(
446 .into_iter() 446 .into_iter()
447 .map(|fold| { 447 .map(|fold| {
448 let kind = match fold.kind { 448 let kind = match fold.kind {
449 FoldKind::Comment => FoldingRangeKind::Comment, 449 FoldKind::Comment => Some(FoldingRangeKind::Comment),
450 FoldKind::Imports => FoldingRangeKind::Imports, 450 FoldKind::Imports => Some(FoldingRangeKind::Imports),
451 FoldKind::Block => None,
451 }; 452 };
452 let range = fold.range.conv_with(&line_index); 453 let range = fold.range.conv_with(&line_index);
453 FoldingRange { 454 FoldingRange {
@@ -455,7 +456,7 @@ pub fn handle_folding_range(
455 start_character: Some(range.start.character), 456 start_character: Some(range.start.character),
456 end_line: range.end.line, 457 end_line: range.end.line,
457 end_character: Some(range.start.character), 458 end_character: Some(range.start.character),
458 kind: Some(kind), 459 kind,
459 } 460 }
460 }) 461 })
461 .collect(), 462 .collect(),
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index 894a22769..1ae800d7c 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -98,6 +98,7 @@ pub fn extract_ranges(mut text: &str, tag: &str) -> (Vec<TextRange>, String) {
98 } 98 }
99 } 99 }
100 assert!(stack.is_empty(), "unmatched <{}>", tag); 100 assert!(stack.is_empty(), "unmatched <{}>", tag);
101 ranges.sort_by_key(|r| (r.start(), r.end()));
101 (ranges, res) 102 (ranges, res)
102} 103}
103 104