diff options
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/completion/complete_postfix.rs | 59 | ||||
-rw-r--r-- | crates/ra_ide/src/display.rs | 3 | ||||
-rw-r--r-- | crates/ra_ide/src/hover.rs | 16 | ||||
-rw-r--r-- | crates/ra_ide/src/ssr.rs | 8 |
4 files changed, 74 insertions, 12 deletions
diff --git a/crates/ra_ide/src/completion/complete_postfix.rs b/crates/ra_ide/src/completion/complete_postfix.rs index f2a52a407..02e660ca8 100644 --- a/crates/ra_ide/src/completion/complete_postfix.rs +++ b/crates/ra_ide/src/completion/complete_postfix.rs | |||
@@ -184,6 +184,16 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | |||
184 | &format!("dbg!({})", receiver_text), | 184 | &format!("dbg!({})", receiver_text), |
185 | ) | 185 | ) |
186 | .add_to(acc); | 186 | .add_to(acc); |
187 | |||
188 | postfix_snippet( | ||
189 | ctx, | ||
190 | cap, | ||
191 | &dot_receiver, | ||
192 | "call", | ||
193 | "function(expr)", | ||
194 | &format!("${{1}}({})", receiver_text), | ||
195 | ) | ||
196 | .add_to(acc); | ||
187 | } | 197 | } |
188 | 198 | ||
189 | fn get_receiver_text(receiver: &ast::Expr, receiver_is_ambiguous_float_literal: bool) -> String { | 199 | fn get_receiver_text(receiver: &ast::Expr, receiver_is_ambiguous_float_literal: bool) -> String { |
@@ -256,6 +266,13 @@ mod tests { | |||
256 | detail: "Box::new(expr)", | 266 | detail: "Box::new(expr)", |
257 | }, | 267 | }, |
258 | CompletionItem { | 268 | CompletionItem { |
269 | label: "call", | ||
270 | source_range: 89..89, | ||
271 | delete: 85..89, | ||
272 | insert: "${1}(bar)", | ||
273 | detail: "function(expr)", | ||
274 | }, | ||
275 | CompletionItem { | ||
259 | label: "dbg", | 276 | label: "dbg", |
260 | source_range: 89..89, | 277 | source_range: 89..89, |
261 | delete: 85..89, | 278 | delete: 85..89, |
@@ -335,6 +352,13 @@ mod tests { | |||
335 | detail: "Box::new(expr)", | 352 | detail: "Box::new(expr)", |
336 | }, | 353 | }, |
337 | CompletionItem { | 354 | CompletionItem { |
355 | label: "call", | ||
356 | source_range: 210..210, | ||
357 | delete: 206..210, | ||
358 | insert: "${1}(bar)", | ||
359 | detail: "function(expr)", | ||
360 | }, | ||
361 | CompletionItem { | ||
338 | label: "dbg", | 362 | label: "dbg", |
339 | source_range: 210..210, | 363 | source_range: 210..210, |
340 | delete: 206..210, | 364 | delete: 206..210, |
@@ -414,6 +438,13 @@ mod tests { | |||
414 | detail: "Box::new(expr)", | 438 | detail: "Box::new(expr)", |
415 | }, | 439 | }, |
416 | CompletionItem { | 440 | CompletionItem { |
441 | label: "call", | ||
442 | source_range: 211..211, | ||
443 | delete: 207..211, | ||
444 | insert: "${1}(bar)", | ||
445 | detail: "function(expr)", | ||
446 | }, | ||
447 | CompletionItem { | ||
417 | label: "dbg", | 448 | label: "dbg", |
418 | source_range: 211..211, | 449 | source_range: 211..211, |
419 | delete: 207..211, | 450 | delete: 207..211, |
@@ -488,6 +519,13 @@ mod tests { | |||
488 | detail: "Box::new(expr)", | 519 | detail: "Box::new(expr)", |
489 | }, | 520 | }, |
490 | CompletionItem { | 521 | CompletionItem { |
522 | label: "call", | ||
523 | source_range: 91..91, | ||
524 | delete: 87..91, | ||
525 | insert: "${1}(bar)", | ||
526 | detail: "function(expr)", | ||
527 | }, | ||
528 | CompletionItem { | ||
491 | label: "dbg", | 529 | label: "dbg", |
492 | source_range: 91..91, | 530 | source_range: 91..91, |
493 | delete: 87..91, | 531 | delete: 87..91, |
@@ -547,6 +585,13 @@ mod tests { | |||
547 | detail: "Box::new(expr)", | 585 | detail: "Box::new(expr)", |
548 | }, | 586 | }, |
549 | CompletionItem { | 587 | CompletionItem { |
588 | label: "call", | ||
589 | source_range: 52..52, | ||
590 | delete: 49..52, | ||
591 | insert: "${1}(42)", | ||
592 | detail: "function(expr)", | ||
593 | }, | ||
594 | CompletionItem { | ||
550 | label: "dbg", | 595 | label: "dbg", |
551 | source_range: 52..52, | 596 | source_range: 52..52, |
552 | delete: 49..52, | 597 | delete: 49..52, |
@@ -608,6 +653,13 @@ mod tests { | |||
608 | detail: "Box::new(expr)", | 653 | detail: "Box::new(expr)", |
609 | }, | 654 | }, |
610 | CompletionItem { | 655 | CompletionItem { |
656 | label: "call", | ||
657 | source_range: 149..150, | ||
658 | delete: 145..150, | ||
659 | insert: "${1}(bar)", | ||
660 | detail: "function(expr)", | ||
661 | }, | ||
662 | CompletionItem { | ||
611 | label: "dbg", | 663 | label: "dbg", |
612 | source_range: 149..150, | 664 | source_range: 149..150, |
613 | delete: 145..150, | 665 | delete: 145..150, |
@@ -667,6 +719,13 @@ mod tests { | |||
667 | detail: "Box::new(expr)", | 719 | detail: "Box::new(expr)", |
668 | }, | 720 | }, |
669 | CompletionItem { | 721 | CompletionItem { |
722 | label: "call", | ||
723 | source_range: 56..56, | ||
724 | delete: 49..56, | ||
725 | insert: "${1}(&&&&42)", | ||
726 | detail: "function(expr)", | ||
727 | }, | ||
728 | CompletionItem { | ||
670 | label: "dbg", | 729 | label: "dbg", |
671 | source_range: 56..56, | 730 | source_range: 56..56, |
672 | delete: 49..56, | 731 | delete: 49..56, |
diff --git a/crates/ra_ide/src/display.rs b/crates/ra_ide/src/display.rs index 8bb312156..827c094e7 100644 --- a/crates/ra_ide/src/display.rs +++ b/crates/ra_ide/src/display.rs | |||
@@ -83,12 +83,13 @@ pub(crate) fn rust_code_markup_with_doc( | |||
83 | 83 | ||
84 | if let Some(mod_path) = mod_path { | 84 | if let Some(mod_path) = mod_path { |
85 | if !mod_path.is_empty() { | 85 | if !mod_path.is_empty() { |
86 | format_to!(buf, "{}\n___\n\n", mod_path); | 86 | format_to!(buf, "```rust\n{}\n```\n\n", mod_path); |
87 | } | 87 | } |
88 | } | 88 | } |
89 | format_to!(buf, "```rust\n{}\n```", code); | 89 | format_to!(buf, "```rust\n{}\n```", code); |
90 | 90 | ||
91 | if let Some(doc) = doc { | 91 | if let Some(doc) = doc { |
92 | format_to!(buf, "\n___"); | ||
92 | format_to!(buf, "\n\n{}", doc); | 93 | format_to!(buf, "\n\n{}", doc); |
93 | } | 94 | } |
94 | 95 | ||
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 1f4f6b848..3e721dcca 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs | |||
@@ -405,7 +405,7 @@ mod tests { | |||
405 | }; | 405 | }; |
406 | } | 406 | } |
407 | "#, | 407 | "#, |
408 | &["Foo\n___\n\n```rust\nfield_a: u32"], | 408 | &["Foo\n```\n\n```rust\nfield_a: u32"], |
409 | ); | 409 | ); |
410 | 410 | ||
411 | // Hovering over the field in the definition | 411 | // Hovering over the field in the definition |
@@ -422,7 +422,7 @@ mod tests { | |||
422 | }; | 422 | }; |
423 | } | 423 | } |
424 | "#, | 424 | "#, |
425 | &["Foo\n___\n\n```rust\nfield_a: u32"], | 425 | &["Foo\n```\n\n```rust\nfield_a: u32"], |
426 | ); | 426 | ); |
427 | } | 427 | } |
428 | 428 | ||
@@ -475,7 +475,7 @@ fn main() { | |||
475 | ", | 475 | ", |
476 | ); | 476 | ); |
477 | let hover = analysis.hover(position).unwrap().unwrap(); | 477 | let hover = analysis.hover(position).unwrap().unwrap(); |
478 | assert_eq!(trim_markup_opt(hover.info.first()), Some("Option\n___\n\n```rust\nSome")); | 478 | assert_eq!(trim_markup_opt(hover.info.first()), Some("Option\n```\n\n```rust\nSome")); |
479 | 479 | ||
480 | let (analysis, position) = single_file_with_position( | 480 | let (analysis, position) = single_file_with_position( |
481 | " | 481 | " |
@@ -503,11 +503,12 @@ fn main() { | |||
503 | "#, | 503 | "#, |
504 | &[" | 504 | &[" |
505 | Option | 505 | Option |
506 | ___ | 506 | ``` |
507 | 507 | ||
508 | ```rust | 508 | ```rust |
509 | None | 509 | None |
510 | ``` | 510 | ``` |
511 | ___ | ||
511 | 512 | ||
512 | The None variant | 513 | The None variant |
513 | " | 514 | " |
@@ -527,11 +528,12 @@ The None variant | |||
527 | "#, | 528 | "#, |
528 | &[" | 529 | &[" |
529 | Option | 530 | Option |
530 | ___ | 531 | ``` |
531 | 532 | ||
532 | ```rust | 533 | ```rust |
533 | Some | 534 | Some |
534 | ``` | 535 | ``` |
536 | ___ | ||
535 | 537 | ||
536 | The Some variant | 538 | The Some variant |
537 | " | 539 | " |
@@ -614,7 +616,7 @@ fn func(foo: i32) { if true { <|>foo; }; } | |||
614 | let hover = analysis.hover(position).unwrap().unwrap(); | 616 | let hover = analysis.hover(position).unwrap().unwrap(); |
615 | assert_eq!( | 617 | assert_eq!( |
616 | trim_markup_opt(hover.info.first()), | 618 | trim_markup_opt(hover.info.first()), |
617 | Some("wrapper::Thing\n___\n\n```rust\nfn new() -> Thing") | 619 | Some("wrapper::Thing\n```\n\n```rust\nfn new() -> Thing") |
618 | ); | 620 | ); |
619 | } | 621 | } |
620 | 622 | ||
@@ -891,7 +893,7 @@ fn func(foo: i32) { if true { <|>foo; }; } | |||
891 | fo<|>o(); | 893 | fo<|>o(); |
892 | } | 894 | } |
893 | ", | 895 | ", |
894 | &["fn foo()\n```\n\n<- `\u{3000}` here"], | 896 | &["fn foo()\n```\n___\n\n<- `\u{3000}` here"], |
895 | ); | 897 | ); |
896 | } | 898 | } |
897 | 899 | ||
diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs index 1873d1d0d..130d3b4c3 100644 --- a/crates/ra_ide/src/ssr.rs +++ b/crates/ra_ide/src/ssr.rs | |||
@@ -196,10 +196,10 @@ fn find(pattern: &SsrPattern, code: &SyntaxNode) -> SsrMatches { | |||
196 | ) -> Option<Match> { | 196 | ) -> Option<Match> { |
197 | let match_ = check_opt_nodes(pattern.path(), code.path(), placeholders, match_)?; | 197 | let match_ = check_opt_nodes(pattern.path(), code.path(), placeholders, match_)?; |
198 | 198 | ||
199 | let mut pattern_fields = | 199 | let mut pattern_fields: Vec<RecordField> = |
200 | pattern.record_field_list().map(|x| x.fields().collect()).unwrap_or(vec![]); | 200 | pattern.record_field_list().map(|x| x.fields().collect()).unwrap_or_default(); |
201 | let mut code_fields = | 201 | let mut code_fields: Vec<RecordField> = |
202 | code.record_field_list().map(|x| x.fields().collect()).unwrap_or(vec![]); | 202 | code.record_field_list().map(|x| x.fields().collect()).unwrap_or_default(); |
203 | 203 | ||
204 | if pattern_fields.len() != code_fields.len() { | 204 | if pattern_fields.len() != code_fields.len() { |
205 | return None; | 205 | return None; |