aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/call_info.rs6
-rw-r--r--crates/ra_ide/src/completion/test_utils.rs6
-rw-r--r--crates/ra_ide/src/extend_selection.rs4
-rw-r--r--crates/ra_ide/src/hover.rs36
-rw-r--r--crates/ra_ide/src/mock_analysis.rs5
-rw-r--r--crates/ra_ide/src/references.rs4
-rw-r--r--crates/ra_ide/src/references/rename.rs10
-rw-r--r--crates/ra_ide/src/typing/on_enter.rs4
8 files changed, 34 insertions, 41 deletions
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs
index aa039e6fc..a6bdf1c9d 100644
--- a/crates/ra_ide/src/call_info.rs
+++ b/crates/ra_ide/src/call_info.rs
@@ -215,7 +215,7 @@ impl CallInfo {
215mod tests { 215mod tests {
216 use test_utils::mark; 216 use test_utils::mark;
217 217
218 use crate::mock_analysis::single_file_with_position; 218 use crate::mock_analysis::analysis_and_position;
219 219
220 use super::*; 220 use super::*;
221 221
@@ -231,7 +231,7 @@ mod tests {
231 } 231 }
232 232
233 fn call_info_helper(text: &str) -> Option<CallInfo> { 233 fn call_info_helper(text: &str) -> Option<CallInfo> {
234 let (analysis, position) = single_file_with_position(text); 234 let (analysis, position) = analysis_and_position(text);
235 analysis.call_info(position).unwrap() 235 analysis.call_info(position).unwrap()
236 } 236 }
237 237
@@ -530,7 +530,7 @@ By default this method stops actor's `Context`."#
530 #[test] 530 #[test]
531 fn call_info_bad_offset() { 531 fn call_info_bad_offset() {
532 mark::check!(call_info_bad_offset); 532 mark::check!(call_info_bad_offset);
533 let (analysis, position) = single_file_with_position( 533 let (analysis, position) = analysis_and_position(
534 r#"fn foo(x: u32, y: u32) -> u32 {x + y} 534 r#"fn foo(x: u32, y: u32) -> u32 {x + y}
535 fn bar() { foo <|> (3, ); }"#, 535 fn bar() { foo <|> (3, ); }"#,
536 ); 536 );
diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs
index 1e16a43ca..a1b7c1193 100644
--- a/crates/ra_ide/src/completion/test_utils.rs
+++ b/crates/ra_ide/src/completion/test_utils.rs
@@ -2,7 +2,7 @@
2 2
3use crate::{ 3use crate::{
4 completion::{completion_item::CompletionKind, CompletionConfig}, 4 completion::{completion_item::CompletionKind, CompletionConfig},
5 mock_analysis::{analysis_and_position, single_file_with_position}, 5 mock_analysis::analysis_and_position,
6 CompletionItem, 6 CompletionItem,
7}; 7};
8use hir::Semantics; 8use hir::Semantics;
@@ -33,7 +33,7 @@ fn get_all_completion_items(code: &str, options: &CompletionConfig) -> Vec<Compl
33 let (analysis, position) = if code.contains("//-") { 33 let (analysis, position) = if code.contains("//-") {
34 analysis_and_position(code) 34 analysis_and_position(code)
35 } else { 35 } else {
36 single_file_with_position(code) 36 analysis_and_position(code)
37 }; 37 };
38 analysis.completions(options, position).unwrap().unwrap().into() 38 analysis.completions(options, position).unwrap().unwrap().into()
39} 39}
@@ -55,7 +55,7 @@ pub(crate) fn completion_list_with_options(
55} 55}
56 56
57pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) { 57pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) {
58 let (analysis, pos) = single_file_with_position(code); 58 let (analysis, pos) = analysis_and_position(code);
59 analysis 59 analysis
60 .with_db(|db| { 60 .with_db(|db| {
61 let sema = Semantics::new(db); 61 let sema = Semantics::new(db);
diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs
index cb6b1a40d..8a6b3ea99 100644
--- a/crates/ra_ide/src/extend_selection.rs
+++ b/crates/ra_ide/src/extend_selection.rs
@@ -315,12 +315,12 @@ fn adj_comments(comment: &ast::Comment, dir: Direction) -> ast::Comment {
315 315
316#[cfg(test)] 316#[cfg(test)]
317mod tests { 317mod tests {
318 use crate::mock_analysis::single_file_with_position; 318 use crate::mock_analysis::analysis_and_position;
319 319
320 use super::*; 320 use super::*;
321 321
322 fn do_check(before: &str, afters: &[&str]) { 322 fn do_check(before: &str, afters: &[&str]) {
323 let (analysis, position) = single_file_with_position(&before); 323 let (analysis, position) = analysis_and_position(&before);
324 let before = analysis.file_text(position.file_id).unwrap(); 324 let before = analysis.file_text(position.file_id).unwrap();
325 let range = TextRange::empty(position.offset); 325 let range = TextRange::empty(position.offset);
326 let mut frange = FileRange { file_id: position.file_id, range }; 326 let mut frange = FileRange { file_id: position.file_id, range };
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index 9660fd2d3..c3e36a387 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -399,7 +399,7 @@ mod tests {
399 use ra_db::FileLoader; 399 use ra_db::FileLoader;
400 use ra_syntax::TextRange; 400 use ra_syntax::TextRange;
401 401
402 use crate::mock_analysis::{analysis_and_position, single_file_with_position}; 402 use crate::mock_analysis::analysis_and_position;
403 403
404 fn trim_markup(s: &str) -> &str { 404 fn trim_markup(s: &str) -> &str {
405 s.trim_start_matches("```rust\n").trim_end_matches("\n```") 405 s.trim_start_matches("```rust\n").trim_end_matches("\n```")
@@ -442,7 +442,7 @@ mod tests {
442 442
443 #[test] 443 #[test]
444 fn hover_shows_type_of_an_expression() { 444 fn hover_shows_type_of_an_expression() {
445 let (analysis, position) = single_file_with_position( 445 let (analysis, position) = analysis_and_position(
446 r#" 446 r#"
447pub fn foo() -> u32 { 1 } 447pub fn foo() -> u32 { 1 }
448 448
@@ -641,7 +641,7 @@ fn main() {
641 641
642 #[test] 642 #[test]
643 fn hover_some() { 643 fn hover_some() {
644 let (analysis, position) = single_file_with_position( 644 let (analysis, position) = analysis_and_position(
645 " 645 "
646 enum Option<T> { Some(T) } 646 enum Option<T> { Some(T) }
647 use Option::Some; 647 use Option::Some;
@@ -654,7 +654,7 @@ fn main() {
654 let hover = analysis.hover(position).unwrap().unwrap(); 654 let hover = analysis.hover(position).unwrap().unwrap();
655 assert_eq!(trim_markup_opt(hover.info.first()), Some("Option\n```\n\n```rust\nSome")); 655 assert_eq!(trim_markup_opt(hover.info.first()), Some("Option\n```\n\n```rust\nSome"));
656 656
657 let (analysis, position) = single_file_with_position( 657 let (analysis, position) = analysis_and_position(
658 " 658 "
659 enum Option<T> { Some(T) } 659 enum Option<T> { Some(T) }
660 use Option::Some; 660 use Option::Some;
@@ -720,21 +720,21 @@ The Some variant
720 720
721 #[test] 721 #[test]
722 fn hover_for_local_variable() { 722 fn hover_for_local_variable() {
723 let (analysis, position) = single_file_with_position("fn func(foo: i32) { fo<|>o; }"); 723 let (analysis, position) = analysis_and_position("fn func(foo: i32) { fo<|>o; }");
724 let hover = analysis.hover(position).unwrap().unwrap(); 724 let hover = analysis.hover(position).unwrap().unwrap();
725 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); 725 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
726 } 726 }
727 727
728 #[test] 728 #[test]
729 fn hover_for_local_variable_pat() { 729 fn hover_for_local_variable_pat() {
730 let (analysis, position) = single_file_with_position("fn func(fo<|>o: i32) {}"); 730 let (analysis, position) = analysis_and_position("fn func(fo<|>o: i32) {}");
731 let hover = analysis.hover(position).unwrap().unwrap(); 731 let hover = analysis.hover(position).unwrap().unwrap();
732 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); 732 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
733 } 733 }
734 734
735 #[test] 735 #[test]
736 fn hover_local_var_edge() { 736 fn hover_local_var_edge() {
737 let (analysis, position) = single_file_with_position( 737 let (analysis, position) = analysis_and_position(
738 " 738 "
739fn func(foo: i32) { if true { <|>foo; }; } 739fn func(foo: i32) { if true { <|>foo; }; }
740", 740",
@@ -745,14 +745,14 @@ fn func(foo: i32) { if true { <|>foo; }; }
745 745
746 #[test] 746 #[test]
747 fn hover_for_param_edge() { 747 fn hover_for_param_edge() {
748 let (analysis, position) = single_file_with_position("fn func(<|>foo: i32) {}"); 748 let (analysis, position) = analysis_and_position("fn func(<|>foo: i32) {}");
749 let hover = analysis.hover(position).unwrap().unwrap(); 749 let hover = analysis.hover(position).unwrap().unwrap();
750 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); 750 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
751 } 751 }
752 752
753 #[test] 753 #[test]
754 fn test_hover_infer_associated_method_result() { 754 fn test_hover_infer_associated_method_result() {
755 let (analysis, position) = single_file_with_position( 755 let (analysis, position) = analysis_and_position(
756 " 756 "
757 struct Thing { x: u32 } 757 struct Thing { x: u32 }
758 758
@@ -773,7 +773,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
773 773
774 #[test] 774 #[test]
775 fn test_hover_infer_associated_method_exact() { 775 fn test_hover_infer_associated_method_exact() {
776 let (analysis, position) = single_file_with_position( 776 let (analysis, position) = analysis_and_position(
777 " 777 "
778 mod wrapper { 778 mod wrapper {
779 struct Thing { x: u32 } 779 struct Thing { x: u32 }
@@ -799,7 +799,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
799 799
800 #[test] 800 #[test]
801 fn test_hover_infer_associated_const_in_pattern() { 801 fn test_hover_infer_associated_const_in_pattern() {
802 let (analysis, position) = single_file_with_position( 802 let (analysis, position) = analysis_and_position(
803 " 803 "
804 struct X; 804 struct X;
805 impl X { 805 impl X {
@@ -821,7 +821,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
821 821
822 #[test] 822 #[test]
823 fn test_hover_self() { 823 fn test_hover_self() {
824 let (analysis, position) = single_file_with_position( 824 let (analysis, position) = analysis_and_position(
825 " 825 "
826 struct Thing { x: u32 } 826 struct Thing { x: u32 }
827 impl Thing { 827 impl Thing {
@@ -835,7 +835,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
835 assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing")); 835 assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
836 836
837 /* FIXME: revive these tests 837 /* FIXME: revive these tests
838 let (analysis, position) = single_file_with_position( 838 let (analysis, position) = analysis_and_position(
839 " 839 "
840 struct Thing { x: u32 } 840 struct Thing { x: u32 }
841 impl Thing { 841 impl Thing {
@@ -849,7 +849,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
849 let hover = analysis.hover(position).unwrap().unwrap(); 849 let hover = analysis.hover(position).unwrap().unwrap();
850 assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing")); 850 assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
851 851
852 let (analysis, position) = single_file_with_position( 852 let (analysis, position) = analysis_and_position(
853 " 853 "
854 enum Thing { A } 854 enum Thing { A }
855 impl Thing { 855 impl Thing {
@@ -862,7 +862,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
862 let hover = analysis.hover(position).unwrap().unwrap(); 862 let hover = analysis.hover(position).unwrap().unwrap();
863 assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); 863 assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
864 864
865 let (analysis, position) = single_file_with_position( 865 let (analysis, position) = analysis_and_position(
866 " 866 "
867 enum Thing { A } 867 enum Thing { A }
868 impl Thing { 868 impl Thing {
@@ -878,7 +878,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
878 878
879 #[test] 879 #[test]
880 fn test_hover_shadowing_pat() { 880 fn test_hover_shadowing_pat() {
881 let (analysis, position) = single_file_with_position( 881 let (analysis, position) = analysis_and_position(
882 " 882 "
883 fn x() {} 883 fn x() {}
884 884
@@ -894,7 +894,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
894 894
895 #[test] 895 #[test]
896 fn test_hover_macro_invocation() { 896 fn test_hover_macro_invocation() {
897 let (analysis, position) = single_file_with_position( 897 let (analysis, position) = analysis_and_position(
898 " 898 "
899 macro_rules! foo { 899 macro_rules! foo {
900 () => {} 900 () => {}
@@ -911,7 +911,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
911 911
912 #[test] 912 #[test]
913 fn test_hover_tuple_field() { 913 fn test_hover_tuple_field() {
914 let (analysis, position) = single_file_with_position( 914 let (analysis, position) = analysis_and_position(
915 " 915 "
916 struct TS(String, i32<|>); 916 struct TS(String, i32<|>);
917 ", 917 ",
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs
index f568d6baa..e99c2b0a3 100644
--- a/crates/ra_ide/src/mock_analysis.rs
+++ b/crates/ra_ide/src/mock_analysis.rs
@@ -221,11 +221,6 @@ pub fn single_file(ra_fixture: &str) -> (Analysis, FileId) {
221 (mock.analysis(), file_id) 221 (mock.analysis(), file_id)
222} 222}
223 223
224/// Creates analysis for a single file, returns position marked with <|>.
225pub fn single_file_with_position(ra_fixture: &str) -> (Analysis, FilePosition) {
226 analysis_and_position(ra_fixture)
227}
228
229/// Creates analysis for a single file, returns range marked with a pair of <|>. 224/// Creates analysis for a single file, returns range marked with a pair of <|>.
230pub fn single_file_with_range(ra_fixture: &str) -> (Analysis, FileRange) { 225pub fn single_file_with_range(ra_fixture: &str) -> (Analysis, FileRange) {
231 let mut mock = MockAnalysis::new(); 226 let mut mock = MockAnalysis::new();
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index 50929bb72..3433fdae3 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -191,7 +191,7 @@ fn get_struct_def_name_for_struct_literal_search(
191#[cfg(test)] 191#[cfg(test)]
192mod tests { 192mod tests {
193 use crate::{ 193 use crate::{
194 mock_analysis::{analysis_and_position, single_file_with_position, MockAnalysis}, 194 mock_analysis::{analysis_and_position, MockAnalysis},
195 Declaration, Reference, ReferenceSearchResult, SearchScope, 195 Declaration, Reference, ReferenceSearchResult, SearchScope,
196 }; 196 };
197 197
@@ -653,7 +653,7 @@ fn main() {
653 } 653 }
654 654
655 fn get_all_refs(ra_fixture: &str) -> ReferenceSearchResult { 655 fn get_all_refs(ra_fixture: &str) -> ReferenceSearchResult {
656 let (analysis, position) = single_file_with_position(ra_fixture); 656 let (analysis, position) = analysis_and_position(ra_fixture);
657 analysis.find_all_refs(position, None).unwrap().unwrap() 657 analysis.find_all_refs(position, None).unwrap().unwrap()
658 } 658 }
659 659
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs
index 91545e025..7ebc0adcf 100644
--- a/crates/ra_ide/src/references/rename.rs
+++ b/crates/ra_ide/src/references/rename.rs
@@ -271,12 +271,10 @@ fn rename_reference(
271mod tests { 271mod tests {
272 use insta::assert_debug_snapshot; 272 use insta::assert_debug_snapshot;
273 use ra_text_edit::TextEditBuilder; 273 use ra_text_edit::TextEditBuilder;
274 use stdx::trim_indent;
274 use test_utils::{assert_eq_text, mark}; 275 use test_utils::{assert_eq_text, mark};
275 276
276 use crate::{ 277 use crate::{mock_analysis::analysis_and_position, FileId};
277 mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId,
278 };
279 use stdx::trim_indent;
280 278
281 #[test] 279 #[test]
282 fn test_rename_to_underscore() { 280 fn test_rename_to_underscore() {
@@ -310,7 +308,7 @@ mod tests {
310 308
311 #[test] 309 #[test]
312 fn test_rename_to_invalid_identifier() { 310 fn test_rename_to_invalid_identifier() {
313 let (analysis, position) = single_file_with_position( 311 let (analysis, position) = analysis_and_position(
314 " 312 "
315 fn main() { 313 fn main() {
316 let i<|> = 1; 314 let i<|> = 1;
@@ -1056,7 +1054,7 @@ pub mod foo<|>;
1056 1054
1057 fn test_rename(ra_fixture_before: &str, new_name: &str, ra_fixture_after: &str) { 1055 fn test_rename(ra_fixture_before: &str, new_name: &str, ra_fixture_after: &str) {
1058 let ra_fixture_after = &trim_indent(ra_fixture_after); 1056 let ra_fixture_after = &trim_indent(ra_fixture_after);
1059 let (analysis, position) = single_file_with_position(ra_fixture_before); 1057 let (analysis, position) = analysis_and_position(ra_fixture_before);
1060 let source_change = analysis.rename(position, new_name).unwrap(); 1058 let source_change = analysis.rename(position, new_name).unwrap();
1061 let mut text_edit_builder = TextEditBuilder::default(); 1059 let mut text_edit_builder = TextEditBuilder::default();
1062 let mut file_id: Option<FileId> = None; 1060 let mut file_id: Option<FileId> = None;
diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs
index 50adae8bb..2faaa8ff0 100644
--- a/crates/ra_ide/src/typing/on_enter.rs
+++ b/crates/ra_ide/src/typing/on_enter.rs
@@ -77,11 +77,11 @@ fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option<SmolStr> {
77mod tests { 77mod tests {
78 use test_utils::assert_eq_text; 78 use test_utils::assert_eq_text;
79 79
80 use crate::mock_analysis::single_file_with_position; 80 use crate::mock_analysis::analysis_and_position;
81 use stdx::trim_indent; 81 use stdx::trim_indent;
82 82
83 fn apply_on_enter(before: &str) -> Option<String> { 83 fn apply_on_enter(before: &str) -> Option<String> {
84 let (analysis, position) = single_file_with_position(&before); 84 let (analysis, position) = analysis_and_position(&before);
85 let result = analysis.on_enter(position).unwrap()?; 85 let result = analysis.on_enter(position).unwrap()?;
86 86
87 let mut actual = analysis.file_text(position.file_id).unwrap().to_string(); 87 let mut actual = analysis.file_text(position.file_id).unwrap().to_string();