aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/call_hierarchy.rs40
-rw-r--r--crates/ra_ide/src/completion.rs12
-rw-r--r--crates/ra_ide/src/completion/complete_keyword.rs6
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs2
-rw-r--r--crates/ra_ide/src/completion/presentation.rs50
-rw-r--r--crates/ra_ide/src/diagnostics.rs42
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs45
-rw-r--r--crates/ra_ide/src/display/structure.rs428
-rw-r--r--crates/ra_ide/src/expand_macro.rs241
-rw-r--r--crates/ra_ide/src/folding_ranges.rs161
-rw-r--r--crates/ra_ide/src/goto_definition.rs1052
-rw-r--r--crates/ra_ide/src/goto_implementation.rs197
-rw-r--r--crates/ra_ide/src/goto_type_definition.rs14
-rw-r--r--crates/ra_ide/src/hover.rs72
-rw-r--r--crates/ra_ide/src/inlay_hints.rs976
-rw-r--r--crates/ra_ide/src/lib.rs6
-rw-r--r--crates/ra_ide/src/mock_analysis.rs24
-rw-r--r--crates/ra_ide/src/references.rs9
-rw-r--r--crates/ra_ide/src/references/rename.rs44
-rw-r--r--crates/ra_ide/src/runnables.rs1036
-rw-r--r--crates/ra_ide/src/snapshots/highlight_doctest.html101
-rw-r--r--crates/ra_ide/src/snapshots/highlight_injection.html47
-rw-r--r--crates/ra_ide/src/snapshots/highlight_strings.html95
-rw-r--r--crates/ra_ide/src/snapshots/highlight_unsafe.html53
-rw-r--r--crates/ra_ide/src/snapshots/highlighting.html117
-rw-r--r--crates/ra_ide/src/snapshots/rainbow_highlighting.html48
-rw-r--r--crates/ra_ide/src/ssr.rs14
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs22
28 files changed, 2032 insertions, 2922 deletions
diff --git a/crates/ra_ide/src/call_hierarchy.rs b/crates/ra_ide/src/call_hierarchy.rs
index 1e3a31602..884353808 100644
--- a/crates/ra_ide/src/call_hierarchy.rs
+++ b/crates/ra_ide/src/call_hierarchy.rs
@@ -39,10 +39,11 @@ pub(crate) fn call_hierarchy(
39 39
40pub(crate) fn incoming_calls(db: &RootDatabase, position: FilePosition) -> Option<Vec<CallItem>> { 40pub(crate) fn incoming_calls(db: &RootDatabase, position: FilePosition) -> Option<Vec<CallItem>> {
41 let sema = Semantics::new(db); 41 let sema = Semantics::new(db);
42
42 // 1. Find all refs 43 // 1. Find all refs
43 // 2. Loop through refs and determine unique fndef. This will become our `from: CallHierarchyItem,` in the reply. 44 // 2. Loop through refs and determine unique fndef. This will become our `from: CallHierarchyItem,` in the reply.
44 // 3. Add ranges relative to the start of the fndef. 45 // 3. Add ranges relative to the start of the fndef.
45 let refs = references::find_all_refs(db, position, None)?; 46 let refs = references::find_all_refs(&sema, position, None)?;
46 47
47 let mut calls = CallLocations::default(); 48 let mut calls = CallLocations::default();
48 49
@@ -355,4 +356,41 @@ fn caller3() {
355 &["caller3 FN_DEF FileId(1) 66..83 69..76 : [52..59]"], 356 &["caller3 FN_DEF FileId(1) 66..83 69..76 : [52..59]"],
356 ); 357 );
357 } 358 }
359
360 #[test]
361 fn test_call_hierarchy_issue_5103() {
362 check_hierarchy(
363 r#"
364fn a() {
365 b()
366}
367
368fn b() {}
369
370fn main() {
371 a<|>()
372}
373"#,
374 "a FN_DEF FileId(1) 0..18 3..4",
375 &["main FN_DEF FileId(1) 31..52 34..38 : [47..48]"],
376 &["b FN_DEF FileId(1) 20..29 23..24 : [13..14]"],
377 );
378
379 check_hierarchy(
380 r#"
381fn a() {
382 b<|>()
383}
384
385fn b() {}
386
387fn main() {
388 a()
389}
390"#,
391 "b FN_DEF FileId(1) 20..29 23..24",
392 &["a FN_DEF FileId(1) 0..18 3..4 : [13..14]"],
393 &[],
394 );
395 }
358} 396}
diff --git a/crates/ra_ide/src/completion.rs b/crates/ra_ide/src/completion.rs
index e1fcf379d..9ebb8ebb7 100644
--- a/crates/ra_ide/src/completion.rs
+++ b/crates/ra_ide/src/completion.rs
@@ -63,11 +63,11 @@ pub use crate::completion::{
63// There also snippet completions: 63// There also snippet completions:
64// 64//
65// .Expressions 65// .Expressions
66// - `pd` -> `println!("{:?}")` 66// - `pd` -> `eprintln!(" = {:?}", );")`
67// - `ppd` -> `println!("{:#?}")` 67// - `ppd` -> `eprintln!(" = {:#?}", );`
68// 68//
69// .Items 69// .Items
70// - `tfn` -> `#[test] fn f(){}` 70// - `tfn` -> `#[test] fn feature(){}`
71// - `tmod` -> 71// - `tmod` ->
72// ```rust 72// ```rust
73// #[cfg(test)] 73// #[cfg(test)]
@@ -75,7 +75,7 @@ pub use crate::completion::{
75// use super::*; 75// use super::*;
76// 76//
77// #[test] 77// #[test]
78// fn test_fn() {} 78// fn test_name() {}
79// } 79// }
80// ``` 80// ```
81 81
@@ -137,8 +137,8 @@ mod tests {
137 documentation: &'a str, 137 documentation: &'a str,
138 } 138 }
139 139
140 fn check_detail_and_documentation(fixture: &str, expected: DetailAndDocumentation) { 140 fn check_detail_and_documentation(ra_fixture: &str, expected: DetailAndDocumentation) {
141 let (analysis, position) = analysis_and_position(fixture); 141 let (analysis, position) = analysis_and_position(ra_fixture);
142 let config = CompletionConfig::default(); 142 let config = CompletionConfig::default();
143 let completions = analysis.completions(&config, position).unwrap().unwrap(); 143 let completions = analysis.completions(&config, position).unwrap().unwrap();
144 for item in completions { 144 for item in completions {
diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs
index 3b174f916..e599cc3d1 100644
--- a/crates/ra_ide/src/completion/complete_keyword.rs
+++ b/crates/ra_ide/src/completion/complete_keyword.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use ra_syntax::ast; 3use ra_syntax::{ast, SyntaxKind};
4 4
5use crate::completion::{ 5use crate::completion::{
6 CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions, 6 CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
@@ -37,6 +37,10 @@ pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC
37} 37}
38 38
39pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) { 39pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) {
40 if ctx.token.kind() == SyntaxKind::COMMENT {
41 return;
42 }
43
40 let has_trait_or_impl_parent = ctx.has_impl_parent || ctx.has_trait_parent; 44 let has_trait_or_impl_parent = ctx.has_impl_parent || ctx.has_trait_parent;
41 if ctx.trait_as_prev_sibling || ctx.impl_as_prev_sibling { 45 if ctx.trait_as_prev_sibling || ctx.impl_as_prev_sibling {
42 add_keyword(ctx, acc, "where", "where "); 46 add_keyword(ctx, acc, "where", "where ");
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index 560fb19e6..ef22ea54d 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -213,7 +213,7 @@ impl<'a> CompletionContext<'a> {
213 } 213 }
214 } 214 }
215 215
216 pub(crate) fn scope(&self) -> SemanticsScope<'_, RootDatabase> { 216 pub(crate) fn scope(&self) -> SemanticsScope<'_> {
217 self.sema.scope_at_offset(&self.token.parent(), self.offset) 217 self.sema.scope_at_offset(&self.token.parent(), self.offset)
218 } 218 }
219 219
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index 4fdc2f0bb..b18279746 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -1516,4 +1516,54 @@ mod tests {
1516 "### 1516 "###
1517 ); 1517 );
1518 } 1518 }
1519
1520 #[test]
1521 fn no_keyword_autocompletion_on_line_comments() {
1522 assert_debug_snapshot!(
1523 do_completion(
1524 r"
1525 fn test() {
1526 let x = 2; // A comment<|>
1527 }
1528 ",
1529 CompletionKind::Keyword
1530 ),
1531 @r###"
1532 []
1533 "###
1534 );
1535 }
1536
1537 #[test]
1538 fn no_keyword_autocompletion_on_multi_line_comments() {
1539 assert_debug_snapshot!(
1540 do_completion(
1541 r"
1542 /*
1543 Some multi-line comment<|>
1544 */
1545 ",
1546 CompletionKind::Keyword
1547 ),
1548 @r###"
1549 []
1550 "###
1551 );
1552 }
1553
1554 #[test]
1555 fn no_keyword_autocompletion_on_doc_comments() {
1556 assert_debug_snapshot!(
1557 do_completion(
1558 r"
1559 /// Some doc comment
1560 /// let test<|> = 1
1561 ",
1562 CompletionKind::Keyword
1563 ),
1564 @r###"
1565 []
1566 "###
1567 );
1568 }
1519} 1569}
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index 05fb799d6..46f8c31c7 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -324,10 +324,10 @@ mod tests {
324 /// * a diagnostic is produced 324 /// * a diagnostic is produced
325 /// * this diagnostic touches the input cursor position 325 /// * this diagnostic touches the input cursor position
326 /// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied 326 /// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied
327 fn check_apply_diagnostic_fix_from_position(fixture: &str, after: &str) { 327 fn check_apply_diagnostic_fix_from_position(ra_fixture: &str, after: &str) {
328 let after = trim_indent(after); 328 let after = trim_indent(after);
329 329
330 let (analysis, file_position) = analysis_and_position(fixture); 330 let (analysis, file_position) = analysis_and_position(ra_fixture);
331 let diagnostic = analysis.diagnostics(file_position.file_id).unwrap().pop().unwrap(); 331 let diagnostic = analysis.diagnostics(file_position.file_id).unwrap().pop().unwrap();
332 let mut fix = diagnostic.fix.unwrap(); 332 let mut fix = diagnostic.fix.unwrap();
333 let edit = fix.source_change.source_file_edits.pop().unwrap().edit; 333 let edit = fix.source_change.source_file_edits.pop().unwrap().edit;
@@ -365,14 +365,14 @@ mod tests {
365 365
366 /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics 366 /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics
367 /// apply to the file containing the cursor. 367 /// apply to the file containing the cursor.
368 fn check_no_diagnostic_for_target_file(fixture: &str) { 368 fn check_no_diagnostic_for_target_file(ra_fixture: &str) {
369 let (analysis, file_position) = analysis_and_position(fixture); 369 let (analysis, file_position) = analysis_and_position(ra_fixture);
370 let diagnostics = analysis.diagnostics(file_position.file_id).unwrap(); 370 let diagnostics = analysis.diagnostics(file_position.file_id).unwrap();
371 assert_eq!(diagnostics.len(), 0); 371 assert_eq!(diagnostics.len(), 0);
372 } 372 }
373 373
374 fn check_no_diagnostic(content: &str) { 374 fn check_no_diagnostic(ra_fixture: &str) {
375 let (analysis, file_id) = single_file(content); 375 let (analysis, file_id) = single_file(ra_fixture);
376 let diagnostics = analysis.diagnostics(file_id).unwrap(); 376 let diagnostics = analysis.diagnostics(file_id).unwrap();
377 assert_eq!(diagnostics.len(), 0, "expected no diagnostic, found one"); 377 assert_eq!(diagnostics.len(), 0, "expected no diagnostic, found one");
378 } 378 }
@@ -473,7 +473,8 @@ mod tests {
473 473
474 #[test] 474 #[test]
475 fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() { 475 fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() {
476 let content = r#" 476 check_no_diagnostic_for_target_file(
477 r"
477 //- /main.rs 478 //- /main.rs
478 use core::result::Result::{self, Ok, Err}; 479 use core::result::Result::{self, Ok, Err};
479 480
@@ -485,13 +486,14 @@ mod tests {
485 pub mod result { 486 pub mod result {
486 pub enum Result<T, E> { Ok(T), Err(E) } 487 pub enum Result<T, E> { Ok(T), Err(E) }
487 } 488 }
488 "#; 489 ",
489 check_no_diagnostic_for_target_file(content); 490 );
490 } 491 }
491 492
492 #[test] 493 #[test]
493 fn test_wrap_return_type_not_applicable_when_return_type_is_not_result() { 494 fn test_wrap_return_type_not_applicable_when_return_type_is_not_result() {
494 let content = r#" 495 check_no_diagnostic_for_target_file(
496 r"
495 //- /main.rs 497 //- /main.rs
496 use core::result::Result::{self, Ok, Err}; 498 use core::result::Result::{self, Ok, Err};
497 499
@@ -508,8 +510,8 @@ mod tests {
508 pub mod result { 510 pub mod result {
509 pub enum Result<T, E> { Ok(T), Err(E) } 511 pub enum Result<T, E> { Ok(T), Err(E) }
510 } 512 }
511 "#; 513 ",
512 check_no_diagnostic_for_target_file(content); 514 );
513 } 515 }
514 516
515 #[test] 517 #[test]
@@ -618,7 +620,8 @@ mod tests {
618 620
619 #[test] 621 #[test]
620 fn test_fill_struct_fields_no_diagnostic() { 622 fn test_fill_struct_fields_no_diagnostic() {
621 let content = r" 623 check_no_diagnostic(
624 r"
622 struct TestStruct { 625 struct TestStruct {
623 one: i32, 626 one: i32,
624 two: i64, 627 two: i64,
@@ -628,14 +631,14 @@ mod tests {
628 let one = 1; 631 let one = 1;
629 let s = TestStruct{ one, two: 2 }; 632 let s = TestStruct{ one, two: 2 };
630 } 633 }
631 "; 634 ",
632 635 );
633 check_no_diagnostic(content);
634 } 636 }
635 637
636 #[test] 638 #[test]
637 fn test_fill_struct_fields_no_diagnostic_on_spread() { 639 fn test_fill_struct_fields_no_diagnostic_on_spread() {
638 let content = r" 640 check_no_diagnostic(
641 r"
639 struct TestStruct { 642 struct TestStruct {
640 one: i32, 643 one: i32,
641 two: i64, 644 two: i64,
@@ -645,9 +648,8 @@ mod tests {
645 let one = 1; 648 let one = 1;
646 let s = TestStruct{ ..a }; 649 let s = TestStruct{ ..a };
647 } 650 }
648 "; 651 ",
649 652 );
650 check_no_diagnostic(content);
651 } 653 }
652 654
653 #[test] 655 #[test]
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs
index 0b52b01ab..8bf2428ed 100644
--- a/crates/ra_ide/src/display/navigation_target.rs
+++ b/crates/ra_ide/src/display/navigation_target.rs
@@ -11,7 +11,7 @@ use ra_syntax::{
11 TextRange, 11 TextRange,
12}; 12};
13 13
14use crate::{FileRange, FileSymbol}; 14use crate::FileSymbol;
15 15
16use super::short_label::ShortLabel; 16use super::short_label::ShortLabel;
17 17
@@ -47,6 +47,19 @@ impl NavigationTarget {
47 pub fn range(&self) -> TextRange { 47 pub fn range(&self) -> TextRange {
48 self.focus_range.unwrap_or(self.full_range) 48 self.focus_range.unwrap_or(self.full_range)
49 } 49 }
50 /// A "most interesting" range withing the `full_range`.
51 ///
52 /// Typically, `full_range` is the whole syntax node,
53 /// including doc comments, and `focus_range` is the range of the identifier.
54 pub fn focus_range(&self) -> Option<TextRange> {
55 self.focus_range
56 }
57 pub fn full_range(&self) -> TextRange {
58 self.full_range
59 }
60 pub fn file_id(&self) -> FileId {
61 self.file_id
62 }
50 63
51 pub fn name(&self) -> &SmolStr { 64 pub fn name(&self) -> &SmolStr {
52 &self.name 65 &self.name
@@ -60,18 +73,6 @@ impl NavigationTarget {
60 self.kind 73 self.kind
61 } 74 }
62 75
63 pub fn file_id(&self) -> FileId {
64 self.file_id
65 }
66
67 pub fn file_range(&self) -> FileRange {
68 FileRange { file_id: self.file_id, range: self.full_range }
69 }
70
71 pub fn full_range(&self) -> TextRange {
72 self.full_range
73 }
74
75 pub fn docs(&self) -> Option<&str> { 76 pub fn docs(&self) -> Option<&str> {
76 self.docs.as_deref() 77 self.docs.as_deref()
77 } 78 }
@@ -80,14 +81,6 @@ impl NavigationTarget {
80 self.description.as_deref() 81 self.description.as_deref()
81 } 82 }
82 83
83 /// A "most interesting" range withing the `full_range`.
84 ///
85 /// Typically, `full_range` is the whole syntax node,
86 /// including doc comments, and `focus_range` is the range of the identifier.
87 pub fn focus_range(&self) -> Option<TextRange> {
88 self.focus_range
89 }
90
91 pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget { 84 pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
92 let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default(); 85 let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
93 if let Some(src) = module.declaration_source(db) { 86 if let Some(src) = module.declaration_source(db) {
@@ -278,16 +271,22 @@ impl ToNav for hir::Module {
278impl ToNav for hir::ImplDef { 271impl ToNav for hir::ImplDef {
279 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 272 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
280 let src = self.source(db); 273 let src = self.source(db);
281 let frange = if let Some(item) = self.is_builtin_derive(db) { 274 let derive_attr = self.is_builtin_derive(db);
275 let frange = if let Some(item) = &derive_attr {
282 original_range(db, item.syntax()) 276 original_range(db, item.syntax())
283 } else { 277 } else {
284 original_range(db, src.as_ref().map(|it| it.syntax())) 278 original_range(db, src.as_ref().map(|it| it.syntax()))
285 }; 279 };
280 let focus_range = if derive_attr.is_some() {
281 None
282 } else {
283 src.value.target_type().map(|ty| original_range(db, src.with_value(ty.syntax())).range)
284 };
286 285
287 NavigationTarget::from_syntax( 286 NavigationTarget::from_syntax(
288 frange.file_id, 287 frange.file_id,
289 "impl".into(), 288 "impl".into(),
290 None, 289 focus_range,
291 frange.range, 290 frange.range,
292 src.value.syntax().kind(), 291 src.value.syntax().kind(),
293 ) 292 )
diff --git a/crates/ra_ide/src/display/structure.rs b/crates/ra_ide/src/display/structure.rs
index aad5a8e4d..c22a5d17b 100644
--- a/crates/ra_ide/src/display/structure.rs
+++ b/crates/ra_ide/src/display/structure.rs
@@ -173,12 +173,19 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
173 173
174#[cfg(test)] 174#[cfg(test)]
175mod tests { 175mod tests {
176 use expect::{expect, Expect};
177
176 use super::*; 178 use super::*;
177 use insta::assert_debug_snapshot; 179
180 fn check(ra_fixture: &str, expect: Expect) {
181 let file = SourceFile::parse(ra_fixture).ok().unwrap();
182 let structure = file_structure(&file);
183 expect.assert_debug_eq(&structure)
184 }
178 185
179 #[test] 186 #[test]
180 fn test_file_structure() { 187 fn test_file_structure() {
181 let file = SourceFile::parse( 188 check(
182 r#" 189 r#"
183struct Foo { 190struct Foo {
184 x: i32 191 x: i32
@@ -223,216 +230,211 @@ fn obsolete() {}
223#[deprecated(note = "for awhile")] 230#[deprecated(note = "for awhile")]
224fn very_obsolete() {} 231fn very_obsolete() {}
225"#, 232"#,
226 ) 233 expect![[r#"
227 .ok() 234 [
228 .unwrap(); 235 StructureNode {
229 let structure = file_structure(&file); 236 parent: None,
230 assert_debug_snapshot!(structure, 237 label: "Foo",
231 @r###" 238 navigation_range: 8..11,
232 [ 239 node_range: 1..26,
233 StructureNode { 240 kind: STRUCT_DEF,
234 parent: None, 241 detail: None,
235 label: "Foo", 242 deprecated: false,
236 navigation_range: 8..11, 243 },
237 node_range: 1..26, 244 StructureNode {
238 kind: STRUCT_DEF, 245 parent: Some(
239 detail: None, 246 0,
240 deprecated: false, 247 ),
241 }, 248 label: "x",
242 StructureNode { 249 navigation_range: 18..19,
243 parent: Some( 250 node_range: 18..24,
244 0, 251 kind: RECORD_FIELD_DEF,
245 ), 252 detail: Some(
246 label: "x", 253 "i32",
247 navigation_range: 18..19, 254 ),
248 node_range: 18..24, 255 deprecated: false,
249 kind: RECORD_FIELD_DEF, 256 },
250 detail: Some( 257 StructureNode {
251 "i32", 258 parent: None,
252 ), 259 label: "m",
253 deprecated: false, 260 navigation_range: 32..33,
254 }, 261 node_range: 28..158,
255 StructureNode { 262 kind: MODULE,
256 parent: None, 263 detail: None,
257 label: "m", 264 deprecated: false,
258 navigation_range: 32..33, 265 },
259 node_range: 28..158, 266 StructureNode {
260 kind: MODULE, 267 parent: Some(
261 detail: None, 268 2,
262 deprecated: false, 269 ),
263 }, 270 label: "bar1",
264 StructureNode { 271 navigation_range: 43..47,
265 parent: Some( 272 node_range: 40..52,
266 2, 273 kind: FN_DEF,
267 ), 274 detail: Some(
268 label: "bar1", 275 "fn()",
269 navigation_range: 43..47, 276 ),
270 node_range: 40..52, 277 deprecated: false,
271 kind: FN_DEF, 278 },
272 detail: Some( 279 StructureNode {
273 "fn()", 280 parent: Some(
274 ), 281 2,
275 deprecated: false, 282 ),
276 }, 283 label: "bar2",
277 StructureNode { 284 navigation_range: 60..64,
278 parent: Some( 285 node_range: 57..81,
279 2, 286 kind: FN_DEF,
280 ), 287 detail: Some(
281 label: "bar2", 288 "fn<T>(t: T) -> T",
282 navigation_range: 60..64, 289 ),
283 node_range: 57..81, 290 deprecated: false,
284 kind: FN_DEF, 291 },
285 detail: Some( 292 StructureNode {
286 "fn<T>(t: T) -> T", 293 parent: Some(
287 ), 294 2,
288 deprecated: false, 295 ),
289 }, 296 label: "bar3",
290 StructureNode { 297 navigation_range: 89..93,
291 parent: Some( 298 node_range: 86..156,
292 2, 299 kind: FN_DEF,
293 ), 300 detail: Some(
294 label: "bar3", 301 "fn<A, B>(a: A, b: B) -> Vec< u32 >",
295 navigation_range: 89..93, 302 ),
296 node_range: 86..156, 303 deprecated: false,
297 kind: FN_DEF, 304 },
298 detail: Some( 305 StructureNode {
299 "fn<A, B>(a: A, b: B) -> Vec< u32 >", 306 parent: None,
300 ), 307 label: "E",
301 deprecated: false, 308 navigation_range: 165..166,
302 }, 309 node_range: 160..180,
303 StructureNode { 310 kind: ENUM_DEF,
304 parent: None, 311 detail: None,
305 label: "E", 312 deprecated: false,
306 navigation_range: 165..166, 313 },
307 node_range: 160..180, 314 StructureNode {
308 kind: ENUM_DEF, 315 parent: Some(
309 detail: None, 316 6,
310 deprecated: false, 317 ),
311 }, 318 label: "X",
312 StructureNode { 319 navigation_range: 169..170,
313 parent: Some( 320 node_range: 169..170,
314 6, 321 kind: ENUM_VARIANT,
315 ), 322 detail: None,
316 label: "X", 323 deprecated: false,
317 navigation_range: 169..170, 324 },
318 node_range: 169..170, 325 StructureNode {
319 kind: ENUM_VARIANT, 326 parent: Some(
320 detail: None, 327 6,
321 deprecated: false, 328 ),
322 }, 329 label: "Y",
323 StructureNode { 330 navigation_range: 172..173,
324 parent: Some( 331 node_range: 172..178,
325 6, 332 kind: ENUM_VARIANT,
326 ), 333 detail: None,
327 label: "Y", 334 deprecated: false,
328 navigation_range: 172..173, 335 },
329 node_range: 172..178, 336 StructureNode {
330 kind: ENUM_VARIANT, 337 parent: None,
331 detail: None, 338 label: "T",
332 deprecated: false, 339 navigation_range: 186..187,
333 }, 340 node_range: 181..193,
334 StructureNode { 341 kind: TYPE_ALIAS_DEF,
335 parent: None, 342 detail: Some(
336 label: "T", 343 "()",
337 navigation_range: 186..187, 344 ),
338 node_range: 181..193, 345 deprecated: false,
339 kind: TYPE_ALIAS_DEF, 346 },
340 detail: Some( 347 StructureNode {
341 "()", 348 parent: None,
342 ), 349 label: "S",
343 deprecated: false, 350 navigation_range: 201..202,
344 }, 351 node_range: 194..213,
345 StructureNode { 352 kind: STATIC_DEF,
346 parent: None, 353 detail: Some(
347 label: "S", 354 "i32",
348 navigation_range: 201..202, 355 ),
349 node_range: 194..213, 356 deprecated: false,
350 kind: STATIC_DEF, 357 },
351 detail: Some( 358 StructureNode {
352 "i32", 359 parent: None,
353 ), 360 label: "C",
354 deprecated: false, 361 navigation_range: 220..221,
355 }, 362 node_range: 214..232,
356 StructureNode { 363 kind: CONST_DEF,
357 parent: None, 364 detail: Some(
358 label: "C", 365 "i32",
359 navigation_range: 220..221, 366 ),
360 node_range: 214..232, 367 deprecated: false,
361 kind: CONST_DEF, 368 },
362 detail: Some( 369 StructureNode {
363 "i32", 370 parent: None,
364 ), 371 label: "impl E",
365 deprecated: false, 372 navigation_range: 239..240,
366 }, 373 node_range: 234..243,
367 StructureNode { 374 kind: IMPL_DEF,
368 parent: None, 375 detail: None,
369 label: "impl E", 376 deprecated: false,
370 navigation_range: 239..240, 377 },
371 node_range: 234..243, 378 StructureNode {
372 kind: IMPL_DEF, 379 parent: None,
373 detail: None, 380 label: "impl fmt::Debug for E",
374 deprecated: false, 381 navigation_range: 265..266,
375 }, 382 node_range: 245..269,
376 StructureNode { 383 kind: IMPL_DEF,
377 parent: None, 384 detail: None,
378 label: "impl fmt::Debug for E", 385 deprecated: false,
379 navigation_range: 265..266, 386 },
380 node_range: 245..269, 387 StructureNode {
381 kind: IMPL_DEF, 388 parent: None,
382 detail: None, 389 label: "mc",
383 deprecated: false, 390 navigation_range: 284..286,
384 }, 391 node_range: 271..303,
385 StructureNode { 392 kind: MACRO_CALL,
386 parent: None, 393 detail: None,
387 label: "mc", 394 deprecated: false,
388 navigation_range: 284..286, 395 },
389 node_range: 271..303, 396 StructureNode {
390 kind: MACRO_CALL, 397 parent: None,
391 detail: None, 398 label: "mcexp",
392 deprecated: false, 399 navigation_range: 334..339,
393 }, 400 node_range: 305..356,
394 StructureNode { 401 kind: MACRO_CALL,
395 parent: None, 402 detail: None,
396 label: "mcexp", 403 deprecated: false,
397 navigation_range: 334..339, 404 },
398 node_range: 305..356, 405 StructureNode {
399 kind: MACRO_CALL, 406 parent: None,
400 detail: None, 407 label: "mcexp",
401 deprecated: false, 408 navigation_range: 387..392,
402 }, 409 node_range: 358..409,
403 StructureNode { 410 kind: MACRO_CALL,
404 parent: None, 411 detail: None,
405 label: "mcexp", 412 deprecated: false,
406 navigation_range: 387..392, 413 },
407 node_range: 358..409, 414 StructureNode {
408 kind: MACRO_CALL, 415 parent: None,
409 detail: None, 416 label: "obsolete",
410 deprecated: false, 417 navigation_range: 428..436,
411 }, 418 node_range: 411..441,
412 StructureNode { 419 kind: FN_DEF,
413 parent: None, 420 detail: Some(
414 label: "obsolete", 421 "fn()",
415 navigation_range: 428..436, 422 ),
416 node_range: 411..441, 423 deprecated: true,
417 kind: FN_DEF, 424 },
418 detail: Some( 425 StructureNode {
419 "fn()", 426 parent: None,
420 ), 427 label: "very_obsolete",
421 deprecated: true, 428 navigation_range: 481..494,
422 }, 429 node_range: 443..499,
423 StructureNode { 430 kind: FN_DEF,
424 parent: None, 431 detail: Some(
425 label: "very_obsolete", 432 "fn()",
426 navigation_range: 481..494, 433 ),
427 node_range: 443..499, 434 deprecated: true,
428 kind: FN_DEF, 435 },
429 detail: Some( 436 ]
430 "fn()", 437 "#]],
431 ), 438 );
432 deprecated: true,
433 },
434 ]
435 "###
436 );
437 } 439 }
438} 440}
diff --git a/crates/ra_ide/src/expand_macro.rs b/crates/ra_ide/src/expand_macro.rs
index 54a47aac0..043515f54 100644
--- a/crates/ra_ide/src/expand_macro.rs
+++ b/crates/ra_ide/src/expand_macro.rs
@@ -2,7 +2,9 @@ use hir::Semantics;
2use ra_ide_db::RootDatabase; 2use ra_ide_db::RootDatabase;
3use ra_syntax::{ 3use ra_syntax::{
4 algo::{find_node_at_offset, SyntaxRewriter}, 4 algo::{find_node_at_offset, SyntaxRewriter},
5 ast, AstNode, NodeOrToken, SyntaxKind, SyntaxNode, WalkEvent, T, 5 ast, AstNode, NodeOrToken, SyntaxKind,
6 SyntaxKind::*,
7 SyntaxNode, WalkEvent, T,
6}; 8};
7 9
8use crate::FilePosition; 10use crate::FilePosition;
@@ -65,8 +67,6 @@ fn expand_macro_recur(
65// FIXME: It would also be cool to share logic here and in the mbe tests, 67// FIXME: It would also be cool to share logic here and in the mbe tests,
66// which are pretty unreadable at the moment. 68// which are pretty unreadable at the moment.
67fn insert_whitespaces(syn: SyntaxNode) -> String { 69fn insert_whitespaces(syn: SyntaxNode) -> String {
68 use SyntaxKind::*;
69
70 let mut res = String::new(); 70 let mut res = String::new();
71 let mut token_iter = syn 71 let mut token_iter = syn
72 .preorder_with_tokens() 72 .preorder_with_tokens()
@@ -120,175 +120,164 @@ fn insert_whitespaces(syn: SyntaxNode) -> String {
120 120
121#[cfg(test)] 121#[cfg(test)]
122mod tests { 122mod tests {
123 use insta::assert_snapshot; 123 use expect::{expect, Expect};
124 124
125 use crate::mock_analysis::analysis_and_position; 125 use crate::mock_analysis::analysis_and_position;
126 126
127 use super::*; 127 fn check(ra_fixture: &str, expect: Expect) {
128 128 let (analysis, pos) = analysis_and_position(ra_fixture);
129 fn check_expand_macro(fixture: &str) -> ExpandedMacro { 129 let expansion = analysis.expand_macro(pos).unwrap().unwrap();
130 let (analysis, pos) = analysis_and_position(fixture); 130 let actual = format!("{}\n{}", expansion.name, expansion.expansion);
131 analysis.expand_macro(pos).unwrap().unwrap() 131 expect.assert_eq(&actual);
132 } 132 }
133 133
134 #[test] 134 #[test]
135 fn macro_expand_recursive_expansion() { 135 fn macro_expand_recursive_expansion() {
136 let res = check_expand_macro( 136 check(
137 r#" 137 r#"
138 //- /lib.rs 138macro_rules! bar {
139 macro_rules! bar { 139 () => { fn b() {} }
140 () => { fn b() {} } 140}
141 } 141macro_rules! foo {
142 macro_rules! foo { 142 () => { bar!(); }
143 () => { bar!(); } 143}
144 } 144macro_rules! baz {
145 macro_rules! baz { 145 () => { foo!(); }
146 () => { foo!(); } 146}
147 } 147f<|>oo!();
148 f<|>oo!(); 148"#,
149 "#, 149 expect![[r#"
150 foo
151 fn b(){}
152 "#]],
150 ); 153 );
151
152 assert_eq!(res.name, "foo");
153 assert_snapshot!(res.expansion, @r###"
154fn b(){}
155"###);
156 } 154 }
157 155
158 #[test] 156 #[test]
159 fn macro_expand_multiple_lines() { 157 fn macro_expand_multiple_lines() {
160 let res = check_expand_macro( 158 check(
161 r#" 159 r#"
162 //- /lib.rs 160macro_rules! foo {
163 macro_rules! foo { 161 () => {
164 () => { 162 fn some_thing() -> u32 {
165 fn some_thing() -> u32 { 163 let a = 0;
166 let a = 0; 164 a + 10
167 a + 10
168 }
169 }
170 } 165 }
171 f<|>oo!(); 166 }
167}
168f<|>oo!();
172 "#, 169 "#,
170 expect![[r#"
171 foo
172 fn some_thing() -> u32 {
173 let a = 0;
174 a+10
175 }"#]],
173 ); 176 );
174
175 assert_eq!(res.name, "foo");
176 assert_snapshot!(res.expansion, @r###"
177fn some_thing() -> u32 {
178 let a = 0;
179 a+10
180}
181"###);
182 } 177 }
183 178
184 #[test] 179 #[test]
185 fn macro_expand_match_ast() { 180 fn macro_expand_match_ast() {
186 let res = check_expand_macro( 181 check(
187 r#" 182 r#"
188 //- /lib.rs 183macro_rules! match_ast {
189 macro_rules! match_ast { 184 (match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) };
190 (match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) }; 185 (match ($node:expr) {
186 $( ast::$ast:ident($it:ident) => $res:block, )*
187 _ => $catch_all:expr $(,)?
188 }) => {{
189 $( if let Some($it) = ast::$ast::cast($node.clone()) $res else )*
190 { $catch_all }
191 }};
192}
191 193
192 (match ($node:expr) { 194fn main() {
193 $( ast::$ast:ident($it:ident) => $res:block, )* 195 mat<|>ch_ast! {
194 _ => $catch_all:expr $(,)? 196 match container {
195 }) => {{ 197 ast::TraitDef(it) => {},
196 $( if let Some($it) = ast::$ast::cast($node.clone()) $res else )* 198 ast::ImplDef(it) => {},
197 { $catch_all } 199 _ => { continue },
198 }};
199 } 200 }
200
201 fn main() {
202 mat<|>ch_ast! {
203 match container {
204 ast::TraitDef(it) => {},
205 ast::ImplDef(it) => {},
206 _ => { continue },
207 }
208 }
209 }
210 "#,
211 );
212
213 assert_eq!(res.name, "match_ast");
214 assert_snapshot!(res.expansion, @r###"
215{
216 if let Some(it) = ast::TraitDef::cast(container.clone()){}
217 else if let Some(it) = ast::ImplDef::cast(container.clone()){}
218 else {
219 {
220 continue
221 } 201 }
222 }
223} 202}
224"###); 203"#,
204 expect![[r#"
205 match_ast
206 {
207 if let Some(it) = ast::TraitDef::cast(container.clone()){}
208 else if let Some(it) = ast::ImplDef::cast(container.clone()){}
209 else {
210 {
211 continue
212 }
213 }
214 }"#]],
215 );
225 } 216 }
226 217
227 #[test] 218 #[test]
228 fn macro_expand_match_ast_inside_let_statement() { 219 fn macro_expand_match_ast_inside_let_statement() {
229 let res = check_expand_macro( 220 check(
230 r#" 221 r#"
231 //- /lib.rs 222macro_rules! match_ast {
232 macro_rules! match_ast { 223 (match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) };
233 (match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) }; 224 (match ($node:expr) {}) => {{}};
234 (match ($node:expr) {}) => {{}}; 225}
235 }
236 226
237 fn main() { 227fn main() {
238 let p = f(|it| { 228 let p = f(|it| {
239 let res = mat<|>ch_ast! { match c {}}; 229 let res = mat<|>ch_ast! { match c {}};
240 Some(res) 230 Some(res)
241 })?; 231 })?;
242 } 232}
243 "#, 233"#,
234 expect![[r#"
235 match_ast
236 {}
237 "#]],
244 ); 238 );
245
246 assert_eq!(res.name, "match_ast");
247 assert_snapshot!(res.expansion, @r###"{}"###);
248 } 239 }
249 240
250 #[test] 241 #[test]
251 fn macro_expand_inner_macro_fail_to_expand() { 242 fn macro_expand_inner_macro_fail_to_expand() {
252 let res = check_expand_macro( 243 check(
253 r#" 244 r#"
254 //- /lib.rs 245macro_rules! bar {
255 macro_rules! bar { 246 (BAD) => {};
256 (BAD) => {}; 247}
257 } 248macro_rules! foo {
258 macro_rules! foo { 249 () => {bar!()};
259 () => {bar!()}; 250}
260 }
261 251
262 fn main() { 252fn main() {
263 let res = fo<|>o!(); 253 let res = fo<|>o!();
264 } 254}
265 "#, 255"#,
256 expect![[r#"
257 foo
258 "#]],
266 ); 259 );
267
268 assert_eq!(res.name, "foo");
269 assert_snapshot!(res.expansion, @r###""###);
270 } 260 }
271 261
272 #[test] 262 #[test]
273 fn macro_expand_with_dollar_crate() { 263 fn macro_expand_with_dollar_crate() {
274 let res = check_expand_macro( 264 check(
275 r#" 265 r#"
276 //- /lib.rs 266#[macro_export]
277 #[macro_export] 267macro_rules! bar {
278 macro_rules! bar { 268 () => {0};
279 () => {0}; 269}
280 } 270macro_rules! foo {
281 macro_rules! foo { 271 () => {$crate::bar!()};
282 () => {$crate::bar!()}; 272}
283 }
284 273
285 fn main() { 274fn main() {
286 let res = fo<|>o!(); 275 let res = fo<|>o!();
287 } 276}
288 "#, 277"#,
278 expect![[r#"
279 foo
280 0 "#]],
289 ); 281 );
290
291 assert_eq!(res.name, "foo");
292 assert_snapshot!(res.expansion, @r###"0"###);
293 } 282 }
294} 283}
diff --git a/crates/ra_ide/src/folding_ranges.rs b/crates/ra_ide/src/folding_ranges.rs
index 8657377de..5cec689f8 100644
--- a/crates/ra_ide/src/folding_ranges.rs
+++ b/crates/ra_ide/src/folding_ranges.rs
@@ -15,6 +15,7 @@ pub enum FoldKind {
15 Imports, 15 Imports,
16 Mods, 16 Mods,
17 Block, 17 Block,
18 ArgList,
18} 19}
19 20
20#[derive(Debug)] 21#[derive(Debug)]
@@ -83,6 +84,7 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {
83 match kind { 84 match kind {
84 COMMENT => Some(FoldKind::Comment), 85 COMMENT => Some(FoldKind::Comment),
85 USE_ITEM => Some(FoldKind::Imports), 86 USE_ITEM => Some(FoldKind::Imports),
87 ARG_LIST => Some(FoldKind::ArgList),
86 RECORD_FIELD_DEF_LIST 88 RECORD_FIELD_DEF_LIST
87 | RECORD_FIELD_PAT_LIST 89 | RECORD_FIELD_PAT_LIST
88 | ITEM_LIST 90 | ITEM_LIST
@@ -196,89 +198,85 @@ fn contiguous_range_for_comment(
196 198
197#[cfg(test)] 199#[cfg(test)]
198mod tests { 200mod tests {
201 use test_utils::extract_tags;
202
199 use super::*; 203 use super::*;
200 use test_utils::extract_ranges;
201 204
202 fn do_check(text: &str, fold_kinds: &[FoldKind]) { 205 fn check(ra_fixture: &str) {
203 let (ranges, text) = extract_ranges(text, "fold"); 206 let (ranges, text) = extract_tags(ra_fixture, "fold");
207
204 let parse = SourceFile::parse(&text); 208 let parse = SourceFile::parse(&text);
205 let folds = folding_ranges(&parse.tree()); 209 let folds = folding_ranges(&parse.tree());
206
207 assert_eq!( 210 assert_eq!(
208 folds.len(), 211 folds.len(),
209 ranges.len(), 212 ranges.len(),
210 "The amount of folds is different than the expected amount" 213 "The amount of folds is different than the expected amount"
211 ); 214 );
212 assert_eq!( 215
213 folds.len(), 216 for (fold, (range, attr)) in folds.iter().zip(ranges.into_iter()) {
214 fold_kinds.len(),
215 "The amount of fold kinds is different than the expected amount"
216 );
217 for ((fold, range), fold_kind) in
218 folds.iter().zip(ranges.into_iter()).zip(fold_kinds.iter())
219 {
220 assert_eq!(fold.range.start(), range.start()); 217 assert_eq!(fold.range.start(), range.start());
221 assert_eq!(fold.range.end(), range.end()); 218 assert_eq!(fold.range.end(), range.end());
222 assert_eq!(&fold.kind, fold_kind); 219
220 let kind = match fold.kind {
221 FoldKind::Comment => "comment",
222 FoldKind::Imports => "imports",
223 FoldKind::Mods => "mods",
224 FoldKind::Block => "block",
225 FoldKind::ArgList => "arglist",
226 };
227 assert_eq!(kind, &attr.unwrap());
223 } 228 }
224 } 229 }
225 230
226 #[test] 231 #[test]
227 fn test_fold_comments() { 232 fn test_fold_comments() {
228 let text = r#" 233 check(
229<fold>// Hello 234 r#"
235<fold comment>// Hello
230// this is a multiline 236// this is a multiline
231// comment 237// comment
232//</fold> 238//</fold>
233 239
234// But this is not 240// But this is not
235 241
236fn main() <fold>{ 242fn main() <fold block>{
237 <fold>// We should 243 <fold comment>// We should
238 // also 244 // also
239 // fold 245 // fold
240 // this one.</fold> 246 // this one.</fold>
241 <fold>//! But this one is different 247 <fold comment>//! But this one is different
242 //! because it has another flavor</fold> 248 //! because it has another flavor</fold>
243 <fold>/* As does this 249 <fold comment>/* As does this
244 multiline comment */</fold> 250 multiline comment */</fold>
245}</fold>"#; 251}</fold>"#,
246 252 );
247 let fold_kinds = &[
248 FoldKind::Comment,
249 FoldKind::Block,
250 FoldKind::Comment,
251 FoldKind::Comment,
252 FoldKind::Comment,
253 ];
254 do_check(text, fold_kinds);
255 } 253 }
256 254
257 #[test] 255 #[test]
258 fn test_fold_imports() { 256 fn test_fold_imports() {
259 let text = r#" 257 check(
260<fold>use std::<fold>{ 258 r#"
259<fold imports>use std::<fold block>{
261 str, 260 str,
262 vec, 261 vec,
263 io as iop 262 io as iop
264}</fold>;</fold> 263}</fold>;</fold>
265 264
266fn main() <fold>{ 265fn main() <fold block>{
267}</fold>"#; 266}</fold>"#,
268 267 );
269 let folds = &[FoldKind::Imports, FoldKind::Block, FoldKind::Block];
270 do_check(text, folds);
271 } 268 }
272 269
273 #[test] 270 #[test]
274 fn test_fold_mods() { 271 fn test_fold_mods() {
275 let text = r#" 272 check(
273 r#"
276 274
277pub mod foo; 275pub mod foo;
278<fold>mod after_pub; 276<fold mods>mod after_pub;
279mod after_pub_next;</fold> 277mod after_pub_next;</fold>
280 278
281<fold>mod before_pub; 279<fold mods>mod before_pub;
282mod before_pub_next;</fold> 280mod before_pub_next;</fold>
283pub mod bar; 281pub mod bar;
284 282
@@ -286,90 +284,93 @@ mod not_folding_single;
286pub mod foobar; 284pub mod foobar;
287pub not_folding_single_next; 285pub not_folding_single_next;
288 286
289<fold>#[cfg(test)] 287<fold mods>#[cfg(test)]
290mod with_attribute; 288mod with_attribute;
291mod with_attribute_next;</fold> 289mod with_attribute_next;</fold>
292 290
293fn main() <fold>{ 291fn main() <fold block>{
294}</fold>"#; 292}</fold>"#,
295 293 );
296 let folds = &[FoldKind::Mods, FoldKind::Mods, FoldKind::Mods, FoldKind::Block];
297 do_check(text, folds);
298 } 294 }
299 295
300 #[test] 296 #[test]
301 fn test_fold_import_groups() { 297 fn test_fold_import_groups() {
302 let text = r#" 298 check(
303<fold>use std::str; 299 r#"
300<fold imports>use std::str;
304use std::vec; 301use std::vec;
305use std::io as iop;</fold> 302use std::io as iop;</fold>
306 303
307<fold>use std::mem; 304<fold imports>use std::mem;
308use std::f64;</fold> 305use std::f64;</fold>
309 306
310use std::collections::HashMap; 307use std::collections::HashMap;
311// Some random comment 308// Some random comment
312use std::collections::VecDeque; 309use std::collections::VecDeque;
313 310
314fn main() <fold>{ 311fn main() <fold block>{
315}</fold>"#; 312}</fold>"#,
316 313 );
317 let folds = &[FoldKind::Imports, FoldKind::Imports, FoldKind::Block];
318 do_check(text, folds);
319 } 314 }
320 315
321 #[test] 316 #[test]
322 fn test_fold_import_and_groups() { 317 fn test_fold_import_and_groups() {
323 let text = r#" 318 check(
324<fold>use std::str; 319 r#"
320<fold imports>use std::str;
325use std::vec; 321use std::vec;
326use std::io as iop;</fold> 322use std::io as iop;</fold>
327 323
328<fold>use std::mem; 324<fold imports>use std::mem;
329use std::f64;</fold> 325use std::f64;</fold>
330 326
331<fold>use std::collections::<fold>{ 327<fold imports>use std::collections::<fold block>{
332 HashMap, 328 HashMap,
333 VecDeque, 329 VecDeque,
334}</fold>;</fold> 330}</fold>;</fold>
335// Some random comment 331// Some random comment
336 332
337fn main() <fold>{ 333fn main() <fold block>{
338}</fold>"#; 334}</fold>"#,
339 335 );
340 let folds = &[
341 FoldKind::Imports,
342 FoldKind::Imports,
343 FoldKind::Imports,
344 FoldKind::Block,
345 FoldKind::Block,
346 ];
347 do_check(text, folds);
348 } 336 }
349 337
350 #[test] 338 #[test]
351 fn test_folds_macros() { 339 fn test_folds_macros() {
352 let text = r#" 340 check(
353macro_rules! foo <fold>{ 341 r#"
342macro_rules! foo <fold block>{
354 ($($tt:tt)*) => { $($tt)* } 343 ($($tt:tt)*) => { $($tt)* }
355}</fold> 344}</fold>
356"#; 345"#,
357 346 );
358 let folds = &[FoldKind::Block];
359 do_check(text, folds);
360 } 347 }
361 348
362 #[test] 349 #[test]
363 fn test_fold_match_arms() { 350 fn test_fold_match_arms() {
364 let text = r#" 351 check(
365fn main() <fold>{ 352 r#"
366 match 0 <fold>{ 353fn main() <fold block>{
354 match 0 <fold block>{
367 0 => 0, 355 0 => 0,
368 _ => 1, 356 _ => 1,
369 }</fold> 357 }</fold>
370}</fold>"#; 358}</fold>"#,
359 );
360 }
371 361
372 let folds = &[FoldKind::Block, FoldKind::Block]; 362 #[test]
373 do_check(text, folds); 363 fn fold_big_calls() {
364 check(
365 r#"
366fn main() <fold block>{
367 frobnicate<fold arglist>(
368 1,
369 2,
370 3,
371 )</fold>
372}</fold>
373 "#,
374 )
374 } 375 }
375} 376}
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index bea7fbfa7..4c78fa214 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -103,205 +103,149 @@ pub(crate) fn reference_definition(
103 103
104#[cfg(test)] 104#[cfg(test)]
105mod tests { 105mod tests {
106 use test_utils::assert_eq_text; 106 use ra_db::FileRange;
107 107 use ra_syntax::{TextRange, TextSize};
108 use crate::mock_analysis::analysis_and_position; 108
109 109 use crate::mock_analysis::MockAnalysis;
110 fn check_goto(ra_fixture: &str, expected: &str, expected_range: &str) { 110
111 let (analysis, pos) = analysis_and_position(ra_fixture); 111 fn check(ra_fixture: &str) {
112 let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture);
113 let (mut expected, data) = mock.annotation();
114 let analysis = mock.analysis();
115 match data.as_str() {
116 "" => (),
117 "file" => {
118 expected.range =
119 TextRange::up_to(TextSize::of(&*analysis.file_text(expected.file_id).unwrap()))
120 }
121 data => panic!("bad data: {}", data),
122 }
112 123
113 let mut navs = analysis.goto_definition(pos).unwrap().unwrap().info; 124 let mut navs = analysis.goto_definition(position).unwrap().unwrap().info;
114 if navs.len() == 0 { 125 if navs.len() == 0 {
115 panic!("unresolved reference") 126 panic!("unresolved reference")
116 } 127 }
117 assert_eq!(navs.len(), 1); 128 assert_eq!(navs.len(), 1);
118 129
119 let nav = navs.pop().unwrap(); 130 let nav = navs.pop().unwrap();
120 let file_text = analysis.file_text(nav.file_id()).unwrap(); 131 assert_eq!(expected, FileRange { file_id: nav.file_id(), range: nav.range() });
121
122 let mut actual = file_text[nav.full_range()].to_string();
123 if let Some(focus) = nav.focus_range() {
124 actual += "|";
125 actual += &file_text[focus];
126 }
127
128 if !expected_range.contains("...") {
129 test_utils::assert_eq_text!(&actual, expected_range);
130 } else {
131 let mut parts = expected_range.split("...");
132 let prefix = parts.next().unwrap();
133 let suffix = parts.next().unwrap();
134 assert!(
135 actual.starts_with(prefix) && actual.ends_with(suffix),
136 "\nExpected: {}\n Actual: {}\n",
137 expected_range,
138 actual
139 );
140 }
141
142 nav.assert_match(expected);
143 } 132 }
144 133
145 #[test] 134 #[test]
146 fn goto_def_in_items() { 135 fn goto_def_in_items() {
147 check_goto( 136 check(
148 " 137 r#"
149 //- /lib.rs 138struct Foo;
150 struct Foo; 139 //^^^
151 enum E { X(Foo<|>) } 140enum E { X(Foo<|>) }
152 ", 141"#,
153 "Foo STRUCT_DEF FileId(1) 0..11 7..10",
154 "struct Foo;|Foo",
155 ); 142 );
156 } 143 }
157 144
158 #[test] 145 #[test]
159 fn goto_def_at_start_of_item() { 146 fn goto_def_at_start_of_item() {
160 check_goto( 147 check(
161 " 148 r#"
162 //- /lib.rs 149struct Foo;
163 struct Foo; 150 //^^^
164 enum E { X(<|>Foo) } 151enum E { X(<|>Foo) }
165 ", 152"#,
166 "Foo STRUCT_DEF FileId(1) 0..11 7..10",
167 "struct Foo;|Foo",
168 ); 153 );
169 } 154 }
170 155
171 #[test] 156 #[test]
172 fn goto_definition_resolves_correct_name() { 157 fn goto_definition_resolves_correct_name() {
173 check_goto( 158 check(
174 " 159 r#"
175 //- /lib.rs 160//- /lib.rs
176 use a::Foo; 161use a::Foo;
177 mod a; 162mod a;
178 mod b; 163mod b;
179 enum E { X(Foo<|>) } 164enum E { X(Foo<|>) }
180 165
181 //- /a.rs 166//- /a.rs
182 struct Foo; 167struct Foo;
183 168 //^^^
184 //- /b.rs 169//- /b.rs
185 struct Foo; 170struct Foo;
186 ", 171"#,
187 "Foo STRUCT_DEF FileId(2) 0..11 7..10",
188 "struct Foo;|Foo",
189 ); 172 );
190 } 173 }
191 174
192 #[test] 175 #[test]
193 fn goto_def_for_module_declaration() { 176 fn goto_def_for_module_declaration() {
194 check_goto( 177 check(
195 r#" 178 r#"
196//- /lib.rs 179//- /lib.rs
197mod <|>foo; 180mod <|>foo;
198 181
199//- /foo.rs 182//- /foo.rs
200// empty 183// empty
184//^ file
201"#, 185"#,
202 "foo SOURCE_FILE FileId(2) 0..9",
203 "// empty\n",
204 ); 186 );
205 187
206 check_goto( 188 check(
207 r#" 189 r#"
208//- /lib.rs 190//- /lib.rs
209mod <|>foo; 191mod <|>foo;
210 192
211//- /foo/mod.rs 193//- /foo/mod.rs
212// empty 194// empty
195//^ file
213"#, 196"#,
214 "foo SOURCE_FILE FileId(2) 0..9",
215 "// empty\n",
216 ); 197 );
217 } 198 }
218 199
219 #[test] 200 #[test]
220 fn goto_def_for_macros() { 201 fn goto_def_for_macros() {
221 check_goto( 202 check(
222 " 203 r#"
223 //- /lib.rs 204macro_rules! foo { () => { () } }
224 macro_rules! foo { () => { () } } 205 //^^^
225 206fn bar() {
226 fn bar() { 207 <|>foo!();
227 <|>foo!(); 208}
228 } 209"#,
229 ",
230 "foo MACRO_CALL FileId(1) 0..33 13..16",
231 "macro_rules! foo { () => { () } }|foo",
232 ); 210 );
233 } 211 }
234 212
235 #[test] 213 #[test]
236 fn goto_def_for_macros_from_other_crates() { 214 fn goto_def_for_macros_from_other_crates() {
237 check_goto( 215 check(
238 "
239 //- /lib.rs
240 use foo::foo;
241 fn bar() {
242 <|>foo!();
243 }
244
245 //- /foo/lib.rs
246 #[macro_export]
247 macro_rules! foo { () => { () } }
248 ",
249 "foo MACRO_CALL FileId(2) 0..49 29..32",
250 "#[macro_export]\nmacro_rules! foo { () => { () } }|foo",
251 );
252 }
253
254 #[test]
255 fn goto_def_for_use_alias() {
256 check_goto(
257 r#" 216 r#"
258//- /lib.rs 217//- /lib.rs
259use foo as bar<|>; 218use foo::foo;
219fn bar() {
220 <|>foo!();
221}
260 222
261//- /foo/lib.rs 223//- /foo/lib.rs
262#[macro_export] 224#[macro_export]
263macro_rules! foo { () => { () } } 225macro_rules! foo { () => { () } }
226 //^^^
264"#, 227"#,
265 "SOURCE_FILE FileId(2) 0..50",
266 "#[macro_export]\nmacro_rules! foo { () => { () } }\n",
267 );
268 }
269
270 #[test]
271 fn goto_def_for_use_alias_foo_macro() {
272 check_goto(
273 "
274 //- /lib.rs
275 use foo::foo as bar<|>;
276
277 //- /foo/lib.rs
278 #[macro_export]
279 macro_rules! foo { () => { () } }
280 ",
281 "foo MACRO_CALL FileId(2) 0..49 29..32",
282 "#[macro_export]\nmacro_rules! foo { () => { () } }|foo",
283 ); 228 );
284 } 229 }
285 230
286 #[test] 231 #[test]
287 fn goto_def_for_macros_in_use_tree() { 232 fn goto_def_for_macros_in_use_tree() {
288 check_goto( 233 check(
289 " 234 r#"
290 //- /lib.rs 235//- /lib.rs
291 use foo::foo<|>; 236use foo::foo<|>;
292 237
293 //- /foo/lib.rs 238//- /foo/lib.rs
294 #[macro_export] 239#[macro_export]
295 macro_rules! foo { () => { () } } 240macro_rules! foo { () => { () } }
296 ", 241 //^^^
297 "foo MACRO_CALL FileId(2) 0..49 29..32", 242"#,
298 "#[macro_export]\nmacro_rules! foo { () => { () } }|foo",
299 ); 243 );
300 } 244 }
301 245
302 #[test] 246 #[test]
303 fn goto_def_for_macro_defined_fn_with_arg() { 247 fn goto_def_for_macro_defined_fn_with_arg() {
304 check_goto( 248 check(
305 r#" 249 r#"
306//- /lib.rs 250//- /lib.rs
307macro_rules! define_fn { 251macro_rules! define_fn {
@@ -309,522 +253,478 @@ macro_rules! define_fn {
309} 253}
310 254
311define_fn!(foo); 255define_fn!(foo);
256 //^^^
312 257
313fn bar() { 258fn bar() {
314 <|>foo(); 259 <|>foo();
315} 260}
316"#, 261"#,
317 "foo FN_DEF FileId(1) 65..81 76..79",
318 "define_fn!(foo);|foo",
319 ); 262 );
320 } 263 }
321 264
322 #[test] 265 #[test]
323 fn goto_def_for_macro_defined_fn_no_arg() { 266 fn goto_def_for_macro_defined_fn_no_arg() {
324 check_goto( 267 check(
325 r#" 268 r#"
326//- /lib.rs 269//- /lib.rs
327macro_rules! define_fn { 270macro_rules! define_fn {
328 () => (fn foo() {}) 271 () => (fn foo() {})
329} 272}
330 273
331define_fn!(); 274 define_fn!();
275//^^^^^^^^^^^^^
332 276
333fn bar() { 277fn bar() {
334 <|>foo(); 278 <|>foo();
335} 279}
336"#, 280"#,
337 "foo FN_DEF FileId(1) 52..65 52..65",
338 "define_fn!();|define_fn!();",
339 ); 281 );
340 } 282 }
341 283
342 #[test] 284 #[test]
343 fn goto_definition_works_for_macro_inside_pattern() { 285 fn goto_definition_works_for_macro_inside_pattern() {
344 check_goto( 286 check(
345 " 287 r#"
346 //- /lib.rs 288//- /lib.rs
347 macro_rules! foo {() => {0}} 289macro_rules! foo {() => {0}}
348 290 //^^^
349 fn bar() { 291
350 match (0,1) { 292fn bar() {
351 (<|>foo!(), _) => {} 293 match (0,1) {
352 } 294 (<|>foo!(), _) => {}
353 } 295 }
354 ", 296}
355 "foo MACRO_CALL FileId(1) 0..28 13..16", 297"#,
356 "macro_rules! foo {() => {0}}|foo",
357 ); 298 );
358 } 299 }
359 300
360 #[test] 301 #[test]
361 fn goto_definition_works_for_macro_inside_match_arm_lhs() { 302 fn goto_definition_works_for_macro_inside_match_arm_lhs() {
362 check_goto( 303 check(
363 " 304 r#"
364 //- /lib.rs 305//- /lib.rs
365 macro_rules! foo {() => {0}} 306macro_rules! foo {() => {0}}
366 307 //^^^
367 fn bar() { 308fn bar() {
368 match 0 { 309 match 0 {
369 <|>foo!() => {} 310 <|>foo!() => {}
370 } 311 }
371 } 312}
372 ", 313"#,
373 "foo MACRO_CALL FileId(1) 0..28 13..16", 314 );
374 "macro_rules! foo {() => {0}}|foo", 315 }
316
317 #[test]
318 fn goto_def_for_use_alias() {
319 check(
320 r#"
321//- /lib.rs
322use foo as bar<|>;
323
324//- /foo/lib.rs
325// empty
326//^ file
327"#,
328 );
329 }
330
331 #[test]
332 fn goto_def_for_use_alias_foo_macro() {
333 check(
334 r#"
335//- /lib.rs
336use foo::foo as bar<|>;
337
338//- /foo/lib.rs
339#[macro_export]
340macro_rules! foo { () => { () } }
341 //^^^
342"#,
375 ); 343 );
376 } 344 }
377 345
378 #[test] 346 #[test]
379 fn goto_def_for_methods() { 347 fn goto_def_for_methods() {
380 check_goto( 348 check(
381 " 349 r#"
382 //- /lib.rs 350//- /lib.rs
383 struct Foo; 351struct Foo;
384 impl Foo { 352impl Foo {
385 fn frobnicate(&self) { } 353 fn frobnicate(&self) { }
386 } 354 //^^^^^^^^^^
355}
387 356
388 fn bar(foo: &Foo) { 357fn bar(foo: &Foo) {
389 foo.frobnicate<|>(); 358 foo.frobnicate<|>();
390 } 359}
391 ", 360"#,
392 "frobnicate FN_DEF FileId(1) 27..51 30..40",
393 "fn frobnicate(&self) { }|frobnicate",
394 ); 361 );
395 } 362 }
396 363
397 #[test] 364 #[test]
398 fn goto_def_for_fields() { 365 fn goto_def_for_fields() {
399 check_goto( 366 check(
400 r" 367 r#"
401 //- /lib.rs 368struct Foo {
402 struct Foo { 369 spam: u32,
403 spam: u32, 370} //^^^^
404 }
405 371
406 fn bar(foo: &Foo) { 372fn bar(foo: &Foo) {
407 foo.spam<|>; 373 foo.spam<|>;
408 } 374}
409 ", 375"#,
410 "spam RECORD_FIELD_DEF FileId(1) 17..26 17..21",
411 "spam: u32|spam",
412 ); 376 );
413 } 377 }
414 378
415 #[test] 379 #[test]
416 fn goto_def_for_record_fields() { 380 fn goto_def_for_record_fields() {
417 check_goto( 381 check(
418 r" 382 r#"
419 //- /lib.rs 383//- /lib.rs
420 struct Foo { 384struct Foo {
421 spam: u32, 385 spam: u32,
422 } 386} //^^^^
423 387
424 fn bar() -> Foo { 388fn bar() -> Foo {
425 Foo { 389 Foo {
426 spam<|>: 0, 390 spam<|>: 0,
427 } 391 }
428 } 392}
429 ", 393"#,
430 "spam RECORD_FIELD_DEF FileId(1) 17..26 17..21",
431 "spam: u32|spam",
432 ); 394 );
433 } 395 }
434 396
435 #[test] 397 #[test]
436 fn goto_def_for_record_pat_fields() { 398 fn goto_def_for_record_pat_fields() {
437 check_goto( 399 check(
438 r" 400 r#"
439 //- /lib.rs 401//- /lib.rs
440 struct Foo { 402struct Foo {
441 spam: u32, 403 spam: u32,
442 } 404} //^^^^
443 405
444 fn bar(foo: Foo) -> Foo { 406fn bar(foo: Foo) -> Foo {
445 let Foo { spam<|>: _, } = foo 407 let Foo { spam<|>: _, } = foo
446 } 408}
447 ", 409"#,
448 "spam RECORD_FIELD_DEF FileId(1) 17..26 17..21",
449 "spam: u32|spam",
450 ); 410 );
451 } 411 }
452 412
453 #[test] 413 #[test]
454 fn goto_def_for_record_fields_macros() { 414 fn goto_def_for_record_fields_macros() {
455 check_goto( 415 check(
456 r" 416 r"
457 //- /lib.rs 417macro_rules! m { () => { 92 };}
458 macro_rules! m { () => { 92 };} 418struct Foo { spam: u32 }
459 struct Foo { spam: u32 } 419 //^^^^
460 420
461 fn bar() -> Foo { 421fn bar() -> Foo {
462 Foo { spam<|>: m!() } 422 Foo { spam<|>: m!() }
463 } 423}
464 ", 424",
465 "spam RECORD_FIELD_DEF FileId(1) 45..54 45..49",
466 "spam: u32|spam",
467 ); 425 );
468 } 426 }
469 427
470 #[test] 428 #[test]
471 fn goto_for_tuple_fields() { 429 fn goto_for_tuple_fields() {
472 check_goto( 430 check(
473 " 431 r#"
474 //- /lib.rs 432struct Foo(u32);
475 struct Foo(u32); 433 //^^^
476 434
477 fn bar() { 435fn bar() {
478 let foo = Foo(0); 436 let foo = Foo(0);
479 foo.<|>0; 437 foo.<|>0;
480 } 438}
481 ", 439"#,
482 "TUPLE_FIELD_DEF FileId(1) 11..14",
483 "u32",
484 ); 440 );
485 } 441 }
486 442
487 #[test] 443 #[test]
488 fn goto_def_for_ufcs_inherent_methods() { 444 fn goto_def_for_ufcs_inherent_methods() {
489 check_goto( 445 check(
490 " 446 r#"
491 //- /lib.rs 447struct Foo;
492 struct Foo; 448impl Foo {
493 impl Foo { 449 fn frobnicate() { }
494 fn frobnicate() { } 450} //^^^^^^^^^^
495 }
496 451
497 fn bar(foo: &Foo) { 452fn bar(foo: &Foo) {
498 Foo::frobnicate<|>(); 453 Foo::frobnicate<|>();
499 } 454}
500 ", 455"#,
501 "frobnicate FN_DEF FileId(1) 27..46 30..40",
502 "fn frobnicate() { }|frobnicate",
503 ); 456 );
504 } 457 }
505 458
506 #[test] 459 #[test]
507 fn goto_def_for_ufcs_trait_methods_through_traits() { 460 fn goto_def_for_ufcs_trait_methods_through_traits() {
508 check_goto( 461 check(
509 " 462 r#"
510 //- /lib.rs 463trait Foo {
511 trait Foo { 464 fn frobnicate();
512 fn frobnicate(); 465} //^^^^^^^^^^
513 }
514 466
515 fn bar() { 467fn bar() {
516 Foo::frobnicate<|>(); 468 Foo::frobnicate<|>();
517 } 469}
518 ", 470"#,
519 "frobnicate FN_DEF FileId(1) 16..32 19..29",
520 "fn frobnicate();|frobnicate",
521 ); 471 );
522 } 472 }
523 473
524 #[test] 474 #[test]
525 fn goto_def_for_ufcs_trait_methods_through_self() { 475 fn goto_def_for_ufcs_trait_methods_through_self() {
526 check_goto( 476 check(
527 " 477 r#"
528 //- /lib.rs 478struct Foo;
529 struct Foo; 479trait Trait {
530 trait Trait { 480 fn frobnicate();
531 fn frobnicate(); 481} //^^^^^^^^^^
532 } 482impl Trait for Foo {}
533 impl Trait for Foo {}
534 483
535 fn bar() { 484fn bar() {
536 Foo::frobnicate<|>(); 485 Foo::frobnicate<|>();
537 } 486}
538 ", 487"#,
539 "frobnicate FN_DEF FileId(1) 30..46 33..43",
540 "fn frobnicate();|frobnicate",
541 ); 488 );
542 } 489 }
543 490
544 #[test] 491 #[test]
545 fn goto_definition_on_self() { 492 fn goto_definition_on_self() {
546 check_goto( 493 check(
547 " 494 r#"
548 //- /lib.rs 495struct Foo;
549 struct Foo; 496impl Foo {
550 impl Foo { 497 //^^^
551 pub fn new() -> Self { 498 pub fn new() -> Self {
552 Self<|> {} 499 Self<|> {}
553 } 500 }
554 } 501}
555 ", 502"#,
556 "impl IMPL_DEF FileId(1) 12..73", 503 );
557 "impl Foo {...}", 504 check(
558 ); 505 r#"
559 506struct Foo;
560 check_goto( 507impl Foo {
561 " 508 //^^^
562 //- /lib.rs 509 pub fn new() -> Self<|> {
563 struct Foo; 510 Self {}
564 impl Foo { 511 }
565 pub fn new() -> Self<|> { 512}
566 Self {} 513"#,
567 } 514 );
568 } 515
569 ", 516 check(
570 "impl IMPL_DEF FileId(1) 12..73", 517 r#"
571 "impl Foo {...}", 518enum Foo { A }
572 ); 519impl Foo {
573 520 //^^^
574 check_goto( 521 pub fn new() -> Self<|> {
575 " 522 Foo::A
576 //- /lib.rs 523 }
577 enum Foo { A } 524}
578 impl Foo { 525"#,
579 pub fn new() -> Self<|> { 526 );
580 Foo::A 527
581 } 528 check(
582 } 529 r#"
583 ", 530enum Foo { A }
584 "impl IMPL_DEF FileId(1) 15..75", 531impl Foo {
585 "impl Foo {...}", 532 //^^^
586 ); 533 pub fn thing(a: &Self<|>) {
587 534 }
588 check_goto( 535}
589 " 536"#,
590 //- /lib.rs
591 enum Foo { A }
592 impl Foo {
593 pub fn thing(a: &Self<|>) {
594 }
595 }
596 ",
597 "impl IMPL_DEF FileId(1) 15..62",
598 "impl Foo {...}",
599 ); 537 );
600 } 538 }
601 539
602 #[test] 540 #[test]
603 fn goto_definition_on_self_in_trait_impl() { 541 fn goto_definition_on_self_in_trait_impl() {
604 check_goto( 542 check(
605 " 543 r#"
606 //- /lib.rs 544struct Foo;
607 struct Foo; 545trait Make {
608 trait Make { 546 fn new() -> Self;
609 fn new() -> Self; 547}
610 } 548impl Make for Foo {
611 impl Make for Foo { 549 //^^^
612 fn new() -> Self { 550 fn new() -> Self {
613 Self<|> {} 551 Self<|> {}
614 } 552 }
615 } 553}
616 ", 554"#,
617 "impl IMPL_DEF FileId(1) 49..115",
618 "impl Make for Foo {...}",
619 ); 555 );
620 556
621 check_goto( 557 check(
622 " 558 r#"
623 //- /lib.rs 559struct Foo;
624 struct Foo; 560trait Make {
625 trait Make { 561 fn new() -> Self;
626 fn new() -> Self; 562}
627 } 563impl Make for Foo {
628 impl Make for Foo { 564 //^^^
629 fn new() -> Self<|> { 565 fn new() -> Self<|> {
630 Self {} 566 Self {}
631 } 567 }
632 } 568}
633 ", 569"#,
634 "impl IMPL_DEF FileId(1) 49..115",
635 "impl Make for Foo {...}",
636 ); 570 );
637 } 571 }
638 572
639 #[test] 573 #[test]
640 fn goto_def_when_used_on_definition_name_itself() { 574 fn goto_def_when_used_on_definition_name_itself() {
641 check_goto( 575 check(
642 " 576 r#"
643 //- /lib.rs 577struct Foo<|> { value: u32 }
644 struct Foo<|> { value: u32 } 578 //^^^
645 ", 579 "#,
646 "Foo STRUCT_DEF FileId(1) 0..25 7..10",
647 "struct Foo { value: u32 }|Foo",
648 ); 580 );
649 581
650 check_goto( 582 check(
651 r#" 583 r#"
652 //- /lib.rs 584struct Foo {
653 struct Foo { 585 field<|>: string,
654 field<|>: string, 586} //^^^^^
655 } 587"#,
656 "#,
657 "field RECORD_FIELD_DEF FileId(1) 17..30 17..22",
658 "field: string|field",
659 ); 588 );
660 589
661 check_goto( 590 check(
662 " 591 r#"
663 //- /lib.rs 592fn foo_test<|>() { }
664 fn foo_test<|>() { } 593 //^^^^^^^^
665 ", 594"#,
666 "foo_test FN_DEF FileId(1) 0..17 3..11",
667 "fn foo_test() { }|foo_test",
668 ); 595 );
669 596
670 check_goto( 597 check(
671 " 598 r#"
672 //- /lib.rs 599enum Foo<|> { Variant }
673 enum Foo<|> { 600 //^^^
674 Variant, 601"#,
675 }
676 ",
677 "Foo ENUM_DEF FileId(1) 0..25 5..8",
678 "enum Foo {...}|Foo",
679 );
680
681 check_goto(
682 "
683 //- /lib.rs
684 enum Foo {
685 Variant1,
686 Variant2<|>,
687 Variant3,
688 }
689 ",
690 "Variant2 ENUM_VARIANT FileId(1) 29..37 29..37",
691 "Variant2|Variant2",
692 ); 602 );
693 603
694 check_goto( 604 check(
695 r#" 605 r#"
696 //- /lib.rs 606enum Foo {
697 static INNER<|>: &str = ""; 607 Variant1,
698 "#, 608 Variant2<|>,
699 "INNER STATIC_DEF FileId(1) 0..24 7..12", 609 //^^^^^^^^
700 "static INNER: &str = \"\";|INNER", 610 Variant3,
611}
612"#,
701 ); 613 );
702 614
703 check_goto( 615 check(
704 r#" 616 r#"
705 //- /lib.rs 617static INNER<|>: &str = "";
706 const INNER<|>: &str = ""; 618 //^^^^^
707 "#, 619"#,
708 "INNER CONST_DEF FileId(1) 0..23 6..11",
709 "const INNER: &str = \"\";|INNER",
710 ); 620 );
711 621
712 check_goto( 622 check(
713 r#" 623 r#"
714 //- /lib.rs 624const INNER<|>: &str = "";
715 type Thing<|> = Option<()>; 625 //^^^^^
716 "#, 626"#,
717 "Thing TYPE_ALIAS_DEF FileId(1) 0..24 5..10",
718 "type Thing = Option<()>;|Thing",
719 ); 627 );
720 628
721 check_goto( 629 check(
722 r#" 630 r#"
723 //- /lib.rs 631type Thing<|> = Option<()>;
724 trait Foo<|> { } 632 //^^^^^
725 "#, 633"#,
726 "Foo TRAIT_DEF FileId(1) 0..13 6..9",
727 "trait Foo { }|Foo",
728 ); 634 );
729 635
730 check_goto( 636 check(
731 r#" 637 r#"
732 //- /lib.rs 638trait Foo<|> { }
733 mod bar<|> { } 639 //^^^
734 "#, 640"#,
735 "bar MODULE FileId(1) 0..11 4..7", 641 );
736 "mod bar { }|bar", 642
643 check(
644 r#"
645mod bar<|> { }
646 //^^^
647"#,
737 ); 648 );
738 } 649 }
739 650
740 #[test] 651 #[test]
741 fn goto_from_macro() { 652 fn goto_from_macro() {
742 check_goto( 653 check(
743 " 654 r#"
744 //- /lib.rs 655macro_rules! id {
745 macro_rules! id { 656 ($($tt:tt)*) => { $($tt)* }
746 ($($tt:tt)*) => { $($tt)* } 657}
747 } 658fn foo() {}
748 fn foo() {} 659 //^^^
749 id! { 660id! {
750 fn bar() { 661 fn bar() {
751 fo<|>o(); 662 fo<|>o();
752 } 663 }
753 } 664}
754 mod confuse_index { fn foo(); } 665mod confuse_index { fn foo(); }
755 ", 666"#,
756 "foo FN_DEF FileId(1) 52..63 55..58",
757 "fn foo() {}|foo",
758 ); 667 );
759 } 668 }
760 669
761 #[test] 670 #[test]
762 fn goto_through_format() { 671 fn goto_through_format() {
763 check_goto( 672 check(
764 " 673 r#"
765 //- /lib.rs 674#[macro_export]
766 #[macro_export] 675macro_rules! format {
767 macro_rules! format { 676 ($($arg:tt)*) => ($crate::fmt::format($crate::__export::format_args!($($arg)*)))
768 ($($arg:tt)*) => ($crate::fmt::format($crate::__export::format_args!($($arg)*))) 677}
769 } 678#[rustc_builtin_macro]
770 #[rustc_builtin_macro] 679#[macro_export]
771 #[macro_export] 680macro_rules! format_args {
772 macro_rules! format_args { 681 ($fmt:expr) => ({ /* compiler built-in */ });
773 ($fmt:expr) => ({ /* compiler built-in */ }); 682 ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ })
774 ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ }) 683}
775 } 684pub mod __export {
776 pub mod __export { 685 pub use crate::format_args;
777 pub use crate::format_args; 686 fn foo() {} // for index confusion
778 fn foo() {} // for index confusion 687}
779 } 688fn foo() -> i8 {}
780 fn foo() -> i8 {} 689 //^^^
781 fn test() { 690fn test() {
782 format!(\"{}\", fo<|>o()) 691 format!("{}", fo<|>o())
783 } 692}
784 ", 693"#,
785 "foo FN_DEF FileId(1) 398..415 401..404",
786 "fn foo() -> i8 {}|foo",
787 ); 694 );
788 } 695 }
789 696
790 #[test] 697 #[test]
791 fn goto_for_type_param() { 698 fn goto_for_type_param() {
792 check_goto( 699 check(
793 r#" 700 r#"
794 //- /lib.rs 701struct Foo<T: Clone> { t: <|>T }
795 struct Foo<T: Clone> { 702 //^
796 t: <|>T, 703"#,
797 }
798 "#,
799 "T TYPE_PARAM FileId(1) 11..19 11..12",
800 "T: Clone|T",
801 ); 704 );
802 } 705 }
803 706
804 #[test] 707 #[test]
805 fn goto_within_macro() { 708 fn goto_within_macro() {
806 check_goto( 709 check(
807 r#" 710 r#"
808//- /lib.rs
809macro_rules! id { 711macro_rules! id {
810 ($($tt:tt)*) => ($($tt)*) 712 ($($tt:tt)*) => ($($tt)*)
811} 713}
812 714
813fn foo() { 715fn foo() {
814 let x = 1; 716 let x = 1;
717 //^
815 id!({ 718 id!({
816 let y = <|>x; 719 let y = <|>x;
817 let z = y; 720 let z = y;
818 }); 721 });
819} 722}
820"#, 723"#,
821 "x BIND_PAT FileId(1) 70..71",
822 "x",
823 ); 724 );
824 725
825 check_goto( 726 check(
826 r#" 727 r#"
827//- /lib.rs
828macro_rules! id { 728macro_rules! id {
829 ($($tt:tt)*) => ($($tt)*) 729 ($($tt:tt)*) => ($($tt)*)
830} 730}
@@ -833,159 +733,125 @@ fn foo() {
833 let x = 1; 733 let x = 1;
834 id!({ 734 id!({
835 let y = x; 735 let y = x;
736 //^
836 let z = <|>y; 737 let z = <|>y;
837 }); 738 });
838} 739}
839"#, 740"#,
840 "y BIND_PAT FileId(1) 99..100",
841 "y",
842 ); 741 );
843 } 742 }
844 743
845 #[test] 744 #[test]
846 fn goto_def_in_local_fn() { 745 fn goto_def_in_local_fn() {
847 check_goto( 746 check(
848 " 747 r#"
849 //- /lib.rs 748fn main() {
850 fn main() { 749 fn foo() {
851 fn foo() { 750 let x = 92;
852 let x = 92; 751 //^
853 <|>x; 752 <|>x;
854 } 753 }
855 } 754}
856 ", 755"#,
857 "x BIND_PAT FileId(1) 39..40",
858 "x",
859 ); 756 );
860 } 757 }
861 758
862 #[test] 759 #[test]
863 fn goto_def_in_local_macro() { 760 fn goto_def_in_local_macro() {
864 check_goto( 761 check(
865 r" 762 r#"
866 //- /lib.rs 763fn bar() {
867 fn bar() { 764 macro_rules! foo { () => { () } }
868 macro_rules! foo { () => { () } } 765 //^^^
869 <|>foo!(); 766 <|>foo!();
870 } 767}
871 ", 768"#,
872 "foo MACRO_CALL FileId(1) 15..48 28..31",
873 "macro_rules! foo { () => { () } }|foo",
874 ); 769 );
875 } 770 }
876 771
877 #[test] 772 #[test]
878 fn goto_def_for_field_init_shorthand() { 773 fn goto_def_for_field_init_shorthand() {
879 check_goto( 774 check(
880 " 775 r#"
881 //- /lib.rs 776struct Foo { x: i32 }
882 struct Foo { x: i32 } 777fn main() {
883 fn main() { 778 let x = 92;
884 let x = 92; 779 //^
885 Foo { x<|> }; 780 Foo { x<|> };
886 } 781}
887 ", 782"#,
888 "x BIND_PAT FileId(1) 42..43",
889 "x",
890 ) 783 )
891 } 784 }
892 785
893 #[test] 786 #[test]
894 fn goto_def_for_enum_variant_field() { 787 fn goto_def_for_enum_variant_field() {
895 check_goto( 788 check(
896 " 789 r#"
897 //- /lib.rs 790enum Foo {
898 enum Foo { 791 Bar { x: i32 }
899 Bar { x: i32 } 792} //^
900 } 793fn baz(foo: Foo) {
901 fn baz(foo: Foo) { 794 match foo {
902 match foo { 795 Foo::Bar { x<|> } => x
903 Foo::Bar { x<|> } => x 796 };
904 }; 797}
905 } 798"#,
906 ",
907 "x RECORD_FIELD_DEF FileId(1) 21..27 21..22",
908 "x: i32|x",
909 ); 799 );
910 } 800 }
911 801
912 #[test] 802 #[test]
913 fn goto_def_for_enum_variant_self_pattern_const() { 803 fn goto_def_for_enum_variant_self_pattern_const() {
914 check_goto( 804 check(
915 " 805 r#"
916 //- /lib.rs 806enum Foo { Bar }
917 enum Foo { 807 //^^^
918 Bar, 808impl Foo {
919 } 809 fn baz(self) {
920 impl Foo { 810 match self { Self::Bar<|> => {} }
921 fn baz(self) { 811 }
922 match self { 812}
923 Self::Bar<|> => {} 813"#,
924 }
925 }
926 }
927 ",
928 "Bar ENUM_VARIANT FileId(1) 15..18 15..18",
929 "Bar|Bar",
930 ); 814 );
931 } 815 }
932 816
933 #[test] 817 #[test]
934 fn goto_def_for_enum_variant_self_pattern_record() { 818 fn goto_def_for_enum_variant_self_pattern_record() {
935 check_goto( 819 check(
936 " 820 r#"
937 //- /lib.rs 821enum Foo { Bar { val: i32 } }
938 enum Foo { 822 //^^^
939 Bar { val: i32 }, 823impl Foo {
940 } 824 fn baz(self) -> i32 {
941 impl Foo { 825 match self { Self::Bar<|> { val } => {} }
942 fn baz(self) -> i32 { 826 }
943 match self { 827}
944 Self::Bar<|> { val } => {} 828"#,
945 }
946 }
947 }
948 ",
949 "Bar ENUM_VARIANT FileId(1) 15..31 15..18",
950 "Bar { val: i32 }|Bar",
951 ); 829 );
952 } 830 }
953 831
954 #[test] 832 #[test]
955 fn goto_def_for_enum_variant_self_expr_const() { 833 fn goto_def_for_enum_variant_self_expr_const() {
956 check_goto( 834 check(
957 " 835 r#"
958 //- /lib.rs 836enum Foo { Bar }
959 enum Foo { 837 //^^^
960 Bar, 838impl Foo {
961 } 839 fn baz(self) { Self::Bar<|>; }
962 impl Foo { 840}
963 fn baz(self) { 841"#,
964 Self::Bar<|>;
965 }
966 }
967 ",
968 "Bar ENUM_VARIANT FileId(1) 15..18 15..18",
969 "Bar|Bar",
970 ); 842 );
971 } 843 }
972 844
973 #[test] 845 #[test]
974 fn goto_def_for_enum_variant_self_expr_record() { 846 fn goto_def_for_enum_variant_self_expr_record() {
975 check_goto( 847 check(
976 " 848 r#"
977 //- /lib.rs 849enum Foo { Bar { val: i32 } }
978 enum Foo { 850 //^^^
979 Bar { val: i32 }, 851impl Foo {
980 } 852 fn baz(self) { Self::Bar<|> {val: 4}; }
981 impl Foo { 853}
982 fn baz(self) { 854"#,
983 Self::Bar<|> {val: 4};
984 }
985 }
986 ",
987 "Bar ENUM_VARIANT FileId(1) 15..31 15..18",
988 "Bar { val: i32 }|Bar",
989 ); 855 );
990 } 856 }
991} 857}
diff --git a/crates/ra_ide/src/goto_implementation.rs b/crates/ra_ide/src/goto_implementation.rs
index 0cec0657e..9acc960fc 100644
--- a/crates/ra_ide/src/goto_implementation.rs
+++ b/crates/ra_ide/src/goto_implementation.rs
@@ -74,135 +74,156 @@ fn impls_for_trait(
74 74
75#[cfg(test)] 75#[cfg(test)]
76mod tests { 76mod tests {
77 use crate::mock_analysis::analysis_and_position; 77 use ra_db::FileRange;
78 78
79 fn check_goto(fixture: &str, expected: &[&str]) { 79 use crate::mock_analysis::MockAnalysis;
80 let (analysis, pos) = analysis_and_position(fixture);
81 80
82 let mut navs = analysis.goto_implementation(pos).unwrap().unwrap().info; 81 fn check(ra_fixture: &str) {
83 assert_eq!(navs.len(), expected.len()); 82 let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture);
84 navs.sort_by_key(|nav| (nav.file_id(), nav.full_range().start())); 83 let annotations = mock.annotations();
85 navs.into_iter().enumerate().for_each(|(i, nav)| nav.assert_match(expected[i])); 84 let analysis = mock.analysis();
85
86 let navs = analysis.goto_implementation(position).unwrap().unwrap().info;
87
88 let key = |frange: &FileRange| (frange.file_id, frange.range.start());
89
90 let mut expected = annotations
91 .into_iter()
92 .map(|(range, data)| {
93 assert!(data.is_empty());
94 range
95 })
96 .collect::<Vec<_>>();
97 expected.sort_by_key(key);
98
99 let mut actual = navs
100 .into_iter()
101 .map(|nav| FileRange { file_id: nav.file_id(), range: nav.range() })
102 .collect::<Vec<_>>();
103 actual.sort_by_key(key);
104
105 assert_eq!(expected, actual);
86 } 106 }
87 107
88 #[test] 108 #[test]
89 fn goto_implementation_works() { 109 fn goto_implementation_works() {
90 check_goto( 110 check(
91 " 111 r#"
92 //- /lib.rs 112struct Foo<|>;
93 struct Foo<|>; 113impl Foo {}
94 impl Foo {} 114 //^^^
95 ", 115"#,
96 &["impl IMPL_DEF FileId(1) 12..23"],
97 ); 116 );
98 } 117 }
99 118
100 #[test] 119 #[test]
101 fn goto_implementation_works_multiple_blocks() { 120 fn goto_implementation_works_multiple_blocks() {
102 check_goto( 121 check(
103 " 122 r#"
104 //- /lib.rs 123struct Foo<|>;
105 struct Foo<|>; 124impl Foo {}
106 impl Foo {} 125 //^^^
107 impl Foo {} 126impl Foo {}
108 ", 127 //^^^
109 &["impl IMPL_DEF FileId(1) 12..23", "impl IMPL_DEF FileId(1) 24..35"], 128"#,
110 ); 129 );
111 } 130 }
112 131
113 #[test] 132 #[test]
114 fn goto_implementation_works_multiple_mods() { 133 fn goto_implementation_works_multiple_mods() {
115 check_goto( 134 check(
116 " 135 r#"
117 //- /lib.rs 136struct Foo<|>;
118 struct Foo<|>; 137mod a {
119 mod a { 138 impl super::Foo {}
120 impl super::Foo {} 139 //^^^^^^^^^^
121 } 140}
122 mod b { 141mod b {
123 impl super::Foo {} 142 impl super::Foo {}
124 } 143 //^^^^^^^^^^
125 ", 144}
126 &["impl IMPL_DEF FileId(1) 24..42", "impl IMPL_DEF FileId(1) 57..75"], 145"#,
127 ); 146 );
128 } 147 }
129 148
130 #[test] 149 #[test]
131 fn goto_implementation_works_multiple_files() { 150 fn goto_implementation_works_multiple_files() {
132 check_goto( 151 check(
133 " 152 r#"
134 //- /lib.rs 153//- /lib.rs
135 struct Foo<|>; 154struct Foo<|>;
136 mod a; 155mod a;
137 mod b; 156mod b;
138 //- /a.rs 157//- /a.rs
139 impl crate::Foo {} 158impl crate::Foo {}
140 //- /b.rs 159 //^^^^^^^^^^
141 impl crate::Foo {} 160//- /b.rs
142 ", 161impl crate::Foo {}
143 &["impl IMPL_DEF FileId(2) 0..18", "impl IMPL_DEF FileId(3) 0..18"], 162 //^^^^^^^^^^
163"#,
144 ); 164 );
145 } 165 }
146 166
147 #[test] 167 #[test]
148 fn goto_implementation_for_trait() { 168 fn goto_implementation_for_trait() {
149 check_goto( 169 check(
150 " 170 r#"
151 //- /lib.rs 171trait T<|> {}
152 trait T<|> {} 172struct Foo;
153 struct Foo; 173impl T for Foo {}
154 impl T for Foo {} 174 //^^^
155 ", 175"#,
156 &["impl IMPL_DEF FileId(1) 23..40"],
157 ); 176 );
158 } 177 }
159 178
160 #[test] 179 #[test]
161 fn goto_implementation_for_trait_multiple_files() { 180 fn goto_implementation_for_trait_multiple_files() {
162 check_goto( 181 check(
163 " 182 r#"
164 //- /lib.rs 183//- /lib.rs
165 trait T<|> {}; 184trait T<|> {};
166 struct Foo; 185struct Foo;
167 mod a; 186mod a;
168 mod b; 187mod b;
169 //- /a.rs 188//- /a.rs
170 impl crate::T for crate::Foo {} 189impl crate::T for crate::Foo {}
171 //- /b.rs 190 //^^^^^^^^^^
172 impl crate::T for crate::Foo {} 191//- /b.rs
173 ", 192impl crate::T for crate::Foo {}
174 &["impl IMPL_DEF FileId(2) 0..31", "impl IMPL_DEF FileId(3) 0..31"], 193 //^^^^^^^^^^
194 "#,
175 ); 195 );
176 } 196 }
177 197
178 #[test] 198 #[test]
179 fn goto_implementation_all_impls() { 199 fn goto_implementation_all_impls() {
180 check_goto( 200 check(
181 " 201 r#"
182 //- /lib.rs 202//- /lib.rs
183 trait T {} 203trait T {}
184 struct Foo<|>; 204struct Foo<|>;
185 impl Foo {} 205impl Foo {}
186 impl T for Foo {} 206 //^^^
187 impl T for &Foo {} 207impl T for Foo {}
188 ", 208 //^^^
189 &[ 209impl T for &Foo {}
190 "impl IMPL_DEF FileId(1) 23..34", 210 //^^^^
191 "impl IMPL_DEF FileId(1) 35..52", 211"#,
192 "impl IMPL_DEF FileId(1) 53..71",
193 ],
194 ); 212 );
195 } 213 }
196 214
197 #[test] 215 #[test]
198 fn goto_implementation_to_builtin_derive() { 216 fn goto_implementation_to_builtin_derive() {
199 check_goto( 217 check(
200 " 218 r#"
201 //- /lib.rs 219 #[derive(Copy)]
202 #[derive(Copy)] 220//^^^^^^^^^^^^^^^
203 struct Foo<|>; 221struct Foo<|>;
204 ", 222
205 &["impl IMPL_DEF FileId(1) 0..15"], 223mod marker {
224 trait Copy {}
225}
226"#,
206 ); 227 );
207 } 228 }
208} 229}
diff --git a/crates/ra_ide/src/goto_type_definition.rs b/crates/ra_ide/src/goto_type_definition.rs
index 91a3097fb..7eb40d637 100644
--- a/crates/ra_ide/src/goto_type_definition.rs
+++ b/crates/ra_ide/src/goto_type_definition.rs
@@ -55,8 +55,8 @@ fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
55mod tests { 55mod tests {
56 use crate::mock_analysis::analysis_and_position; 56 use crate::mock_analysis::analysis_and_position;
57 57
58 fn check_goto(fixture: &str, expected: &str) { 58 fn check_goto(ra_fixture: &str, expected: &str) {
59 let (analysis, pos) = analysis_and_position(fixture); 59 let (analysis, pos) = analysis_and_position(ra_fixture);
60 60
61 let mut navs = analysis.goto_type_definition(pos).unwrap().unwrap().info; 61 let mut navs = analysis.goto_type_definition(pos).unwrap().unwrap().info;
62 assert_eq!(navs.len(), 1); 62 assert_eq!(navs.len(), 1);
@@ -67,7 +67,7 @@ mod tests {
67 #[test] 67 #[test]
68 fn goto_type_definition_works_simple() { 68 fn goto_type_definition_works_simple() {
69 check_goto( 69 check_goto(
70 " 70 r"
71 //- /lib.rs 71 //- /lib.rs
72 struct Foo; 72 struct Foo;
73 fn foo() { 73 fn foo() {
@@ -82,7 +82,7 @@ mod tests {
82 #[test] 82 #[test]
83 fn goto_type_definition_works_simple_ref() { 83 fn goto_type_definition_works_simple_ref() {
84 check_goto( 84 check_goto(
85 " 85 r"
86 //- /lib.rs 86 //- /lib.rs
87 struct Foo; 87 struct Foo;
88 fn foo() { 88 fn foo() {
@@ -97,7 +97,7 @@ mod tests {
97 #[test] 97 #[test]
98 fn goto_type_definition_works_through_macro() { 98 fn goto_type_definition_works_through_macro() {
99 check_goto( 99 check_goto(
100 " 100 r"
101 //- /lib.rs 101 //- /lib.rs
102 macro_rules! id { 102 macro_rules! id {
103 ($($tt:tt)*) => { $($tt)* } 103 ($($tt:tt)*) => { $($tt)* }
@@ -116,7 +116,7 @@ mod tests {
116 #[test] 116 #[test]
117 fn goto_type_definition_for_param() { 117 fn goto_type_definition_for_param() {
118 check_goto( 118 check_goto(
119 " 119 r"
120 //- /lib.rs 120 //- /lib.rs
121 struct Foo; 121 struct Foo;
122 fn foo(<|>f: Foo) {} 122 fn foo(<|>f: Foo) {}
@@ -128,7 +128,7 @@ mod tests {
128 #[test] 128 #[test]
129 fn goto_type_definition_for_tuple_field() { 129 fn goto_type_definition_for_tuple_field() {
130 check_goto( 130 check_goto(
131 " 131 r"
132 //- /lib.rs 132 //- /lib.rs
133 struct Foo; 133 struct Foo;
134 struct Bar(Foo); 134 struct Bar(Foo);
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index c3e36a387..eaba2b61e 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -417,8 +417,8 @@ mod tests {
417 assert_eq!(offset, position.into()); 417 assert_eq!(offset, position.into());
418 } 418 }
419 419
420 fn check_hover_result(fixture: &str, expected: &[&str]) -> (String, Vec<HoverAction>) { 420 fn check_hover_result(ra_fixture: &str, expected: &[&str]) -> (String, Vec<HoverAction>) {
421 let (analysis, position) = analysis_and_position(fixture); 421 let (analysis, position) = analysis_and_position(ra_fixture);
422 let hover = analysis.hover(position).unwrap().unwrap(); 422 let hover = analysis.hover(position).unwrap().unwrap();
423 let mut results = Vec::from(hover.info.results()); 423 let mut results = Vec::from(hover.info.results());
424 results.sort(); 424 results.sort();
@@ -435,8 +435,8 @@ mod tests {
435 (content[hover.range].to_string(), hover.info.actions().to_vec()) 435 (content[hover.range].to_string(), hover.info.actions().to_vec())
436 } 436 }
437 437
438 fn check_hover_no_result(fixture: &str) { 438 fn check_hover_no_result(ra_fixture: &str) {
439 let (analysis, position) = analysis_and_position(fixture); 439 let (analysis, position) = analysis_and_position(ra_fixture);
440 assert!(analysis.hover(position).unwrap().is_none()); 440 assert!(analysis.hover(position).unwrap().is_none());
441 } 441 }
442 442
@@ -923,7 +923,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
923 #[test] 923 #[test]
924 fn test_hover_through_macro() { 924 fn test_hover_through_macro() {
925 let (hover_on, _) = check_hover_result( 925 let (hover_on, _) = check_hover_result(
926 " 926 r"
927 //- /lib.rs 927 //- /lib.rs
928 macro_rules! id { 928 macro_rules! id {
929 ($($tt:tt)*) => { $($tt)* } 929 ($($tt:tt)*) => { $($tt)* }
@@ -944,7 +944,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
944 #[test] 944 #[test]
945 fn test_hover_through_expr_in_macro() { 945 fn test_hover_through_expr_in_macro() {
946 let (hover_on, _) = check_hover_result( 946 let (hover_on, _) = check_hover_result(
947 " 947 r"
948 //- /lib.rs 948 //- /lib.rs
949 macro_rules! id { 949 macro_rules! id {
950 ($($tt:tt)*) => { $($tt)* } 950 ($($tt:tt)*) => { $($tt)* }
@@ -962,7 +962,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
962 #[test] 962 #[test]
963 fn test_hover_through_expr_in_macro_recursive() { 963 fn test_hover_through_expr_in_macro_recursive() {
964 let (hover_on, _) = check_hover_result( 964 let (hover_on, _) = check_hover_result(
965 " 965 r"
966 //- /lib.rs 966 //- /lib.rs
967 macro_rules! id_deep { 967 macro_rules! id_deep {
968 ($($tt:tt)*) => { $($tt)* } 968 ($($tt:tt)*) => { $($tt)* }
@@ -983,7 +983,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
983 #[test] 983 #[test]
984 fn test_hover_through_func_in_macro_recursive() { 984 fn test_hover_through_func_in_macro_recursive() {
985 let (hover_on, _) = check_hover_result( 985 let (hover_on, _) = check_hover_result(
986 " 986 r"
987 //- /lib.rs 987 //- /lib.rs
988 macro_rules! id_deep { 988 macro_rules! id_deep {
989 ($($tt:tt)*) => { $($tt)* } 989 ($($tt:tt)*) => { $($tt)* }
@@ -1026,7 +1026,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1026 #[test] 1026 #[test]
1027 fn test_hover_through_assert_macro() { 1027 fn test_hover_through_assert_macro() {
1028 let (hover_on, _) = check_hover_result( 1028 let (hover_on, _) = check_hover_result(
1029 r#" 1029 r"
1030 //- /lib.rs 1030 //- /lib.rs
1031 #[rustc_builtin_macro] 1031 #[rustc_builtin_macro]
1032 macro_rules! assert {} 1032 macro_rules! assert {}
@@ -1035,7 +1035,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1035 fn foo() { 1035 fn foo() {
1036 assert!(ba<|>r()); 1036 assert!(ba<|>r());
1037 } 1037 }
1038 "#, 1038 ",
1039 &["fn bar() -> bool"], 1039 &["fn bar() -> bool"],
1040 ); 1040 );
1041 1041
@@ -1077,14 +1077,14 @@ fn func(foo: i32) { if true { <|>foo; }; }
1077 #[test] 1077 #[test]
1078 fn test_hover_function_show_qualifiers() { 1078 fn test_hover_function_show_qualifiers() {
1079 check_hover_result( 1079 check_hover_result(
1080 " 1080 r"
1081 //- /lib.rs 1081 //- /lib.rs
1082 async fn foo<|>() {} 1082 async fn foo<|>() {}
1083 ", 1083 ",
1084 &["async fn foo()"], 1084 &["async fn foo()"],
1085 ); 1085 );
1086 check_hover_result( 1086 check_hover_result(
1087 " 1087 r"
1088 //- /lib.rs 1088 //- /lib.rs
1089 pub const unsafe fn foo<|>() {} 1089 pub const unsafe fn foo<|>() {}
1090 ", 1090 ",
@@ -1102,7 +1102,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1102 #[test] 1102 #[test]
1103 fn test_hover_trait_show_qualifiers() { 1103 fn test_hover_trait_show_qualifiers() {
1104 let (_, actions) = check_hover_result( 1104 let (_, actions) = check_hover_result(
1105 " 1105 r"
1106 //- /lib.rs 1106 //- /lib.rs
1107 unsafe trait foo<|>() {} 1107 unsafe trait foo<|>() {}
1108 ", 1108 ",
@@ -1114,7 +1114,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1114 #[test] 1114 #[test]
1115 fn test_hover_mod_with_same_name_as_function() { 1115 fn test_hover_mod_with_same_name_as_function() {
1116 check_hover_result( 1116 check_hover_result(
1117 " 1117 r"
1118 //- /lib.rs 1118 //- /lib.rs
1119 use self::m<|>y::Bar; 1119 use self::m<|>y::Bar;
1120 1120
@@ -1237,7 +1237,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1237 #[test] 1237 #[test]
1238 fn test_hover_trait_has_impl_action() { 1238 fn test_hover_trait_has_impl_action() {
1239 let (_, actions) = check_hover_result( 1239 let (_, actions) = check_hover_result(
1240 " 1240 r"
1241 //- /lib.rs 1241 //- /lib.rs
1242 trait foo<|>() {} 1242 trait foo<|>() {}
1243 ", 1243 ",
@@ -1249,7 +1249,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1249 #[test] 1249 #[test]
1250 fn test_hover_struct_has_impl_action() { 1250 fn test_hover_struct_has_impl_action() {
1251 let (_, actions) = check_hover_result( 1251 let (_, actions) = check_hover_result(
1252 " 1252 r"
1253 //- /lib.rs 1253 //- /lib.rs
1254 struct foo<|>() {} 1254 struct foo<|>() {}
1255 ", 1255 ",
@@ -1261,7 +1261,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1261 #[test] 1261 #[test]
1262 fn test_hover_union_has_impl_action() { 1262 fn test_hover_union_has_impl_action() {
1263 let (_, actions) = check_hover_result( 1263 let (_, actions) = check_hover_result(
1264 " 1264 r"
1265 //- /lib.rs 1265 //- /lib.rs
1266 union foo<|>() {} 1266 union foo<|>() {}
1267 ", 1267 ",
@@ -1273,7 +1273,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1273 #[test] 1273 #[test]
1274 fn test_hover_enum_has_impl_action() { 1274 fn test_hover_enum_has_impl_action() {
1275 let (_, actions) = check_hover_result( 1275 let (_, actions) = check_hover_result(
1276 " 1276 r"
1277 //- /lib.rs 1277 //- /lib.rs
1278 enum foo<|>() { 1278 enum foo<|>() {
1279 A, 1279 A,
@@ -1288,7 +1288,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1288 #[test] 1288 #[test]
1289 fn test_hover_test_has_action() { 1289 fn test_hover_test_has_action() {
1290 let (_, actions) = check_hover_result( 1290 let (_, actions) = check_hover_result(
1291 " 1291 r"
1292 //- /lib.rs 1292 //- /lib.rs
1293 #[test] 1293 #[test]
1294 fn foo_<|>test() {} 1294 fn foo_<|>test() {}
@@ -1332,7 +1332,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1332 #[test] 1332 #[test]
1333 fn test_hover_test_mod_has_action() { 1333 fn test_hover_test_mod_has_action() {
1334 let (_, actions) = check_hover_result( 1334 let (_, actions) = check_hover_result(
1335 " 1335 r"
1336 //- /lib.rs 1336 //- /lib.rs
1337 mod tests<|> { 1337 mod tests<|> {
1338 #[test] 1338 #[test]
@@ -1373,7 +1373,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1373 #[test] 1373 #[test]
1374 fn test_hover_struct_has_goto_type_action() { 1374 fn test_hover_struct_has_goto_type_action() {
1375 let (_, actions) = check_hover_result( 1375 let (_, actions) = check_hover_result(
1376 " 1376 r"
1377 //- /main.rs 1377 //- /main.rs
1378 struct S{ f1: u32 } 1378 struct S{ f1: u32 }
1379 1379
@@ -1416,7 +1416,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1416 #[test] 1416 #[test]
1417 fn test_hover_generic_struct_has_goto_type_actions() { 1417 fn test_hover_generic_struct_has_goto_type_actions() {
1418 let (_, actions) = check_hover_result( 1418 let (_, actions) = check_hover_result(
1419 " 1419 r"
1420 //- /main.rs 1420 //- /main.rs
1421 struct Arg(u32); 1421 struct Arg(u32);
1422 struct S<T>{ f1: T } 1422 struct S<T>{ f1: T }
@@ -1479,7 +1479,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1479 #[test] 1479 #[test]
1480 fn test_hover_generic_struct_has_flattened_goto_type_actions() { 1480 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
1481 let (_, actions) = check_hover_result( 1481 let (_, actions) = check_hover_result(
1482 " 1482 r"
1483 //- /main.rs 1483 //- /main.rs
1484 struct Arg(u32); 1484 struct Arg(u32);
1485 struct S<T>{ f1: T } 1485 struct S<T>{ f1: T }
@@ -1542,7 +1542,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1542 #[test] 1542 #[test]
1543 fn test_hover_tuple_has_goto_type_actions() { 1543 fn test_hover_tuple_has_goto_type_actions() {
1544 let (_, actions) = check_hover_result( 1544 let (_, actions) = check_hover_result(
1545 " 1545 r"
1546 //- /main.rs 1546 //- /main.rs
1547 struct A(u32); 1547 struct A(u32);
1548 struct B(u32); 1548 struct B(u32);
@@ -1627,7 +1627,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1627 #[test] 1627 #[test]
1628 fn test_hover_return_impl_trait_has_goto_type_action() { 1628 fn test_hover_return_impl_trait_has_goto_type_action() {
1629 let (_, actions) = check_hover_result( 1629 let (_, actions) = check_hover_result(
1630 " 1630 r"
1631 //- /main.rs 1631 //- /main.rs
1632 trait Foo {} 1632 trait Foo {}
1633 1633
@@ -1672,7 +1672,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1672 #[test] 1672 #[test]
1673 fn test_hover_generic_return_impl_trait_has_goto_type_action() { 1673 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
1674 let (_, actions) = check_hover_result( 1674 let (_, actions) = check_hover_result(
1675 " 1675 r"
1676 //- /main.rs 1676 //- /main.rs
1677 trait Foo<T> {} 1677 trait Foo<T> {}
1678 struct S; 1678 struct S;
@@ -1737,7 +1737,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1737 #[test] 1737 #[test]
1738 fn test_hover_return_impl_traits_has_goto_type_action() { 1738 fn test_hover_return_impl_traits_has_goto_type_action() {
1739 let (_, actions) = check_hover_result( 1739 let (_, actions) = check_hover_result(
1740 " 1740 r"
1741 //- /main.rs 1741 //- /main.rs
1742 trait Foo {} 1742 trait Foo {}
1743 trait Bar {} 1743 trait Bar {}
@@ -1802,7 +1802,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1802 #[test] 1802 #[test]
1803 fn test_hover_generic_return_impl_traits_has_goto_type_action() { 1803 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
1804 let (_, actions) = check_hover_result( 1804 let (_, actions) = check_hover_result(
1805 " 1805 r"
1806 //- /main.rs 1806 //- /main.rs
1807 trait Foo<T> {} 1807 trait Foo<T> {}
1808 trait Bar<T> {} 1808 trait Bar<T> {}
@@ -1907,7 +1907,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1907 #[test] 1907 #[test]
1908 fn test_hover_arg_impl_trait_has_goto_type_action() { 1908 fn test_hover_arg_impl_trait_has_goto_type_action() {
1909 let (_, actions) = check_hover_result( 1909 let (_, actions) = check_hover_result(
1910 " 1910 r"
1911 //- /lib.rs 1911 //- /lib.rs
1912 trait Foo {} 1912 trait Foo {}
1913 fn foo(ar<|>g: &impl Foo) {} 1913 fn foo(ar<|>g: &impl Foo) {}
@@ -1947,7 +1947,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
1947 #[test] 1947 #[test]
1948 fn test_hover_arg_impl_traits_has_goto_type_action() { 1948 fn test_hover_arg_impl_traits_has_goto_type_action() {
1949 let (_, actions) = check_hover_result( 1949 let (_, actions) = check_hover_result(
1950 " 1950 r"
1951 //- /lib.rs 1951 //- /lib.rs
1952 trait Foo {} 1952 trait Foo {}
1953 trait Bar<T> {} 1953 trait Bar<T> {}
@@ -2028,7 +2028,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
2028 #[test] 2028 #[test]
2029 fn test_hover_arg_generic_impl_trait_has_goto_type_action() { 2029 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2030 let (_, actions) = check_hover_result( 2030 let (_, actions) = check_hover_result(
2031 " 2031 r"
2032 //- /lib.rs 2032 //- /lib.rs
2033 trait Foo<T> {} 2033 trait Foo<T> {}
2034 struct S {} 2034 struct S {}
@@ -2088,7 +2088,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
2088 #[test] 2088 #[test]
2089 fn test_hover_dyn_return_has_goto_type_action() { 2089 fn test_hover_dyn_return_has_goto_type_action() {
2090 let (_, actions) = check_hover_result( 2090 let (_, actions) = check_hover_result(
2091 " 2091 r"
2092 //- /main.rs 2092 //- /main.rs
2093 trait Foo {} 2093 trait Foo {}
2094 struct S; 2094 struct S;
@@ -2156,7 +2156,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
2156 #[test] 2156 #[test]
2157 fn test_hover_dyn_arg_has_goto_type_action() { 2157 fn test_hover_dyn_arg_has_goto_type_action() {
2158 let (_, actions) = check_hover_result( 2158 let (_, actions) = check_hover_result(
2159 " 2159 r"
2160 //- /lib.rs 2160 //- /lib.rs
2161 trait Foo {} 2161 trait Foo {}
2162 fn foo(ar<|>g: &dyn Foo) {} 2162 fn foo(ar<|>g: &dyn Foo) {}
@@ -2196,7 +2196,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
2196 #[test] 2196 #[test]
2197 fn test_hover_generic_dyn_arg_has_goto_type_action() { 2197 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2198 let (_, actions) = check_hover_result( 2198 let (_, actions) = check_hover_result(
2199 " 2199 r"
2200 //- /lib.rs 2200 //- /lib.rs
2201 trait Foo<T> {} 2201 trait Foo<T> {}
2202 struct S {} 2202 struct S {}
@@ -2256,7 +2256,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
2256 #[test] 2256 #[test]
2257 fn test_hover_goto_type_action_links_order() { 2257 fn test_hover_goto_type_action_links_order() {
2258 let (_, actions) = check_hover_result( 2258 let (_, actions) = check_hover_result(
2259 " 2259 r"
2260 //- /lib.rs 2260 //- /lib.rs
2261 trait ImplTrait<T> {} 2261 trait ImplTrait<T> {}
2262 trait DynTrait<T> {} 2262 trait DynTrait<T> {}
@@ -2357,7 +2357,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
2357 #[test] 2357 #[test]
2358 fn test_hover_associated_type_has_goto_type_action() { 2358 fn test_hover_associated_type_has_goto_type_action() {
2359 let (_, actions) = check_hover_result( 2359 let (_, actions) = check_hover_result(
2360 " 2360 r"
2361 //- /main.rs 2361 //- /main.rs
2362 trait Foo { 2362 trait Foo {
2363 type Item; 2363 type Item;
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index c87652555..62d364bfa 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -3,7 +3,7 @@ use ra_ide_db::RootDatabase;
3use ra_prof::profile; 3use ra_prof::profile;
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner}, 5 ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner},
6 match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, 6 match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, T,
7}; 7};
8 8
9use crate::{FileId, FunctionSignature}; 9use crate::{FileId, FunctionSignature};
@@ -112,7 +112,7 @@ fn get_chaining_hints(
112 // Ignoring extra whitespace and comments 112 // Ignoring extra whitespace and comments
113 let next = tokens.next()?.kind(); 113 let next = tokens.next()?.kind();
114 let next_next = tokens.next()?.kind(); 114 let next_next = tokens.next()?.kind();
115 if next == SyntaxKind::WHITESPACE && next_next == SyntaxKind::DOT { 115 if next == SyntaxKind::WHITESPACE && next_next == T![.] {
116 let ty = sema.type_of_expr(&expr)?; 116 let ty = sema.type_of_expr(&expr)?;
117 if ty.is_unknown() { 117 if ty.is_unknown() {
118 return None; 118 return None;
@@ -345,583 +345,251 @@ fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<
345 345
346#[cfg(test)] 346#[cfg(test)]
347mod tests { 347mod tests {
348 use crate::inlay_hints::InlayHintsConfig; 348 use expect::{expect, Expect};
349 use insta::assert_debug_snapshot; 349 use test_utils::extract_annotations;
350 350
351 use crate::mock_analysis::single_file; 351 use crate::{inlay_hints::InlayHintsConfig, mock_analysis::single_file};
352
353 fn check(ra_fixture: &str) {
354 check_with_config(ra_fixture, InlayHintsConfig::default());
355 }
356
357 fn check_with_config(ra_fixture: &str, config: InlayHintsConfig) {
358 let (analysis, file_id) = single_file(ra_fixture);
359 let expected = extract_annotations(&*analysis.file_text(file_id).unwrap());
360 let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap();
361 let actual =
362 inlay_hints.into_iter().map(|it| (it.range, it.label.to_string())).collect::<Vec<_>>();
363 assert_eq!(expected, actual);
364 }
365
366 fn check_expect(ra_fixture: &str, config: InlayHintsConfig, expect: Expect) {
367 let (analysis, file_id) = single_file(ra_fixture);
368 let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap();
369 expect.assert_debug_eq(&inlay_hints)
370 }
352 371
353 #[test] 372 #[test]
354 fn param_hints_only() { 373 fn param_hints_only() {
355 let (analysis, file_id) = single_file( 374 check_with_config(
356 r#" 375 r#"
357 fn foo(a: i32, b: i32) -> i32 { a + b } 376fn foo(a: i32, b: i32) -> i32 { a + b }
358 fn main() { 377fn main() {
359 let _x = foo(4, 4); 378 let _x = foo(
360 }"#, 379 4,
361 ); 380 //^ a
362 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: true, type_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" 381 4,
363 [ 382 //^ b
364 InlayHint { 383 );
365 range: 69..70, 384}"#,
366 kind: ParameterHint, 385 InlayHintsConfig {
367 label: "a", 386 parameter_hints: true,
368 }, 387 type_hints: false,
369 InlayHint { 388 chaining_hints: false,
370 range: 72..73, 389 max_length: None,
371 kind: ParameterHint,
372 label: "b",
373 }, 390 },
374 ] 391 );
375 "###);
376 } 392 }
377 393
378 #[test] 394 #[test]
379 fn hints_disabled() { 395 fn hints_disabled() {
380 let (analysis, file_id) = single_file( 396 check_with_config(
381 r#" 397 r#"
382 fn foo(a: i32, b: i32) -> i32 { a + b } 398fn foo(a: i32, b: i32) -> i32 { a + b }
383 fn main() { 399fn main() {
384 let _x = foo(4, 4); 400 let _x = foo(4, 4);
385 }"#, 401}"#,
402 InlayHintsConfig {
403 type_hints: false,
404 parameter_hints: false,
405 chaining_hints: false,
406 max_length: None,
407 },
386 ); 408 );
387 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ type_hints: false, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###"[]"###);
388 } 409 }
389 410
390 #[test] 411 #[test]
391 fn type_hints_only() { 412 fn type_hints_only() {
392 let (analysis, file_id) = single_file( 413 check_with_config(
393 r#" 414 r#"
394 fn foo(a: i32, b: i32) -> i32 { a + b } 415fn foo(a: i32, b: i32) -> i32 { a + b }
395 fn main() { 416fn main() {
396 let _x = foo(4, 4); 417 let _x = foo(4, 4);
397 }"#, 418 //^^ i32
398 ); 419}"#,
399 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ type_hints: true, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" 420 InlayHintsConfig {
400 [ 421 type_hints: true,
401 InlayHint { 422 parameter_hints: false,
402 range: 60..62, 423 chaining_hints: false,
403 kind: TypeHint, 424 max_length: None,
404 label: "i32",
405 }, 425 },
406 ] 426 );
407 "###);
408 } 427 }
428
409 #[test] 429 #[test]
410 fn default_generic_types_should_not_be_displayed() { 430 fn default_generic_types_should_not_be_displayed() {
411 let (analysis, file_id) = single_file( 431 check(
412 r#" 432 r#"
413struct Test<K, T = u8> { 433struct Test<K, T = u8> { k: K, t: T }
414 k: K,
415 t: T,
416}
417 434
418fn main() { 435fn main() {
419 let zz = Test { t: 23u8, k: 33 }; 436 let zz = Test { t: 23u8, k: 33 };
437 //^^ Test<i32>
420 let zz_ref = &zz; 438 let zz_ref = &zz;
439 //^^^^^^ &Test<i32>
421}"#, 440}"#,
422 ); 441 );
423
424 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
425 [
426 InlayHint {
427 range: 68..70,
428 kind: TypeHint,
429 label: "Test<i32>",
430 },
431 InlayHint {
432 range: 106..112,
433 kind: TypeHint,
434 label: "&Test<i32>",
435 },
436 ]
437 "###
438 );
439 } 442 }
440 443
441 #[test] 444 #[test]
442 fn let_statement() { 445 fn let_statement() {
443 let (analysis, file_id) = single_file( 446 check(
444 r#" 447 r#"
445#[derive(PartialEq)] 448#[derive(PartialEq)]
446enum CustomOption<T> { 449enum Option<T> { None, Some(T) }
447 None,
448 Some(T),
449}
450 450
451#[derive(PartialEq)] 451#[derive(PartialEq)]
452struct Test { 452struct Test { a: Option<u32>, b: u8 }
453 a: CustomOption<u32>,
454 b: u8,
455}
456 453
457fn main() { 454fn main() {
458 struct InnerStruct {} 455 struct InnerStruct {}
459 456
460 let test = 54; 457 let test = 54;
458 //^^^^ i32
461 let test: i32 = 33; 459 let test: i32 = 33;
462 let mut test = 33; 460 let mut test = 33;
461 //^^^^^^^^ i32
463 let _ = 22; 462 let _ = 22;
464 let test = "test"; 463 let test = "test";
464 //^^^^ &str
465 let test = InnerStruct {}; 465 let test = InnerStruct {};
466 466
467 let test = vec![222]; 467 let test = unresolved();
468 let test: Vec<_> = (0..3).collect();
469 let test = (0..3).collect::<Vec<i128>>();
470 let test = (0..3).collect::<Vec<_>>();
471
472 let mut test = Vec::new();
473 test.push(333);
474 468
475 let test = (42, 'a'); 469 let test = (42, 'a');
476 let (a, (b, c, (d, e), f)) = (2, (3, 4, (6.6, 7.7), 5)); 470 //^^^^ (i32, char)
471 let (a, (b, (c,)) = (2, (3, (9.2,));
472 //^ i32 ^ i32 ^ f64
477 let &x = &92; 473 let &x = &92;
474 //^ i32
478}"#, 475}"#,
479 ); 476 );
480
481 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
482 [
483 InlayHint {
484 range: 192..196,
485 kind: TypeHint,
486 label: "i32",
487 },
488 InlayHint {
489 range: 235..243,
490 kind: TypeHint,
491 label: "i32",
492 },
493 InlayHint {
494 range: 274..278,
495 kind: TypeHint,
496 label: "&str",
497 },
498 InlayHint {
499 range: 538..542,
500 kind: TypeHint,
501 label: "(i32, char)",
502 },
503 InlayHint {
504 range: 565..566,
505 kind: TypeHint,
506 label: "i32",
507 },
508 InlayHint {
509 range: 569..570,
510 kind: TypeHint,
511 label: "i32",
512 },
513 InlayHint {
514 range: 572..573,
515 kind: TypeHint,
516 label: "i32",
517 },
518 InlayHint {
519 range: 576..577,
520 kind: TypeHint,
521 label: "f64",
522 },
523 InlayHint {
524 range: 579..580,
525 kind: TypeHint,
526 label: "f64",
527 },
528 InlayHint {
529 range: 583..584,
530 kind: TypeHint,
531 label: "i32",
532 },
533 InlayHint {
534 range: 626..627,
535 kind: TypeHint,
536 label: "i32",
537 },
538 ]
539 "###
540 );
541 } 477 }
542 478
543 #[test] 479 #[test]
544 fn closure_parameters() { 480 fn closure_parameters() {
545 let (analysis, file_id) = single_file( 481 check(
546 r#" 482 r#"
547fn main() { 483fn main() {
548 let mut start = 0; 484 let mut start = 0;
549 (0..2).for_each(|increment| { 485 //^^^^^^^^^ i32
550 start += increment; 486 (0..2).for_each(|increment| { start += increment; });
551 }); 487 //^^^^^^^^^ i32
488
489 let multiply =
490 //^^^^^^^^ |…| -> i32
491 | a, b| a * b
492 //^ i32 ^ i32
493 ;
552 494
553 let multiply = |a, b, c, d| a * b * c * d; 495 let _: i32 = multiply(1, 2);
554 let _: i32 = multiply(1, 2, 3, 4);
555 let multiply_ref = &multiply; 496 let multiply_ref = &multiply;
497 //^^^^^^^^^^^^ &|…| -> i32
556 498
557 let return_42 = || 42; 499 let return_42 = || 42;
500 //^^^^^^^^^ || -> i32
558}"#, 501}"#,
559 ); 502 );
560
561 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
562 [
563 InlayHint {
564 range: 20..29,
565 kind: TypeHint,
566 label: "i32",
567 },
568 InlayHint {
569 range: 56..65,
570 kind: TypeHint,
571 label: "i32",
572 },
573 InlayHint {
574 range: 114..122,
575 kind: TypeHint,
576 label: "|…| -> i32",
577 },
578 InlayHint {
579 range: 126..127,
580 kind: TypeHint,
581 label: "i32",
582 },
583 InlayHint {
584 range: 129..130,
585 kind: TypeHint,
586 label: "i32",
587 },
588 InlayHint {
589 range: 132..133,
590 kind: TypeHint,
591 label: "i32",
592 },
593 InlayHint {
594 range: 135..136,
595 kind: TypeHint,
596 label: "i32",
597 },
598 InlayHint {
599 range: 200..212,
600 kind: TypeHint,
601 label: "&|…| -> i32",
602 },
603 InlayHint {
604 range: 235..244,
605 kind: TypeHint,
606 label: "|| -> i32",
607 },
608 ]
609 "###
610 );
611 } 503 }
612 504
613 #[test] 505 #[test]
614 fn for_expression() { 506 fn for_expression() {
615 let (analysis, file_id) = single_file( 507 check(
616 r#" 508 r#"
617fn main() { 509fn main() {
618 let mut start = 0; 510 let mut start = 0;
619 for increment in 0..2 { 511 //^^^^^^^^^ i32
620 start += increment; 512 for increment in 0..2 { start += increment; }
621 } 513 //^^^^^^^^^ i32
622}"#, 514}"#,
623 ); 515 );
624
625 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
626 [
627 InlayHint {
628 range: 20..29,
629 kind: TypeHint,
630 label: "i32",
631 },
632 InlayHint {
633 range: 43..52,
634 kind: TypeHint,
635 label: "i32",
636 },
637 ]
638 "###
639 );
640 } 516 }
641 517
642 #[test] 518 #[test]
643 fn if_expr() { 519 fn if_expr() {
644 let (analysis, file_id) = single_file( 520 check(
645 r#" 521 r#"
646#[derive(PartialEq)] 522enum Option<T> { None, Some(T) }
647enum CustomOption<T> { 523use Option::*;
648 None,
649 Some(T),
650}
651
652#[derive(PartialEq)]
653struct Test {
654 a: CustomOption<u32>,
655 b: u8,
656}
657 524
658use CustomOption::*; 525struct Test { a: Option<u32>, b: u8 }
659 526
660fn main() { 527fn main() {
661 let test = Some(Test { a: Some(3), b: 1 }); 528 let test = Some(Test { a: Some(3), b: 1 });
529 //^^^^ Option<Test>
662 if let None = &test {}; 530 if let None = &test {};
663 if let test = &test {}; 531 if let test = &test {};
532 //^^^^ &Option<Test>
664 if let Some(test) = &test {}; 533 if let Some(test) = &test {};
665 if let Some(Test { a, b }) = &test {}; 534 //^^^^ &Test
666 if let Some(Test { a: x, b: y }) = &test {}; 535 if let Some(Test { a, b }) = &test {};
667 if let Some(Test { a: Some(x), b: y }) = &test {}; 536 //^ &Option<u32> ^ &u8
668 if let Some(Test { a: None, b: y }) = &test {}; 537 if let Some(Test { a: x, b: y }) = &test {};
538 //^ &Option<u32> ^ &u8
539 if let Some(Test { a: Some(x), b: y }) = &test {};
540 //^ &u32 ^ &u8
541 if let Some(Test { a: None, b: y }) = &test {};
542 //^ &u8
669 if let Some(Test { b: y, .. }) = &test {}; 543 if let Some(Test { b: y, .. }) = &test {};
670 544 //^ &u8
671 if test == None {} 545 if test == None {}
672}"#, 546}"#,
673 ); 547 );
674
675 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
676 [
677 InlayHint {
678 range: 187..191,
679 kind: TypeHint,
680 label: "CustomOption<Test>",
681 },
682 InlayHint {
683 range: 266..270,
684 kind: TypeHint,
685 label: "&CustomOption<Test>",
686 },
687 InlayHint {
688 range: 299..303,
689 kind: TypeHint,
690 label: "&Test",
691 },
692 InlayHint {
693 range: 340..341,
694 kind: TypeHint,
695 label: "&CustomOption<u32>",
696 },
697 InlayHint {
698 range: 343..344,
699 kind: TypeHint,
700 label: "&u8",
701 },
702 InlayHint {
703 range: 386..387,
704 kind: TypeHint,
705 label: "&CustomOption<u32>",
706 },
707 InlayHint {
708 range: 392..393,
709 kind: TypeHint,
710 label: "&u8",
711 },
712 InlayHint {
713 range: 440..441,
714 kind: TypeHint,
715 label: "&u32",
716 },
717 InlayHint {
718 range: 447..448,
719 kind: TypeHint,
720 label: "&u8",
721 },
722 InlayHint {
723 range: 499..500,
724 kind: TypeHint,
725 label: "&u8",
726 },
727 InlayHint {
728 range: 542..543,
729 kind: TypeHint,
730 label: "&u8",
731 },
732 ]
733 "###
734 );
735 } 548 }
736 549
737 #[test] 550 #[test]
738 fn while_expr() { 551 fn while_expr() {
739 let (analysis, file_id) = single_file( 552 check(
740 r#" 553 r#"
741#[derive(PartialEq)] 554enum Option<T> { None, Some(T) }
742enum CustomOption<T> { 555use Option::*;
743 None,
744 Some(T),
745}
746 556
747#[derive(PartialEq)] 557struct Test { a: Option<u32>, b: u8 }
748struct Test {
749 a: CustomOption<u32>,
750 b: u8,
751}
752
753use CustomOption::*;
754 558
755fn main() { 559fn main() {
756 let test = Some(Test { a: Some(3), b: 1 }); 560 let test = Some(Test { a: Some(3), b: 1 });
757 while let None = &test {}; 561 //^^^^ Option<Test>
758 while let test = &test {}; 562 while let Some(Test { a: Some(x), b: y }) = &test {};
759 while let Some(test) = &test {}; 563 //^ &u32 ^ &u8
760 while let Some(Test { a, b }) = &test {};
761 while let Some(Test { a: x, b: y }) = &test {};
762 while let Some(Test { a: Some(x), b: y }) = &test {};
763 while let Some(Test { a: None, b: y }) = &test {};
764 while let Some(Test { b: y, .. }) = &test {};
765
766 while test == None {}
767}"#, 564}"#,
768 ); 565 );
769
770 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
771 [
772 InlayHint {
773 range: 187..191,
774 kind: TypeHint,
775 label: "CustomOption<Test>",
776 },
777 InlayHint {
778 range: 272..276,
779 kind: TypeHint,
780 label: "&CustomOption<Test>",
781 },
782 InlayHint {
783 range: 308..312,
784 kind: TypeHint,
785 label: "&Test",
786 },
787 InlayHint {
788 range: 352..353,
789 kind: TypeHint,
790 label: "&CustomOption<u32>",
791 },
792 InlayHint {
793 range: 355..356,
794 kind: TypeHint,
795 label: "&u8",
796 },
797 InlayHint {
798 range: 401..402,
799 kind: TypeHint,
800 label: "&CustomOption<u32>",
801 },
802 InlayHint {
803 range: 407..408,
804 kind: TypeHint,
805 label: "&u8",
806 },
807 InlayHint {
808 range: 458..459,
809 kind: TypeHint,
810 label: "&u32",
811 },
812 InlayHint {
813 range: 465..466,
814 kind: TypeHint,
815 label: "&u8",
816 },
817 InlayHint {
818 range: 520..521,
819 kind: TypeHint,
820 label: "&u8",
821 },
822 InlayHint {
823 range: 566..567,
824 kind: TypeHint,
825 label: "&u8",
826 },
827 ]
828 "###
829 );
830 } 566 }
831 567
832 #[test] 568 #[test]
833 fn match_arm_list() { 569 fn match_arm_list() {
834 let (analysis, file_id) = single_file( 570 check(
835 r#" 571 r#"
836#[derive(PartialEq)] 572enum Option<T> { None, Some(T) }
837enum CustomOption<T> { 573use Option::*;
838 None,
839 Some(T),
840}
841
842#[derive(PartialEq)]
843struct Test {
844 a: CustomOption<u32>,
845 b: u8,
846}
847 574
848use CustomOption::*; 575struct Test { a: Option<u32>, b: u8 }
849 576
850fn main() { 577fn main() {
851 match Some(Test { a: Some(3), b: 1 }) { 578 match Some(Test { a: Some(3), b: 1 }) {
852 None => (), 579 None => (),
853 test => (), 580 test => (),
854 Some(test) => (), 581 //^^^^ Option<Test>
855 Some(Test { a, b }) => (),
856 Some(Test { a: x, b: y }) => (),
857 Some(Test { a: Some(x), b: y }) => (), 582 Some(Test { a: Some(x), b: y }) => (),
858 Some(Test { a: None, b: y }) => (), 583 //^ u32 ^ u8
859 Some(Test { b: y, .. }) => (),
860 _ => {} 584 _ => {}
861 } 585 }
862}"#, 586}"#,
863 ); 587 );
864
865 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
866 [
867 InlayHint {
868 range: 251..255,
869 kind: TypeHint,
870 label: "CustomOption<Test>",
871 },
872 InlayHint {
873 range: 276..280,
874 kind: TypeHint,
875 label: "Test",
876 },
877 InlayHint {
878 range: 309..310,
879 kind: TypeHint,
880 label: "CustomOption<u32>",
881 },
882 InlayHint {
883 range: 312..313,
884 kind: TypeHint,
885 label: "u8",
886 },
887 InlayHint {
888 range: 347..348,
889 kind: TypeHint,
890 label: "CustomOption<u32>",
891 },
892 InlayHint {
893 range: 353..354,
894 kind: TypeHint,
895 label: "u8",
896 },
897 InlayHint {
898 range: 393..394,
899 kind: TypeHint,
900 label: "u32",
901 },
902 InlayHint {
903 range: 400..401,
904 kind: TypeHint,
905 label: "u8",
906 },
907 InlayHint {
908 range: 444..445,
909 kind: TypeHint,
910 label: "u8",
911 },
912 InlayHint {
913 range: 479..480,
914 kind: TypeHint,
915 label: "u8",
916 },
917 ]
918 "###
919 );
920 } 588 }
921 589
922 #[test] 590 #[test]
923 fn hint_truncation() { 591 fn hint_truncation() {
924 let (analysis, file_id) = single_file( 592 check_with_config(
925 r#" 593 r#"
926struct Smol<T>(T); 594struct Smol<T>(T);
927 595
@@ -929,52 +597,26 @@ struct VeryLongOuterName<T>(T);
929 597
930fn main() { 598fn main() {
931 let a = Smol(0u32); 599 let a = Smol(0u32);
600 //^ Smol<u32>
932 let b = VeryLongOuterName(0usize); 601 let b = VeryLongOuterName(0usize);
602 //^ VeryLongOuterName<…>
933 let c = Smol(Smol(0u32)) 603 let c = Smol(Smol(0u32))
604 //^ Smol<Smol<…>>
934}"#, 605}"#,
935 ); 606 InlayHintsConfig { max_length: Some(8), ..Default::default() },
936
937 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###"
938 [
939 InlayHint {
940 range: 73..74,
941 kind: TypeHint,
942 label: "Smol<u32>",
943 },
944 InlayHint {
945 range: 97..98,
946 kind: TypeHint,
947 label: "VeryLongOuterName<…>",
948 },
949 InlayHint {
950 range: 136..137,
951 kind: TypeHint,
952 label: "Smol<Smol<…>>",
953 },
954 ]
955 "###
956 ); 607 );
957 } 608 }
958 609
959 #[test] 610 #[test]
960 fn function_call_parameter_hint() { 611 fn function_call_parameter_hint() {
961 let (analysis, file_id) = single_file( 612 check(
962 r#" 613 r#"
963enum CustomOption<T> { 614enum Option<T> { None, Some(T) }
964 None, 615use Option::*;
965 Some(T),
966}
967use CustomOption::*;
968 616
969struct FileId {} 617struct FileId {}
970struct SmolStr {} 618struct SmolStr {}
971 619
972impl From<&str> for SmolStr {
973 fn from(_: &str) -> Self {
974 unimplemented!()
975 }
976}
977
978struct TextRange {} 620struct TextRange {}
979struct SyntaxKind {} 621struct SyntaxKind {}
980struct NavigationTarget {} 622struct NavigationTarget {}
@@ -982,18 +624,15 @@ struct NavigationTarget {}
982struct Test {} 624struct Test {}
983 625
984impl Test { 626impl Test {
985 fn method(&self, mut param: i32) -> i32 { 627 fn method(&self, mut param: i32) -> i32 { param * 2 }
986 param * 2
987 }
988 628
989 fn from_syntax( 629 fn from_syntax(
990 file_id: FileId, 630 file_id: FileId,
991 name: SmolStr, 631 name: SmolStr,
992 focus_range: CustomOption<TextRange>, 632 focus_range: Option<TextRange>,
993 full_range: TextRange, 633 full_range: TextRange,
994 kind: SyntaxKind, 634 kind: SyntaxKind,
995 docs: CustomOption<String>, 635 docs: Option<String>,
996 description: CustomOption<String>,
997 ) -> NavigationTarget { 636 ) -> NavigationTarget {
998 NavigationTarget {} 637 NavigationTarget {}
999 } 638 }
@@ -1005,108 +644,35 @@ fn test_func(mut foo: i32, bar: i32, msg: &str, _: i32, last: i32) -> i32 {
1005 644
1006fn main() { 645fn main() {
1007 let not_literal = 1; 646 let not_literal = 1;
1008 let _: i32 = test_func(1, 2, "hello", 3, not_literal); 647 //^^^^^^^^^^^ i32
648 let _: i32 = test_func(1, 2, "hello", 3, not_literal);
649 //^ foo ^ bar ^^^^^^^ msg ^^^^^^^^^^^ last
1009 let t: Test = Test {}; 650 let t: Test = Test {};
1010 t.method(123); 651 t.method(123);
1011 Test::method(&t, 3456); 652 //^^^ param
1012 653 Test::method(&t, 3456);
654 //^^ &self ^^^^ param
1013 Test::from_syntax( 655 Test::from_syntax(
1014 FileId {}, 656 FileId {},
657 //^^^^^^^^^ file_id
1015 "impl".into(), 658 "impl".into(),
659 //^^^^^^^^^^^^^ name
1016 None, 660 None,
661 //^^^^ focus_range
1017 TextRange {}, 662 TextRange {},
663 //^^^^^^^^^^^^ full_range
1018 SyntaxKind {}, 664 SyntaxKind {},
665 //^^^^^^^^^^^^^ kind
1019 None, 666 None,
1020 None, 667 //^^^^ docs
1021 ); 668 );
1022}"#, 669}"#,
1023 ); 670 );
1024
1025 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
1026 [
1027 InlayHint {
1028 range: 797..808,
1029 kind: TypeHint,
1030 label: "i32",
1031 },
1032 InlayHint {
1033 range: 841..842,
1034 kind: ParameterHint,
1035 label: "foo",
1036 },
1037 InlayHint {
1038 range: 844..845,
1039 kind: ParameterHint,
1040 label: "bar",
1041 },
1042 InlayHint {
1043 range: 847..854,
1044 kind: ParameterHint,
1045 label: "msg",
1046 },
1047 InlayHint {
1048 range: 859..870,
1049 kind: ParameterHint,
1050 label: "last",
1051 },
1052 InlayHint {
1053 range: 913..916,
1054 kind: ParameterHint,
1055 label: "param",
1056 },
1057 InlayHint {
1058 range: 936..938,
1059 kind: ParameterHint,
1060 label: "&self",
1061 },
1062 InlayHint {
1063 range: 940..944,
1064 kind: ParameterHint,
1065 label: "param",
1066 },
1067 InlayHint {
1068 range: 979..988,
1069 kind: ParameterHint,
1070 label: "file_id",
1071 },
1072 InlayHint {
1073 range: 998..1011,
1074 kind: ParameterHint,
1075 label: "name",
1076 },
1077 InlayHint {
1078 range: 1021..1025,
1079 kind: ParameterHint,
1080 label: "focus_range",
1081 },
1082 InlayHint {
1083 range: 1035..1047,
1084 kind: ParameterHint,
1085 label: "full_range",
1086 },
1087 InlayHint {
1088 range: 1057..1070,
1089 kind: ParameterHint,
1090 label: "kind",
1091 },
1092 InlayHint {
1093 range: 1080..1084,
1094 kind: ParameterHint,
1095 label: "docs",
1096 },
1097 InlayHint {
1098 range: 1094..1098,
1099 kind: ParameterHint,
1100 label: "description",
1101 },
1102 ]
1103 "###
1104 );
1105 } 671 }
1106 672
1107 #[test] 673 #[test]
1108 fn omitted_parameters_hints_heuristics() { 674 fn omitted_parameters_hints_heuristics() {
1109 let (analysis, file_id) = single_file( 675 check_with_config(
1110 r#" 676 r#"
1111fn map(f: i32) {} 677fn map(f: i32) {}
1112fn filter(predicate: i32) {} 678fn filter(predicate: i32) {}
@@ -1187,23 +753,16 @@ fn main() {
1187 let _: f64 = a.div_euclid(b); 753 let _: f64 = a.div_euclid(b);
1188 let _: f64 = a.abs_sub(b); 754 let _: f64 = a.abs_sub(b);
1189}"#, 755}"#,
1190 ); 756 InlayHintsConfig { max_length: Some(8), ..Default::default() },
1191
1192 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###"
1193 []
1194 "###
1195 ); 757 );
1196 } 758 }
1197 759
1198 #[test] 760 #[test]
1199 fn unit_structs_have_no_type_hints() { 761 fn unit_structs_have_no_type_hints() {
1200 let (analysis, file_id) = single_file( 762 check_with_config(
1201 r#" 763 r#"
1202enum CustomResult<T, E> { 764enum Result<T, E> { Ok(T), Err(E) }
1203 Ok(T), 765use Result::*;
1204 Err(E),
1205}
1206use CustomResult::*;
1207 766
1208struct SyntheticSyntax; 767struct SyntheticSyntax;
1209 768
@@ -1213,136 +772,157 @@ fn main() {
1213 Err(SyntheticSyntax) => (), 772 Err(SyntheticSyntax) => (),
1214 } 773 }
1215}"#, 774}"#,
1216 ); 775 InlayHintsConfig { max_length: Some(8), ..Default::default() },
1217
1218 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###"
1219 []
1220 "###
1221 ); 776 );
1222 } 777 }
1223 778
1224 #[test] 779 #[test]
1225 fn chaining_hints_ignore_comments() { 780 fn chaining_hints_ignore_comments() {
1226 let (analysis, file_id) = single_file( 781 check_expect(
1227 r#" 782 r#"
1228 struct A(B); 783struct A(B);
1229 impl A { fn into_b(self) -> B { self.0 } } 784impl A { fn into_b(self) -> B { self.0 } }
1230 struct B(C); 785struct B(C);
1231 impl B { fn into_c(self) -> C { self.0 } } 786impl B { fn into_c(self) -> C { self.0 } }
1232 struct C; 787struct C;
1233 788
1234 fn main() { 789fn main() {
1235 let c = A(B(C)) 790 let c = A(B(C))
1236 .into_b() // This is a comment 791 .into_b() // This is a comment
1237 .into_c(); 792 .into_c();
1238 }"#, 793}
794"#,
795 InlayHintsConfig {
796 parameter_hints: false,
797 type_hints: false,
798 chaining_hints: true,
799 max_length: None,
800 },
801 expect![[r#"
802 [
803 InlayHint {
804 range: 147..172,
805 kind: ChainingHint,
806 label: "B",
807 },
808 InlayHint {
809 range: 147..154,
810 kind: ChainingHint,
811 label: "A",
812 },
813 ]
814 "#]],
1239 ); 815 );
1240 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"
1241 [
1242 InlayHint {
1243 range: 147..172,
1244 kind: ChainingHint,
1245 label: "B",
1246 },
1247 InlayHint {
1248 range: 147..154,
1249 kind: ChainingHint,
1250 label: "A",
1251 },
1252 ]
1253 "###);
1254 } 816 }
1255 817
1256 #[test] 818 #[test]
1257 fn chaining_hints_without_newlines() { 819 fn chaining_hints_without_newlines() {
1258 let (analysis, file_id) = single_file( 820 check_with_config(
1259 r#" 821 r#"
1260 struct A(B); 822struct A(B);
1261 impl A { fn into_b(self) -> B { self.0 } } 823impl A { fn into_b(self) -> B { self.0 } }
1262 struct B(C); 824struct B(C);
1263 impl B { fn into_c(self) -> C { self.0 } } 825impl B { fn into_c(self) -> C { self.0 } }
1264 struct C; 826struct C;
1265 827
1266 fn main() { 828fn main() {
1267 let c = A(B(C)).into_b().into_c(); 829 let c = A(B(C)).into_b().into_c();
1268 }"#, 830}"#,
831 InlayHintsConfig {
832 parameter_hints: false,
833 type_hints: false,
834 chaining_hints: true,
835 max_length: None,
836 },
1269 ); 837 );
1270 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"[]"###);
1271 } 838 }
1272 839
1273 #[test] 840 #[test]
1274 fn struct_access_chaining_hints() { 841 fn struct_access_chaining_hints() {
1275 let (analysis, file_id) = single_file( 842 check_expect(
1276 r#" 843 r#"
1277 struct A { pub b: B } 844struct A { pub b: B }
1278 struct B { pub c: C } 845struct B { pub c: C }
1279 struct C(pub bool); 846struct C(pub bool);
1280 struct D; 847struct D;
1281 848
1282 impl D { 849impl D {
1283 fn foo(&self) -> i32 { 42 } 850 fn foo(&self) -> i32 { 42 }
1284 } 851}
1285 852
1286 fn main() { 853fn main() {
1287 let x = A { b: B { c: C(true) } } 854 let x = A { b: B { c: C(true) } }
1288 .b 855 .b
1289 .c 856 .c
1290 .0; 857 .0;
1291 let x = D 858 let x = D
1292 .foo(); 859 .foo();
1293 }"#, 860}"#,
861 InlayHintsConfig {
862 parameter_hints: false,
863 type_hints: false,
864 chaining_hints: true,
865 max_length: None,
866 },
867 expect![[r#"
868 [
869 InlayHint {
870 range: 143..190,
871 kind: ChainingHint,
872 label: "C",
873 },
874 InlayHint {
875 range: 143..179,
876 kind: ChainingHint,
877 label: "B",
878 },
879 ]
880 "#]],
1294 ); 881 );
1295 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"
1296 [
1297 InlayHint {
1298 range: 143..190,
1299 kind: ChainingHint,
1300 label: "C",
1301 },
1302 InlayHint {
1303 range: 143..179,
1304 kind: ChainingHint,
1305 label: "B",
1306 },
1307 ]
1308 "###);
1309 } 882 }
1310 883
1311 #[test] 884 #[test]
1312 fn generic_chaining_hints() { 885 fn generic_chaining_hints() {
1313 let (analysis, file_id) = single_file( 886 check_expect(
1314 r#" 887 r#"
1315 struct A<T>(T); 888struct A<T>(T);
1316 struct B<T>(T); 889struct B<T>(T);
1317 struct C<T>(T); 890struct C<T>(T);
1318 struct X<T,R>(T, R); 891struct X<T,R>(T, R);
1319 892
1320 impl<T> A<T> { 893impl<T> A<T> {
1321 fn new(t: T) -> Self { A(t) } 894 fn new(t: T) -> Self { A(t) }
1322 fn into_b(self) -> B<T> { B(self.0) } 895 fn into_b(self) -> B<T> { B(self.0) }
1323 } 896}
1324 impl<T> B<T> { 897impl<T> B<T> {
1325 fn into_c(self) -> C<T> { C(self.0) } 898 fn into_c(self) -> C<T> { C(self.0) }
1326 } 899}
1327 fn main() { 900fn main() {
1328 let c = A::new(X(42, true)) 901 let c = A::new(X(42, true))
1329 .into_b() 902 .into_b()
1330 .into_c(); 903 .into_c();
1331 }"#, 904}
905"#,
906 InlayHintsConfig {
907 parameter_hints: false,
908 type_hints: false,
909 chaining_hints: true,
910 max_length: None,
911 },
912 expect![[r#"
913 [
914 InlayHint {
915 range: 246..283,
916 kind: ChainingHint,
917 label: "B<X<i32, bool>>",
918 },
919 InlayHint {
920 range: 246..265,
921 kind: ChainingHint,
922 label: "A<X<i32, bool>>",
923 },
924 ]
925 "#]],
1332 ); 926 );
1333 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"
1334 [
1335 InlayHint {
1336 range: 246..283,
1337 kind: ChainingHint,
1338 label: "B<X<i32, bool>>",
1339 },
1340 InlayHint {
1341 range: 246..265,
1342 kind: ChainingHint,
1343 label: "A<X<i32, bool>>",
1344 },
1345 ]
1346 "###);
1347 } 927 }
1348} 928}
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index ecac5134e..8660278f1 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -75,7 +75,7 @@ pub use crate::{
75 }, 75 },
76}; 76};
77 77
78pub use hir::Documentation; 78pub use hir::{Documentation, Semantics};
79pub use ra_assists::{Assist, AssistConfig, AssistId, ResolvedAssist}; 79pub use ra_assists::{Assist, AssistConfig, AssistId, ResolvedAssist};
80pub use ra_db::{ 80pub use ra_db::{
81 Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRoot, 81 Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRoot,
@@ -385,7 +385,9 @@ impl Analysis {
385 position: FilePosition, 385 position: FilePosition,
386 search_scope: Option<SearchScope>, 386 search_scope: Option<SearchScope>,
387 ) -> Cancelable<Option<ReferenceSearchResult>> { 387 ) -> Cancelable<Option<ReferenceSearchResult>> {
388 self.with_db(|db| references::find_all_refs(db, position, search_scope).map(|it| it.info)) 388 self.with_db(|db| {
389 references::find_all_refs(&Semantics::new(db), position, search_scope).map(|it| it.info)
390 })
389 } 391 }
390 392
391 /// Returns a short text describing element at position. 393 /// Returns a short text describing element at position.
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs
index 889b84c59..a393d3dba 100644
--- a/crates/ra_ide/src/mock_analysis.rs
+++ b/crates/ra_ide/src/mock_analysis.rs
@@ -3,7 +3,9 @@ use std::sync::Arc;
3 3
4use ra_cfg::CfgOptions; 4use ra_cfg::CfgOptions;
5use ra_db::{CrateName, Env, FileSet, SourceRoot, VfsPath}; 5use ra_db::{CrateName, Env, FileSet, SourceRoot, VfsPath};
6use test_utils::{extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER}; 6use test_utils::{
7 extract_annotations, extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER,
8};
7 9
8use crate::{ 10use crate::{
9 Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange, 11 Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange,
@@ -77,6 +79,24 @@ impl MockAnalysis {
77 .expect("no file in this mock"); 79 .expect("no file in this mock");
78 FileId(idx as u32 + 1) 80 FileId(idx as u32 + 1)
79 } 81 }
82 pub fn annotations(&self) -> Vec<(FileRange, String)> {
83 self.files
84 .iter()
85 .enumerate()
86 .flat_map(|(idx, fixture)| {
87 let file_id = FileId(idx as u32 + 1);
88 let annotations = extract_annotations(&fixture.text);
89 annotations
90 .into_iter()
91 .map(move |(range, data)| (FileRange { file_id, range }, data))
92 })
93 .collect()
94 }
95 pub fn annotation(&self) -> (FileRange, String) {
96 let mut all = self.annotations();
97 assert_eq!(all.len(), 1);
98 all.pop().unwrap()
99 }
80 pub fn analysis_host(self) -> AnalysisHost { 100 pub fn analysis_host(self) -> AnalysisHost {
81 let mut host = AnalysisHost::default(); 101 let mut host = AnalysisHost::default();
82 let mut change = AnalysisChange::new(); 102 let mut change = AnalysisChange::new();
@@ -110,7 +130,7 @@ impl MockAnalysis {
110 let other_crate = crate_graph.add_crate_root( 130 let other_crate = crate_graph.add_crate_root(
111 file_id, 131 file_id,
112 edition, 132 edition,
113 Some(CrateName::new(crate_name).unwrap()), 133 Some(crate_name.to_string()),
114 cfg, 134 cfg,
115 env, 135 env,
116 Default::default(), 136 Default::default(),
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index 3433fdae3..c2b0d5efe 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -86,12 +86,11 @@ impl IntoIterator for ReferenceSearchResult {
86} 86}
87 87
88pub(crate) fn find_all_refs( 88pub(crate) fn find_all_refs(
89 db: &RootDatabase, 89 sema: &Semantics<RootDatabase>,
90 position: FilePosition, 90 position: FilePosition,
91 search_scope: Option<SearchScope>, 91 search_scope: Option<SearchScope>,
92) -> Option<RangeInfo<ReferenceSearchResult>> { 92) -> Option<RangeInfo<ReferenceSearchResult>> {
93 let _p = profile("find_all_refs"); 93 let _p = profile("find_all_refs");
94 let sema = Semantics::new(db);
95 let syntax = sema.parse(position.file_id).syntax().clone(); 94 let syntax = sema.parse(position.file_id).syntax().clone();
96 95
97 let (opt_name, search_kind) = if let Some(name) = 96 let (opt_name, search_kind) = if let Some(name) =
@@ -108,15 +107,15 @@ pub(crate) fn find_all_refs(
108 let RangeInfo { range, info: def } = find_name(&sema, &syntax, position, opt_name)?; 107 let RangeInfo { range, info: def } = find_name(&sema, &syntax, position, opt_name)?;
109 108
110 let references = def 109 let references = def
111 .find_usages(db, search_scope) 110 .find_usages(sema, search_scope)
112 .into_iter() 111 .into_iter()
113 .filter(|r| search_kind == ReferenceKind::Other || search_kind == r.kind) 112 .filter(|r| search_kind == ReferenceKind::Other || search_kind == r.kind)
114 .collect(); 113 .collect();
115 114
116 let decl_range = def.try_to_nav(db)?.range(); 115 let decl_range = def.try_to_nav(sema.db)?.range();
117 116
118 let declaration = Declaration { 117 let declaration = Declaration {
119 nav: def.try_to_nav(db)?, 118 nav: def.try_to_nav(sema.db)?,
120 kind: ReferenceKind::Other, 119 kind: ReferenceKind::Other,
121 access: decl_access(&def, &syntax, decl_range), 120 access: decl_access(&def, &syntax, decl_range),
122 }; 121 };
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs
index 7ebc0adcf..b6a2266b4 100644
--- a/crates/ra_ide/src/references/rename.rs
+++ b/crates/ra_ide/src/references/rename.rs
@@ -24,23 +24,24 @@ pub(crate) fn rename(
24 position: FilePosition, 24 position: FilePosition,
25 new_name: &str, 25 new_name: &str,
26) -> Option<RangeInfo<SourceChange>> { 26) -> Option<RangeInfo<SourceChange>> {
27 let sema = Semantics::new(db);
28
27 match lex_single_valid_syntax_kind(new_name)? { 29 match lex_single_valid_syntax_kind(new_name)? {
28 SyntaxKind::IDENT | SyntaxKind::UNDERSCORE => (), 30 SyntaxKind::IDENT | SyntaxKind::UNDERSCORE => (),
29 SyntaxKind::SELF_KW => return rename_to_self(db, position), 31 SyntaxKind::SELF_KW => return rename_to_self(&sema, position),
30 _ => return None, 32 _ => return None,
31 } 33 }
32 34
33 let sema = Semantics::new(db);
34 let source_file = sema.parse(position.file_id); 35 let source_file = sema.parse(position.file_id);
35 let syntax = source_file.syntax(); 36 let syntax = source_file.syntax();
36 if let Some(module) = find_module_at_offset(&sema, position, syntax) { 37 if let Some(module) = find_module_at_offset(&sema, position, syntax) {
37 rename_mod(db, position, module, new_name) 38 rename_mod(&sema, position, module, new_name)
38 } else if let Some(self_token) = 39 } else if let Some(self_token) =
39 syntax.token_at_offset(position.offset).find(|t| t.kind() == SyntaxKind::SELF_KW) 40 syntax.token_at_offset(position.offset).find(|t| t.kind() == SyntaxKind::SELF_KW)
40 { 41 {
41 rename_self_to_param(db, position, self_token, new_name) 42 rename_self_to_param(&sema, position, self_token, new_name)
42 } else { 43 } else {
43 rename_reference(sema.db, position, new_name) 44 rename_reference(&sema, position, new_name)
44 } 45 }
45} 46}
46 47
@@ -97,7 +98,7 @@ fn source_edit_from_reference(reference: Reference, new_name: &str) -> SourceFil
97} 98}
98 99
99fn rename_mod( 100fn rename_mod(
100 db: &RootDatabase, 101 sema: &Semantics<RootDatabase>,
101 position: FilePosition, 102 position: FilePosition,
102 module: Module, 103 module: Module,
103 new_name: &str, 104 new_name: &str,
@@ -105,12 +106,12 @@ fn rename_mod(
105 let mut source_file_edits = Vec::new(); 106 let mut source_file_edits = Vec::new();
106 let mut file_system_edits = Vec::new(); 107 let mut file_system_edits = Vec::new();
107 108
108 let src = module.definition_source(db); 109 let src = module.definition_source(sema.db);
109 let file_id = src.file_id.original_file(db); 110 let file_id = src.file_id.original_file(sema.db);
110 match src.value { 111 match src.value {
111 ModuleSource::SourceFile(..) => { 112 ModuleSource::SourceFile(..) => {
112 // mod is defined in path/to/dir/mod.rs 113 // mod is defined in path/to/dir/mod.rs
113 let dst = if module.is_mod_rs(db) { 114 let dst = if module.is_mod_rs(sema.db) {
114 format!("../{}/mod.rs", new_name) 115 format!("../{}/mod.rs", new_name)
115 } else { 116 } else {
116 format!("{}.rs", new_name) 117 format!("{}.rs", new_name)
@@ -122,17 +123,17 @@ fn rename_mod(
122 ModuleSource::Module(..) => {} 123 ModuleSource::Module(..) => {}
123 } 124 }
124 125
125 if let Some(src) = module.declaration_source(db) { 126 if let Some(src) = module.declaration_source(sema.db) {
126 let file_id = src.file_id.original_file(db); 127 let file_id = src.file_id.original_file(sema.db);
127 let name = src.value.name()?; 128 let name = src.value.name()?;
128 let edit = SourceFileEdit { 129 let edit = SourceFileEdit {
129 file_id: file_id, 130 file_id,
130 edit: TextEdit::replace(name.syntax().text_range(), new_name.into()), 131 edit: TextEdit::replace(name.syntax().text_range(), new_name.into()),
131 }; 132 };
132 source_file_edits.push(edit); 133 source_file_edits.push(edit);
133 } 134 }
134 135
135 let RangeInfo { range, info: refs } = find_all_refs(db, position, None)?; 136 let RangeInfo { range, info: refs } = find_all_refs(sema, position, None)?;
136 let ref_edits = refs 137 let ref_edits = refs
137 .references 138 .references
138 .into_iter() 139 .into_iter()
@@ -142,8 +143,10 @@ fn rename_mod(
142 Some(RangeInfo::new(range, SourceChange::from_edits(source_file_edits, file_system_edits))) 143 Some(RangeInfo::new(range, SourceChange::from_edits(source_file_edits, file_system_edits)))
143} 144}
144 145
145fn rename_to_self(db: &RootDatabase, position: FilePosition) -> Option<RangeInfo<SourceChange>> { 146fn rename_to_self(
146 let sema = Semantics::new(db); 147 sema: &Semantics<RootDatabase>,
148 position: FilePosition,
149) -> Option<RangeInfo<SourceChange>> {
147 let source_file = sema.parse(position.file_id); 150 let source_file = sema.parse(position.file_id);
148 let syn = source_file.syntax(); 151 let syn = source_file.syntax();
149 152
@@ -158,7 +161,7 @@ fn rename_to_self(db: &RootDatabase, position: FilePosition) -> Option<RangeInfo
158 _ => return None, // not renaming other types 161 _ => return None, // not renaming other types
159 }; 162 };
160 163
161 let RangeInfo { range, info: refs } = find_all_refs(db, position, None)?; 164 let RangeInfo { range, info: refs } = find_all_refs(sema, position, None)?;
162 165
163 let param_range = first_param.syntax().text_range(); 166 let param_range = first_param.syntax().text_range();
164 let (param_ref, usages): (Vec<Reference>, Vec<Reference>) = refs 167 let (param_ref, usages): (Vec<Reference>, Vec<Reference>) = refs
@@ -210,16 +213,15 @@ fn text_edit_from_self_param(
210} 213}
211 214
212fn rename_self_to_param( 215fn rename_self_to_param(
213 db: &RootDatabase, 216 sema: &Semantics<RootDatabase>,
214 position: FilePosition, 217 position: FilePosition,
215 self_token: SyntaxToken, 218 self_token: SyntaxToken,
216 new_name: &str, 219 new_name: &str,
217) -> Option<RangeInfo<SourceChange>> { 220) -> Option<RangeInfo<SourceChange>> {
218 let sema = Semantics::new(db);
219 let source_file = sema.parse(position.file_id); 221 let source_file = sema.parse(position.file_id);
220 let syn = source_file.syntax(); 222 let syn = source_file.syntax();
221 223
222 let text = db.file_text(position.file_id); 224 let text = sema.db.file_text(position.file_id);
223 let fn_def = find_node_at_offset::<ast::FnDef>(syn, position.offset)?; 225 let fn_def = find_node_at_offset::<ast::FnDef>(syn, position.offset)?;
224 let search_range = fn_def.syntax().text_range(); 226 let search_range = fn_def.syntax().text_range();
225 227
@@ -249,11 +251,11 @@ fn rename_self_to_param(
249} 251}
250 252
251fn rename_reference( 253fn rename_reference(
252 db: &RootDatabase, 254 sema: &Semantics<RootDatabase>,
253 position: FilePosition, 255 position: FilePosition,
254 new_name: &str, 256 new_name: &str,
255) -> Option<RangeInfo<SourceChange>> { 257) -> Option<RangeInfo<SourceChange>> {
256 let RangeInfo { range, info: refs } = find_all_refs(db, position, None)?; 258 let RangeInfo { range, info: refs } = find_all_refs(sema, position, None)?;
257 259
258 let edit = refs 260 let edit = refs
259 .into_iter() 261 .into_iter()
diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs
index f569a3f17..ed15d6494 100644
--- a/crates/ra_ide/src/runnables.rs
+++ b/crates/ra_ide/src/runnables.rs
@@ -251,13 +251,21 @@ fn runnable_mod(
251 251
252#[cfg(test)] 252#[cfg(test)]
253mod tests { 253mod tests {
254 use insta::assert_debug_snapshot; 254 use expect::{expect, Expect};
255 255
256 use crate::mock_analysis::analysis_and_position; 256 use crate::mock_analysis::analysis_and_position;
257 257
258 use super::{Runnable, RunnableAction, BENCH, BIN, DOCTEST, TEST}; 258 use super::{RunnableAction, BENCH, BIN, DOCTEST, TEST};
259 259
260 fn assert_actions(runnables: &[Runnable], actions: &[&RunnableAction]) { 260 fn check(
261 ra_fixture: &str,
262 // FIXME: fold this into `expect` as well
263 actions: &[&RunnableAction],
264 expect: Expect,
265 ) {
266 let (analysis, position) = analysis_and_position(ra_fixture);
267 let runnables = analysis.runnables(position.file_id).unwrap();
268 expect.assert_debug_eq(&runnables);
261 assert_eq!( 269 assert_eq!(
262 actions, 270 actions,
263 runnables.into_iter().map(|it| it.action()).collect::<Vec<_>>().as_slice() 271 runnables.into_iter().map(|it| it.action()).collect::<Vec<_>>().as_slice()
@@ -266,579 +274,557 @@ mod tests {
266 274
267 #[test] 275 #[test]
268 fn test_runnables() { 276 fn test_runnables() {
269 let (analysis, pos) = analysis_and_position( 277 check(
270 r#" 278 r#"
271 //- /lib.rs 279//- /lib.rs
272 <|> //empty 280<|>
273 fn main() {} 281fn main() {}
274 282
275 #[test] 283#[test]
276 fn test_foo() {} 284fn test_foo() {}
277 285
278 #[test] 286#[test]
279 #[ignore] 287#[ignore]
280 fn test_foo() {} 288fn test_foo() {}
281 289
282 #[bench] 290#[bench]
283 fn bench() {} 291fn bench() {}
284 "#, 292"#,
285 ); 293 &[&BIN, &TEST, &TEST, &BENCH],
286 let runnables = analysis.runnables(pos.file_id).unwrap(); 294 expect![[r#"
287 assert_debug_snapshot!(&runnables, 295 [
288 @r###" 296 Runnable {
289 [ 297 nav: NavigationTarget {
290 Runnable { 298 file_id: FileId(
291 nav: NavigationTarget { 299 1,
292 file_id: FileId( 300 ),
293 1, 301 full_range: 1..13,
294 ), 302 name: "main",
295 full_range: 1..21, 303 kind: FN_DEF,
296 name: "main", 304 focus_range: Some(
297 kind: FN_DEF, 305 4..8,
298 focus_range: Some( 306 ),
299 12..16, 307 container_name: None,
300 ), 308 description: None,
301 container_name: None, 309 docs: None,
302 description: None, 310 },
303 docs: None, 311 kind: Bin,
304 }, 312 cfg_exprs: [],
305 kind: Bin,
306 cfg_exprs: [],
307 },
308 Runnable {
309 nav: NavigationTarget {
310 file_id: FileId(
311 1,
312 ),
313 full_range: 23..47,
314 name: "test_foo",
315 kind: FN_DEF,
316 focus_range: Some(
317 34..42,
318 ),
319 container_name: None,
320 description: None,
321 docs: None,
322 },
323 kind: Test {
324 test_id: Path(
325 "test_foo",
326 ),
327 attr: TestAttr {
328 ignore: false,
329 }, 313 },
330 }, 314 Runnable {
331 cfg_exprs: [], 315 nav: NavigationTarget {
332 }, 316 file_id: FileId(
333 Runnable { 317 1,
334 nav: NavigationTarget { 318 ),
335 file_id: FileId( 319 full_range: 15..39,
336 1, 320 name: "test_foo",
337 ), 321 kind: FN_DEF,
338 full_range: 49..83, 322 focus_range: Some(
339 name: "test_foo", 323 26..34,
340 kind: FN_DEF, 324 ),
341 focus_range: Some( 325 container_name: None,
342 70..78, 326 description: None,
343 ), 327 docs: None,
344 container_name: None, 328 },
345 description: None, 329 kind: Test {
346 docs: None, 330 test_id: Path(
347 }, 331 "test_foo",
348 kind: Test { 332 ),
349 test_id: Path( 333 attr: TestAttr {
350 "test_foo", 334 ignore: false,
351 ), 335 },
352 attr: TestAttr { 336 },
353 ignore: true, 337 cfg_exprs: [],
338 },
339 Runnable {
340 nav: NavigationTarget {
341 file_id: FileId(
342 1,
343 ),
344 full_range: 41..75,
345 name: "test_foo",
346 kind: FN_DEF,
347 focus_range: Some(
348 62..70,
349 ),
350 container_name: None,
351 description: None,
352 docs: None,
353 },
354 kind: Test {
355 test_id: Path(
356 "test_foo",
357 ),
358 attr: TestAttr {
359 ignore: true,
360 },
361 },
362 cfg_exprs: [],
354 }, 363 },
355 }, 364 Runnable {
356 cfg_exprs: [], 365 nav: NavigationTarget {
357 }, 366 file_id: FileId(
358 Runnable { 367 1,
359 nav: NavigationTarget { 368 ),
360 file_id: FileId( 369 full_range: 77..99,
361 1, 370 name: "bench",
362 ), 371 kind: FN_DEF,
363 full_range: 85..107, 372 focus_range: Some(
364 name: "bench", 373 89..94,
365 kind: FN_DEF, 374 ),
366 focus_range: Some( 375 container_name: None,
367 97..102, 376 description: None,
368 ), 377 docs: None,
369 container_name: None, 378 },
370 description: None, 379 kind: Bench {
371 docs: None, 380 test_id: Path(
372 }, 381 "bench",
373 kind: Bench { 382 ),
374 test_id: Path( 383 },
375 "bench", 384 cfg_exprs: [],
376 ), 385 },
377 }, 386 ]
378 cfg_exprs: [], 387 "#]],
379 }, 388 );
380 ]
381 "###
382 );
383 assert_actions(&runnables, &[&BIN, &TEST, &TEST, &BENCH]);
384 } 389 }
385 390
386 #[test] 391 #[test]
387 fn test_runnables_doc_test() { 392 fn test_runnables_doc_test() {
388 let (analysis, pos) = analysis_and_position( 393 check(
389 r#" 394 r#"
390 //- /lib.rs 395//- /lib.rs
391 <|> //empty 396<|>
392 fn main() {} 397fn main() {}
393 398
394 /// ``` 399/// ```
395 /// let x = 5; 400/// let x = 5;
396 /// ``` 401/// ```
397 fn foo() {} 402fn foo() {}
398 "#, 403"#,
404 &[&BIN, &DOCTEST],
405 expect![[r#"
406 [
407 Runnable {
408 nav: NavigationTarget {
409 file_id: FileId(
410 1,
411 ),
412 full_range: 1..13,
413 name: "main",
414 kind: FN_DEF,
415 focus_range: Some(
416 4..8,
417 ),
418 container_name: None,
419 description: None,
420 docs: None,
421 },
422 kind: Bin,
423 cfg_exprs: [],
424 },
425 Runnable {
426 nav: NavigationTarget {
427 file_id: FileId(
428 1,
429 ),
430 full_range: 15..57,
431 name: "foo",
432 kind: FN_DEF,
433 focus_range: None,
434 container_name: None,
435 description: None,
436 docs: None,
437 },
438 kind: DocTest {
439 test_id: Path(
440 "foo",
441 ),
442 },
443 cfg_exprs: [],
444 },
445 ]
446 "#]],
399 ); 447 );
400 let runnables = analysis.runnables(pos.file_id).unwrap();
401 assert_debug_snapshot!(&runnables,
402 @r###"
403 [
404 Runnable {
405 nav: NavigationTarget {
406 file_id: FileId(
407 1,
408 ),
409 full_range: 1..21,
410 name: "main",
411 kind: FN_DEF,
412 focus_range: Some(
413 12..16,
414 ),
415 container_name: None,
416 description: None,
417 docs: None,
418 },
419 kind: Bin,
420 cfg_exprs: [],
421 },
422 Runnable {
423 nav: NavigationTarget {
424 file_id: FileId(
425 1,
426 ),
427 full_range: 23..65,
428 name: "foo",
429 kind: FN_DEF,
430 focus_range: None,
431 container_name: None,
432 description: None,
433 docs: None,
434 },
435 kind: DocTest {
436 test_id: Path(
437 "foo",
438 ),
439 },
440 cfg_exprs: [],
441 },
442 ]
443 "###
444 );
445 assert_actions(&runnables, &[&BIN, &DOCTEST]);
446 } 448 }
447 449
448 #[test] 450 #[test]
449 fn test_runnables_doc_test_in_impl() { 451 fn test_runnables_doc_test_in_impl() {
450 let (analysis, pos) = analysis_and_position( 452 check(
451 r#" 453 r#"
452 //- /lib.rs 454//- /lib.rs
453 <|> //empty 455<|>
454 fn main() {} 456fn main() {}
455 457
456 struct Data; 458struct Data;
457 impl Data { 459impl Data {
458 /// ``` 460 /// ```
459 /// let x = 5; 461 /// let x = 5;
460 /// ``` 462 /// ```
461 fn foo() {} 463 fn foo() {}
462 } 464}
463 "#, 465"#,
466 &[&BIN, &DOCTEST],
467 expect![[r#"
468 [
469 Runnable {
470 nav: NavigationTarget {
471 file_id: FileId(
472 1,
473 ),
474 full_range: 1..13,
475 name: "main",
476 kind: FN_DEF,
477 focus_range: Some(
478 4..8,
479 ),
480 container_name: None,
481 description: None,
482 docs: None,
483 },
484 kind: Bin,
485 cfg_exprs: [],
486 },
487 Runnable {
488 nav: NavigationTarget {
489 file_id: FileId(
490 1,
491 ),
492 full_range: 44..98,
493 name: "foo",
494 kind: FN_DEF,
495 focus_range: None,
496 container_name: None,
497 description: None,
498 docs: None,
499 },
500 kind: DocTest {
501 test_id: Path(
502 "Data::foo",
503 ),
504 },
505 cfg_exprs: [],
506 },
507 ]
508 "#]],
464 ); 509 );
465 let runnables = analysis.runnables(pos.file_id).unwrap();
466 assert_debug_snapshot!(&runnables,
467 @r###"
468 [
469 Runnable {
470 nav: NavigationTarget {
471 file_id: FileId(
472 1,
473 ),
474 full_range: 1..21,
475 name: "main",
476 kind: FN_DEF,
477 focus_range: Some(
478 12..16,
479 ),
480 container_name: None,
481 description: None,
482 docs: None,
483 },
484 kind: Bin,
485 cfg_exprs: [],
486 },
487 Runnable {
488 nav: NavigationTarget {
489 file_id: FileId(
490 1,
491 ),
492 full_range: 52..106,
493 name: "foo",
494 kind: FN_DEF,
495 focus_range: None,
496 container_name: None,
497 description: None,
498 docs: None,
499 },
500 kind: DocTest {
501 test_id: Path(
502 "Data::foo",
503 ),
504 },
505 cfg_exprs: [],
506 },
507 ]
508 "###
509 );
510 assert_actions(&runnables, &[&BIN, &DOCTEST]);
511 } 510 }
512 511
513 #[test] 512 #[test]
514 fn test_runnables_module() { 513 fn test_runnables_module() {
515 let (analysis, pos) = analysis_and_position( 514 check(
516 r#" 515 r#"
517 //- /lib.rs 516//- /lib.rs
518 <|> //empty 517<|>
519 mod test_mod { 518mod test_mod {
520 #[test] 519 #[test]
521 fn test_foo1() {} 520 fn test_foo1() {}
522 } 521}
523 "#, 522"#,
524 ); 523 &[&TEST, &TEST],
525 let runnables = analysis.runnables(pos.file_id).unwrap(); 524 expect![[r#"
526 assert_debug_snapshot!(&runnables, 525 [
527 @r###" 526 Runnable {
528 [ 527 nav: NavigationTarget {
529 Runnable { 528 file_id: FileId(
530 nav: NavigationTarget { 529 1,
531 file_id: FileId( 530 ),
532 1, 531 full_range: 1..51,
533 ), 532 name: "test_mod",
534 full_range: 1..59, 533 kind: MODULE,
535 name: "test_mod", 534 focus_range: Some(
536 kind: MODULE, 535 5..13,
537 focus_range: Some( 536 ),
538 13..21, 537 container_name: None,
539 ), 538 description: None,
540 container_name: None, 539 docs: None,
541 description: None, 540 },
542 docs: None, 541 kind: TestMod {
543 }, 542 path: "test_mod",
544 kind: TestMod { 543 },
545 path: "test_mod", 544 cfg_exprs: [],
546 }, 545 },
547 cfg_exprs: [], 546 Runnable {
548 }, 547 nav: NavigationTarget {
549 Runnable { 548 file_id: FileId(
550 nav: NavigationTarget { 549 1,
551 file_id: FileId( 550 ),
552 1, 551 full_range: 20..49,
553 ), 552 name: "test_foo1",
554 full_range: 28..57, 553 kind: FN_DEF,
555 name: "test_foo1", 554 focus_range: Some(
556 kind: FN_DEF, 555 35..44,
557 focus_range: Some( 556 ),
558 43..52, 557 container_name: None,
559 ), 558 description: None,
560 container_name: None, 559 docs: None,
561 description: None, 560 },
562 docs: None, 561 kind: Test {
563 }, 562 test_id: Path(
564 kind: Test { 563 "test_mod::test_foo1",
565 test_id: Path( 564 ),
566 "test_mod::test_foo1", 565 attr: TestAttr {
567 ), 566 ignore: false,
568 attr: TestAttr { 567 },
569 ignore: false, 568 },
569 cfg_exprs: [],
570 }, 570 },
571 }, 571 ]
572 cfg_exprs: [], 572 "#]],
573 }, 573 );
574 ]
575 "###
576 );
577 assert_actions(&runnables, &[&TEST, &TEST]);
578 } 574 }
579 575
580 #[test] 576 #[test]
581 fn test_runnables_one_depth_layer_module() { 577 fn test_runnables_one_depth_layer_module() {
582 let (analysis, pos) = analysis_and_position( 578 check(
583 r#" 579 r#"
584 //- /lib.rs 580//- /lib.rs
585 <|> //empty 581<|>
586 mod foo { 582mod foo {
587 mod test_mod { 583 mod test_mod {
588 #[test] 584 #[test]
589 fn test_foo1() {} 585 fn test_foo1() {}
590 } 586 }
591 } 587}
592 "#, 588"#,
593 ); 589 &[&TEST, &TEST],
594 let runnables = analysis.runnables(pos.file_id).unwrap(); 590 expect![[r#"
595 assert_debug_snapshot!(&runnables, 591 [
596 @r###" 592 Runnable {
597 [ 593 nav: NavigationTarget {
598 Runnable { 594 file_id: FileId(
599 nav: NavigationTarget { 595 1,
600 file_id: FileId( 596 ),
601 1, 597 full_range: 15..77,
602 ), 598 name: "test_mod",
603 full_range: 23..85, 599 kind: MODULE,
604 name: "test_mod", 600 focus_range: Some(
605 kind: MODULE, 601 19..27,
606 focus_range: Some( 602 ),
607 27..35, 603 container_name: None,
608 ), 604 description: None,
609 container_name: None, 605 docs: None,
610 description: None, 606 },
611 docs: None, 607 kind: TestMod {
612 }, 608 path: "foo::test_mod",
613 kind: TestMod { 609 },
614 path: "foo::test_mod", 610 cfg_exprs: [],
615 }, 611 },
616 cfg_exprs: [], 612 Runnable {
617 }, 613 nav: NavigationTarget {
618 Runnable { 614 file_id: FileId(
619 nav: NavigationTarget { 615 1,
620 file_id: FileId( 616 ),
621 1, 617 full_range: 38..71,
622 ), 618 name: "test_foo1",
623 full_range: 46..79, 619 kind: FN_DEF,
624 name: "test_foo1", 620 focus_range: Some(
625 kind: FN_DEF, 621 57..66,
626 focus_range: Some( 622 ),
627 65..74, 623 container_name: None,
628 ), 624 description: None,
629 container_name: None, 625 docs: None,
630 description: None, 626 },
631 docs: None, 627 kind: Test {
632 }, 628 test_id: Path(
633 kind: Test { 629 "foo::test_mod::test_foo1",
634 test_id: Path( 630 ),
635 "foo::test_mod::test_foo1", 631 attr: TestAttr {
636 ), 632 ignore: false,
637 attr: TestAttr { 633 },
638 ignore: false, 634 },
635 cfg_exprs: [],
639 }, 636 },
640 }, 637 ]
641 cfg_exprs: [], 638 "#]],
642 }, 639 );
643 ]
644 "###
645 );
646 assert_actions(&runnables, &[&TEST, &TEST]);
647 } 640 }
648 641
649 #[test] 642 #[test]
650 fn test_runnables_multiple_depth_module() { 643 fn test_runnables_multiple_depth_module() {
651 let (analysis, pos) = analysis_and_position( 644 check(
652 r#" 645 r#"
653 //- /lib.rs 646//- /lib.rs
654 <|> //empty 647<|>
655 mod foo { 648mod foo {
656 mod bar { 649 mod bar {
657 mod test_mod { 650 mod test_mod {
658 #[test] 651 #[test]
659 fn test_foo1() {} 652 fn test_foo1() {}
660 }
661 }
662 } 653 }
663 "#, 654 }
664 ); 655}
665 let runnables = analysis.runnables(pos.file_id).unwrap(); 656"#,
666 assert_debug_snapshot!(&runnables, 657 &[&TEST, &TEST],
667 @r###" 658 expect![[r#"
668 [ 659 [
669 Runnable { 660 Runnable {
670 nav: NavigationTarget { 661 nav: NavigationTarget {
671 file_id: FileId( 662 file_id: FileId(
672 1, 663 1,
673 ), 664 ),
674 full_range: 41..115, 665 full_range: 33..107,
675 name: "test_mod", 666 name: "test_mod",
676 kind: MODULE, 667 kind: MODULE,
677 focus_range: Some( 668 focus_range: Some(
678 45..53, 669 37..45,
679 ), 670 ),
680 container_name: None, 671 container_name: None,
681 description: None, 672 description: None,
682 docs: None, 673 docs: None,
683 }, 674 },
684 kind: TestMod { 675 kind: TestMod {
685 path: "foo::bar::test_mod", 676 path: "foo::bar::test_mod",
686 }, 677 },
687 cfg_exprs: [], 678 cfg_exprs: [],
688 }, 679 },
689 Runnable { 680 Runnable {
690 nav: NavigationTarget { 681 nav: NavigationTarget {
691 file_id: FileId( 682 file_id: FileId(
692 1, 683 1,
693 ), 684 ),
694 full_range: 68..105, 685 full_range: 60..97,
695 name: "test_foo1", 686 name: "test_foo1",
696 kind: FN_DEF, 687 kind: FN_DEF,
697 focus_range: Some( 688 focus_range: Some(
698 91..100, 689 83..92,
699 ), 690 ),
700 container_name: None, 691 container_name: None,
701 description: None, 692 description: None,
702 docs: None, 693 docs: None,
703 }, 694 },
704 kind: Test { 695 kind: Test {
705 test_id: Path( 696 test_id: Path(
706 "foo::bar::test_mod::test_foo1", 697 "foo::bar::test_mod::test_foo1",
707 ), 698 ),
708 attr: TestAttr { 699 attr: TestAttr {
709 ignore: false, 700 ignore: false,
701 },
702 },
703 cfg_exprs: [],
710 }, 704 },
711 }, 705 ]
712 cfg_exprs: [], 706 "#]],
713 }, 707 );
714 ]
715 "###
716 );
717 assert_actions(&runnables, &[&TEST, &TEST]);
718 } 708 }
719 709
720 #[test] 710 #[test]
721 fn test_runnables_with_feature() { 711 fn test_runnables_with_feature() {
722 let (analysis, pos) = analysis_and_position( 712 check(
723 r#" 713 r#"
724 //- /lib.rs crate:foo cfg:feature=foo 714//- /lib.rs crate:foo cfg:feature=foo
725 <|> //empty 715<|>
726 #[test] 716#[test]
727 #[cfg(feature = "foo")] 717#[cfg(feature = "foo")]
728 fn test_foo1() {} 718fn test_foo1() {}
729 "#, 719"#,
730 ); 720 &[&TEST],
731 let runnables = analysis.runnables(pos.file_id).unwrap(); 721 expect![[r#"
732 assert_debug_snapshot!(&runnables, 722 [
733 @r###" 723 Runnable {
734 [ 724 nav: NavigationTarget {
735 Runnable { 725 file_id: FileId(
736 nav: NavigationTarget { 726 1,
737 file_id: FileId( 727 ),
738 1, 728 full_range: 1..50,
739 ), 729 name: "test_foo1",
740 full_range: 1..58, 730 kind: FN_DEF,
741 name: "test_foo1", 731 focus_range: Some(
742 kind: FN_DEF, 732 36..45,
743 focus_range: Some( 733 ),
744 44..53, 734 container_name: None,
745 ), 735 description: None,
746 container_name: None, 736 docs: None,
747 description: None, 737 },
748 docs: None, 738 kind: Test {
749 }, 739 test_id: Path(
750 kind: Test { 740 "test_foo1",
751 test_id: Path( 741 ),
752 "test_foo1", 742 attr: TestAttr {
753 ), 743 ignore: false,
754 attr: TestAttr { 744 },
755 ignore: false, 745 },
756 }, 746 cfg_exprs: [
757 }, 747 KeyValue {
758 cfg_exprs: [ 748 key: "feature",
759 KeyValue { 749 value: "foo",
760 key: "feature", 750 },
761 value: "foo", 751 ],
762 }, 752 },
763 ], 753 ]
764 }, 754 "#]],
765 ] 755 );
766 "###
767 );
768 assert_actions(&runnables, &[&TEST]);
769 } 756 }
770 757
771 #[test] 758 #[test]
772 fn test_runnables_with_features() { 759 fn test_runnables_with_features() {
773 let (analysis, pos) = analysis_and_position( 760 check(
774 r#" 761 r#"
775 //- /lib.rs crate:foo cfg:feature=foo,feature=bar 762//- /lib.rs crate:foo cfg:feature=foo,feature=bar
776 <|> //empty 763<|>
777 #[test] 764#[test]
778 #[cfg(all(feature = "foo", feature = "bar"))] 765#[cfg(all(feature = "foo", feature = "bar"))]
779 fn test_foo1() {} 766fn test_foo1() {}
780 "#, 767"#,
781 ); 768 &[&TEST],
782 let runnables = analysis.runnables(pos.file_id).unwrap(); 769 expect![[r#"
783 assert_debug_snapshot!(&runnables, 770 [
784 @r###" 771 Runnable {
785 [ 772 nav: NavigationTarget {
786 Runnable { 773 file_id: FileId(
787 nav: NavigationTarget { 774 1,
788 file_id: FileId( 775 ),
789 1, 776 full_range: 1..72,
790 ), 777 name: "test_foo1",
791 full_range: 1..80, 778 kind: FN_DEF,
792 name: "test_foo1", 779 focus_range: Some(
793 kind: FN_DEF, 780 58..67,
794 focus_range: Some( 781 ),
795 66..75, 782 container_name: None,
796 ), 783 description: None,
797 container_name: None, 784 docs: None,
798 description: None, 785 },
799 docs: None, 786 kind: Test {
800 }, 787 test_id: Path(
801 kind: Test { 788 "test_foo1",
802 test_id: Path( 789 ),
803 "test_foo1", 790 attr: TestAttr {
804 ), 791 ignore: false,
805 attr: TestAttr {
806 ignore: false,
807 },
808 },
809 cfg_exprs: [
810 All(
811 [
812 KeyValue {
813 key: "feature",
814 value: "foo",
815 },
816 KeyValue {
817 key: "feature",
818 value: "bar",
819 }, 792 },
793 },
794 cfg_exprs: [
795 All(
796 [
797 KeyValue {
798 key: "feature",
799 value: "foo",
800 },
801 KeyValue {
802 key: "feature",
803 value: "bar",
804 },
805 ],
806 ),
820 ], 807 ],
821 ), 808 },
822 ], 809 ]
823 }, 810 "#]],
824 ] 811 );
825 "###
826 );
827 assert_actions(&runnables, &[&TEST]);
828 } 812 }
829 813
830 #[test] 814 #[test]
831 fn test_runnables_no_test_function_in_module() { 815 fn test_runnables_no_test_function_in_module() {
832 let (analysis, pos) = analysis_and_position( 816 check(
833 r#" 817 r#"
834 //- /lib.rs 818//- /lib.rs
835 <|> //empty 819<|>
836 mod test_mod { 820mod test_mod {
837 fn foo1() {} 821 fn foo1() {}
838 } 822}
839 "#, 823"#,
824 &[],
825 expect![[r#"
826 []
827 "#]],
840 ); 828 );
841 let runnables = analysis.runnables(pos.file_id).unwrap();
842 assert!(runnables.is_empty())
843 } 829 }
844} 830}
diff --git a/crates/ra_ide/src/snapshots/highlight_doctest.html b/crates/ra_ide/src/snapshots/highlight_doctest.html
deleted file mode 100644
index e8155def7..000000000
--- a/crates/ra_ide/src/snapshots/highlight_doctest.html
+++ /dev/null
@@ -1,101 +0,0 @@
1
2<style>
3body { margin: 0; }
4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
5
6.lifetime { color: #DFAF8F; font-style: italic; }
7.comment { color: #7F9F7F; }
8.documentation { color: #629755; }
9.injected { opacity: 0.65 ; }
10.struct, .enum { color: #7CB8BB; }
11.enum_variant { color: #BDE0F3; }
12.string_literal { color: #CC9393; }
13.field { color: #94BFF3; }
14.function { color: #93E0E3; }
15.function.unsafe { color: #BC8383; }
16.operator.unsafe { color: #BC8383; }
17.parameter { color: #94BFF3; }
18.text { color: #DCDCCC; }
19.type { color: #7CB8BB; }
20.builtin_type { color: #8CD0D3; }
21.type_param { color: #DFAF8F; }
22.attribute { color: #94BFF3; }
23.numeric_literal { color: #BFEBBF; }
24.bool_literal { color: #BFE6EB; }
25.macro { color: #94BFF3; }
26.module { color: #AFD8AF; }
27.variable { color: #DCDCCC; }
28.format_specifier { color: #CC696B; }
29.mutable { text-decoration: underline; }
30.unresolved_reference { color: #FC5555; }
31.escape_sequence { color: #94BFF3; }
32
33.keyword { color: #F0DFAF; font-weight: bold; }
34.keyword.unsafe { color: #BC8383; font-weight: bold; }
35.control { font-style: italic; }
36</style>
37<pre><code><span class="comment documentation">/// ```</span>
38<span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="generic injected"> _ = </span><span class="string_literal injected">"early doctests should not go boom"</span><span class="generic injected">;</span>
39<span class="comment documentation">/// ```</span>
40<span class="keyword">struct</span> <span class="struct declaration">Foo</span> {
41 <span class="field declaration">bar</span>: <span class="builtin_type">bool</span>,
42}
43
44<span class="keyword">impl</span> <span class="struct">Foo</span> {
45 <span class="keyword">pub</span> <span class="keyword">const</span> <span class="constant declaration">bar</span>: <span class="builtin_type">bool</span> = <span class="bool_literal">true</span>;
46
47 <span class="comment documentation">/// Constructs a new `Foo`.</span>
48 <span class="comment documentation">///</span>
49 <span class="comment documentation">/// # Examples</span>
50 <span class="comment documentation">///</span>
51 <span class="comment documentation">/// ```</span>
52 <span class="comment documentation">/// #</span><span class="generic injected"> </span><span class="attribute injected">#![</span><span class="function attribute injected">allow</span><span class="attribute injected">(unused_mut)]</span>
53 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="generic injected"> </span><span class="keyword injected">mut</span><span class="generic injected"> </span><span class="variable declaration injected mutable">foo</span><span class="generic injected">: </span><span class="struct injected">Foo</span><span class="generic injected"> = </span><span class="struct injected">Foo</span><span class="generic injected">::</span><span class="function injected">new</span><span class="generic injected">();</span>
54 <span class="comment documentation">/// ```</span>
55 <span class="keyword">pub</span> <span class="keyword">const</span> <span class="keyword">fn</span> <span class="function declaration">new</span>() -&gt; <span class="struct">Foo</span> {
56 <span class="struct">Foo</span> { <span class="field">bar</span>: <span class="bool_literal">true</span> }
57 }
58
59 <span class="comment documentation">/// `bar` method on `Foo`.</span>
60 <span class="comment documentation">///</span>
61 <span class="comment documentation">/// # Examples</span>
62 <span class="comment documentation">///</span>
63 <span class="comment documentation">/// ```</span>
64 <span class="comment documentation">/// </span><span class="keyword injected">use</span><span class="generic injected"> </span><span class="module injected">x</span><span class="generic injected">::</span><span class="module injected">y</span><span class="generic injected">;</span>
65 <span class="comment documentation">///</span>
66 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="generic injected"> </span><span class="variable declaration injected">foo</span><span class="generic injected"> = </span><span class="struct injected">Foo</span><span class="generic injected">::</span><span class="function injected">new</span><span class="generic injected">();</span>
67 <span class="comment documentation">///</span>
68 <span class="comment documentation">/// </span><span class="comment injected">// calls bar on foo</span>
69 <span class="comment documentation">/// </span><span class="macro injected">assert!</span><span class="generic injected">(foo.bar());</span>
70 <span class="comment documentation">///</span>
71 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="generic injected"> </span><span class="variable declaration injected">bar</span><span class="generic injected"> = </span><span class="variable injected">foo</span><span class="generic injected">.</span><span class="field injected">bar</span><span class="generic injected"> || </span><span class="struct injected">Foo</span><span class="generic injected">::</span><span class="constant injected">bar</span><span class="generic injected">;</span>
72 <span class="comment documentation">///</span>
73 <span class="comment documentation">/// </span><span class="comment injected">/* multi-line
74 </span><span class="comment documentation">/// </span><span class="comment injected"> comment */</span>
75 <span class="comment documentation">///</span>
76 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="generic injected"> </span><span class="variable declaration injected">multi_line_string</span><span class="generic injected"> = </span><span class="string_literal injected">"Foo
77 </span><span class="comment documentation">/// </span><span class="string_literal injected"> bar
78 </span><span class="comment documentation">/// </span><span class="string_literal injected"> "</span><span class="generic injected">;</span>
79 <span class="comment documentation">///</span>
80 <span class="comment documentation">/// ```</span>
81 <span class="comment documentation">///</span>
82 <span class="comment documentation">/// ```rust,no_run</span>
83 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="generic injected"> </span><span class="variable declaration injected">foobar</span><span class="generic injected"> = </span><span class="struct injected">Foo</span><span class="generic injected">::</span><span class="function injected">new</span><span class="generic injected">().</span><span class="function injected">bar</span><span class="generic injected">();</span>
84 <span class="comment documentation">/// ```</span>
85 <span class="comment documentation">///</span>
86 <span class="comment documentation">/// ```sh</span>
87 <span class="comment documentation">/// echo 1</span>
88 <span class="comment documentation">/// ```</span>
89 <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration">foo</span>(&<span class="self_keyword">self</span>) -&gt; <span class="builtin_type">bool</span> {
90 <span class="bool_literal">true</span>
91 }
92}
93
94<span class="comment documentation">/// ```</span>
95<span class="comment documentation">/// </span><span class="macro injected">noop!</span><span class="generic injected">(</span><span class="numeric_literal injected">1</span><span class="generic injected">);</span>
96<span class="comment documentation">/// ```</span>
97<span class="macro">macro_rules!</span> <span class="macro declaration">noop</span> {
98 ($expr:expr) =&gt; {
99 $expr
100 }
101}</code></pre> \ No newline at end of file
diff --git a/crates/ra_ide/src/snapshots/highlight_injection.html b/crates/ra_ide/src/snapshots/highlight_injection.html
deleted file mode 100644
index 1b0349bae..000000000
--- a/crates/ra_ide/src/snapshots/highlight_injection.html
+++ /dev/null
@@ -1,47 +0,0 @@
1
2<style>
3body { margin: 0; }
4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
5
6.lifetime { color: #DFAF8F; font-style: italic; }
7.comment { color: #7F9F7F; }
8.documentation { color: #629755; }
9.injected { opacity: 0.65 ; }
10.struct, .enum { color: #7CB8BB; }
11.enum_variant { color: #BDE0F3; }
12.string_literal { color: #CC9393; }
13.field { color: #94BFF3; }
14.function { color: #93E0E3; }
15.function.unsafe { color: #BC8383; }
16.operator.unsafe { color: #BC8383; }
17.parameter { color: #94BFF3; }
18.text { color: #DCDCCC; }
19.type { color: #7CB8BB; }
20.builtin_type { color: #8CD0D3; }
21.type_param { color: #DFAF8F; }
22.attribute { color: #94BFF3; }
23.numeric_literal { color: #BFEBBF; }
24.bool_literal { color: #BFE6EB; }
25.macro { color: #94BFF3; }
26.module { color: #AFD8AF; }
27.variable { color: #DCDCCC; }
28.format_specifier { color: #CC696B; }
29.mutable { text-decoration: underline; }
30.unresolved_reference { color: #FC5555; }
31.escape_sequence { color: #94BFF3; }
32
33.keyword { color: #F0DFAF; font-weight: bold; }
34.keyword.unsafe { color: #BC8383; font-weight: bold; }
35.control { font-style: italic; }
36</style>
37<pre><code><span class="keyword">fn</span> <span class="function declaration">fixture</span>(<span class="variable declaration">ra_fixture</span>: &<span class="builtin_type">str</span>) {}
38
39<span class="keyword">fn</span> <span class="function declaration">main</span>() {
40 <span class="function">fixture</span>(<span class="string_literal">r#"</span>
41 <span class="keyword">trait</span> <span class="trait declaration">Foo</span> {
42 <span class="keyword">fn</span> <span class="function declaration">foo</span>() {
43 <span class="macro">println!</span>(<span class="string_literal">"2 + 2 = {}"</span>, <span class="numeric_literal">4</span>);
44 }
45 }<span class="string_literal">"#</span>
46 );
47}</code></pre> \ No newline at end of file
diff --git a/crates/ra_ide/src/snapshots/highlight_strings.html b/crates/ra_ide/src/snapshots/highlight_strings.html
deleted file mode 100644
index d184b5691..000000000
--- a/crates/ra_ide/src/snapshots/highlight_strings.html
+++ /dev/null
@@ -1,95 +0,0 @@
1
2<style>
3body { margin: 0; }
4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
5
6.lifetime { color: #DFAF8F; font-style: italic; }
7.comment { color: #7F9F7F; }
8.documentation { color: #629755; }
9.injected { opacity: 0.65 ; }
10.struct, .enum { color: #7CB8BB; }
11.enum_variant { color: #BDE0F3; }
12.string_literal { color: #CC9393; }
13.field { color: #94BFF3; }
14.function { color: #93E0E3; }
15.function.unsafe { color: #BC8383; }
16.operator.unsafe { color: #BC8383; }
17.parameter { color: #94BFF3; }
18.text { color: #DCDCCC; }
19.type { color: #7CB8BB; }
20.builtin_type { color: #8CD0D3; }
21.type_param { color: #DFAF8F; }
22.attribute { color: #94BFF3; }
23.numeric_literal { color: #BFEBBF; }
24.bool_literal { color: #BFE6EB; }
25.macro { color: #94BFF3; }
26.module { color: #AFD8AF; }
27.variable { color: #DCDCCC; }
28.format_specifier { color: #CC696B; }
29.mutable { text-decoration: underline; }
30.unresolved_reference { color: #FC5555; }
31.escape_sequence { color: #94BFF3; }
32
33.keyword { color: #F0DFAF; font-weight: bold; }
34.keyword.unsafe { color: #BC8383; font-weight: bold; }
35.control { font-style: italic; }
36</style>
37<pre><code><span class="macro">macro_rules!</span> <span class="macro declaration">println</span> {
38 ($($arg:tt)*) =&gt; ({
39 $<span class="keyword">crate</span>::io::_print($<span class="keyword">crate</span>::format_args_nl!($($arg)*));
40 })
41}
42#[rustc_builtin_macro]
43<span class="macro">macro_rules!</span> <span class="macro declaration">format_args_nl</span> {
44 ($fmt:expr) =&gt; {{ <span class="comment">/* compiler built-in */</span> }};
45 ($fmt:expr, $($args:tt)*) =&gt; {{ <span class="comment">/* compiler built-in */</span> }};
46}
47
48<span class="keyword">fn</span> <span class="function declaration">main</span>() {
49 <span class="comment">// from https://doc.rust-lang.org/std/fmt/index.html</span>
50 <span class="macro">println!</span>(<span class="string_literal">"Hello"</span>); <span class="comment">// =&gt; "Hello"</span>
51 <span class="macro">println!</span>(<span class="string_literal">"Hello, </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="string_literal">"world"</span>); <span class="comment">// =&gt; "Hello, world!"</span>
52 <span class="macro">println!</span>(<span class="string_literal">"The number is </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal">"</span>, <span class="numeric_literal">1</span>); <span class="comment">// =&gt; "The number is 1"</span>
53 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="format_specifier">?</span><span class="format_specifier">}</span><span class="string_literal">"</span>, (<span class="numeric_literal">3</span>, <span class="numeric_literal">4</span>)); <span class="comment">// =&gt; "(3, 4)"</span>
54 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="variable">value</span><span class="format_specifier">}</span><span class="string_literal">"</span>, value=<span class="numeric_literal">4</span>); <span class="comment">// =&gt; "4"</span>
55 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal"> </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal">"</span>, <span class="numeric_literal">1</span>, <span class="numeric_literal">2</span>); <span class="comment">// =&gt; "1 2"</span>
56 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="numeric_literal">0</span><span class="numeric_literal">4</span><span class="format_specifier">}</span><span class="string_literal">"</span>, <span class="numeric_literal">42</span>); <span class="comment">// =&gt; "0042" with leading zerosV</span>
57 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="numeric_literal">1</span><span class="format_specifier">}</span><span class="string_literal"> </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal"> </span><span class="format_specifier">{</span><span class="numeric_literal">0</span><span class="format_specifier">}</span><span class="string_literal"> </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal">"</span>, <span class="numeric_literal">1</span>, <span class="numeric_literal">2</span>); <span class="comment">// =&gt; "2 1 1 2"</span>
58 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="variable">argument</span><span class="format_specifier">}</span><span class="string_literal">"</span>, argument = <span class="string_literal">"test"</span>); <span class="comment">// =&gt; "test"</span>
59 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="variable">name</span><span class="format_specifier">}</span><span class="string_literal"> </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal">"</span>, <span class="numeric_literal">1</span>, name = <span class="numeric_literal">2</span>); <span class="comment">// =&gt; "2 1"</span>
60 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="variable">a</span><span class="format_specifier">}</span><span class="string_literal"> </span><span class="format_specifier">{</span><span class="variable">c</span><span class="format_specifier">}</span><span class="string_literal"> </span><span class="format_specifier">{</span><span class="variable">b</span><span class="format_specifier">}</span><span class="string_literal">"</span>, a=<span class="string_literal">"a"</span>, b=<span class="char_literal">'b'</span>, c=<span class="numeric_literal">3</span>); <span class="comment">// =&gt; "a 3 b"</span>
61 <span class="macro">println!</span>(<span class="string_literal">"{{</span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal">}}"</span>, <span class="numeric_literal">2</span>); <span class="comment">// =&gt; "{2}"</span>
62 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="numeric_literal">5</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="string_literal">"x"</span>);
63 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="numeric_literal">1</span><span class="format_specifier">$</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="string_literal">"x"</span>, <span class="numeric_literal">5</span>);
64 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="numeric_literal">1</span><span class="format_specifier">:</span><span class="numeric_literal">0</span><span class="format_specifier">$</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="numeric_literal">5</span>, <span class="string_literal">"x"</span>);
65 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="variable">width</span><span class="format_specifier">$</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="string_literal">"x"</span>, width = <span class="numeric_literal">5</span>);
66 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="format_specifier">&lt;</span><span class="numeric_literal">5</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="string_literal">"x"</span>);
67 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="format_specifier">-</span><span class="format_specifier">&lt;</span><span class="numeric_literal">5</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="string_literal">"x"</span>);
68 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="format_specifier">^</span><span class="numeric_literal">5</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="string_literal">"x"</span>);
69 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="format_specifier">&gt;</span><span class="numeric_literal">5</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="string_literal">"x"</span>);
70 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="format_specifier">+</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="numeric_literal">5</span>);
71 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="format_specifier">#</span><span class="variable">x</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="numeric_literal">27</span>);
72 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="numeric_literal">0</span><span class="numeric_literal">5</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="numeric_literal">5</span>);
73 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="numeric_literal">0</span><span class="numeric_literal">5</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, -<span class="numeric_literal">5</span>);
74 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="format_specifier">#</span><span class="numeric_literal">0</span><span class="numeric_literal">10</span><span class="variable">x</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="numeric_literal">27</span>);
75 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="numeric_literal">0</span><span class="format_specifier">}</span><span class="string_literal"> is </span><span class="format_specifier">{</span><span class="numeric_literal">1</span><span class="format_specifier">:</span><span class="format_specifier">.</span><span class="numeric_literal">5</span><span class="format_specifier">}</span><span class="string_literal">"</span>, <span class="string_literal">"x"</span>, <span class="numeric_literal">0.01</span>);
76 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="numeric_literal">1</span><span class="format_specifier">}</span><span class="string_literal"> is </span><span class="format_specifier">{</span><span class="numeric_literal">2</span><span class="format_specifier">:</span><span class="format_specifier">.</span><span class="numeric_literal">0</span><span class="format_specifier">$</span><span class="format_specifier">}</span><span class="string_literal">"</span>, <span class="numeric_literal">5</span>, <span class="string_literal">"x"</span>, <span class="numeric_literal">0.01</span>);
77 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="numeric_literal">0</span><span class="format_specifier">}</span><span class="string_literal"> is </span><span class="format_specifier">{</span><span class="numeric_literal">2</span><span class="format_specifier">:</span><span class="format_specifier">.</span><span class="numeric_literal">1</span><span class="format_specifier">$</span><span class="format_specifier">}</span><span class="string_literal">"</span>, <span class="string_literal">"x"</span>, <span class="numeric_literal">5</span>, <span class="numeric_literal">0.01</span>);
78 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal"> is </span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="format_specifier">.</span><span class="format_specifier">*</span><span class="format_specifier">}</span><span class="string_literal">"</span>, <span class="string_literal">"x"</span>, <span class="numeric_literal">5</span>, <span class="numeric_literal">0.01</span>);
79 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal"> is </span><span class="format_specifier">{</span><span class="numeric_literal">2</span><span class="format_specifier">:</span><span class="format_specifier">.</span><span class="format_specifier">*</span><span class="format_specifier">}</span><span class="string_literal">"</span>, <span class="string_literal">"x"</span>, <span class="numeric_literal">5</span>, <span class="numeric_literal">0.01</span>);
80 <span class="macro">println!</span>(<span class="string_literal">"Hello </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal"> is </span><span class="format_specifier">{</span><span class="variable">number</span><span class="format_specifier">:</span><span class="format_specifier">.</span><span class="variable">prec</span><span class="format_specifier">$</span><span class="format_specifier">}</span><span class="string_literal">"</span>, <span class="string_literal">"x"</span>, prec = <span class="numeric_literal">5</span>, number = <span class="numeric_literal">0.01</span>);
81 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal">, `</span><span class="format_specifier">{</span><span class="variable">name</span><span class="format_specifier">:</span><span class="format_specifier">.</span><span class="format_specifier">*</span><span class="format_specifier">}</span><span class="string_literal">` has 3 fractional digits"</span>, <span class="string_literal">"Hello"</span>, <span class="numeric_literal">3</span>, name=<span class="numeric_literal">1234.56</span>);
82 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal">, `</span><span class="format_specifier">{</span><span class="variable">name</span><span class="format_specifier">:</span><span class="format_specifier">.</span><span class="format_specifier">*</span><span class="format_specifier">}</span><span class="string_literal">` has 3 characters"</span>, <span class="string_literal">"Hello"</span>, <span class="numeric_literal">3</span>, name=<span class="string_literal">"1234.56"</span>);
83 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal">, `</span><span class="format_specifier">{</span><span class="variable">name</span><span class="format_specifier">:</span><span class="format_specifier">&gt;</span><span class="numeric_literal">8</span><span class="format_specifier">.</span><span class="format_specifier">*</span><span class="format_specifier">}</span><span class="string_literal">` has 3 right-aligned characters"</span>, <span class="string_literal">"Hello"</span>, <span class="numeric_literal">3</span>, name=<span class="string_literal">"1234.56"</span>);
84 <span class="macro">println!</span>(<span class="string_literal">"Hello {{}}"</span>);
85 <span class="macro">println!</span>(<span class="string_literal">"{{ Hello"</span>);
86
87 <span class="macro">println!</span>(<span class="string_literal">r"Hello, </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal">!"</span>, <span class="string_literal">"world"</span>);
88
89 <span class="comment">// escape sequences</span>
90 <span class="macro">println!</span>(<span class="string_literal">"Hello</span><span class="escape_sequence">\n</span><span class="string_literal">World"</span>);
91 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="escape_sequence">\u{48}</span><span class="escape_sequence">\x65</span><span class="escape_sequence">\x6C</span><span class="escape_sequence">\x6C</span><span class="escape_sequence">\x6F</span><span class="string_literal"> World"</span>);
92
93 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="escape_sequence">\x41</span><span class="format_specifier">}</span><span class="string_literal">"</span>, A = <span class="numeric_literal">92</span>);
94 <span class="macro">println!</span>(<span class="string_literal">"</span><span class="format_specifier">{</span><span class="variable">ничоси</span><span class="format_specifier">}</span><span class="string_literal">"</span>, ничоси = <span class="numeric_literal">92</span>);
95}</code></pre> \ No newline at end of file
diff --git a/crates/ra_ide/src/snapshots/highlight_unsafe.html b/crates/ra_ide/src/snapshots/highlight_unsafe.html
deleted file mode 100644
index 6936e949f..000000000
--- a/crates/ra_ide/src/snapshots/highlight_unsafe.html
+++ /dev/null
@@ -1,53 +0,0 @@
1
2<style>
3body { margin: 0; }
4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
5
6.lifetime { color: #DFAF8F; font-style: italic; }
7.comment { color: #7F9F7F; }
8.documentation { color: #629755; }
9.injected { opacity: 0.65 ; }
10.struct, .enum { color: #7CB8BB; }
11.enum_variant { color: #BDE0F3; }
12.string_literal { color: #CC9393; }
13.field { color: #94BFF3; }
14.function { color: #93E0E3; }
15.function.unsafe { color: #BC8383; }
16.operator.unsafe { color: #BC8383; }
17.parameter { color: #94BFF3; }
18.text { color: #DCDCCC; }
19.type { color: #7CB8BB; }
20.builtin_type { color: #8CD0D3; }
21.type_param { color: #DFAF8F; }
22.attribute { color: #94BFF3; }
23.numeric_literal { color: #BFEBBF; }
24.bool_literal { color: #BFE6EB; }
25.macro { color: #94BFF3; }
26.module { color: #AFD8AF; }
27.variable { color: #DCDCCC; }
28.format_specifier { color: #CC696B; }
29.mutable { text-decoration: underline; }
30.unresolved_reference { color: #FC5555; }
31.escape_sequence { color: #94BFF3; }
32
33.keyword { color: #F0DFAF; font-weight: bold; }
34.keyword.unsafe { color: #BC8383; font-weight: bold; }
35.control { font-style: italic; }
36</style>
37<pre><code><span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function declaration unsafe">unsafe_fn</span>() {}
38
39<span class="keyword">struct</span> <span class="struct declaration">HasUnsafeFn</span>;
40
41<span class="keyword">impl</span> <span class="struct">HasUnsafeFn</span> {
42 <span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function declaration unsafe">unsafe_method</span>(&<span class="self_keyword">self</span>) {}
43}
44
45<span class="keyword">fn</span> <span class="function declaration">main</span>() {
46 <span class="keyword">let</span> <span class="variable declaration">x</span> = &<span class="numeric_literal">5</span> <span class="keyword">as</span> *<span class="keyword">const</span> <span class="builtin_type">usize</span>;
47 <span class="keyword unsafe">unsafe</span> {
48 <span class="function unsafe">unsafe_fn</span>();
49 <span class="struct">HasUnsafeFn</span>.<span class="function unsafe">unsafe_method</span>();
50 <span class="keyword">let</span> <span class="variable declaration">y</span> = <span class="operator unsafe">*</span>(<span class="variable">x</span>);
51 <span class="keyword">let</span> <span class="variable declaration">z</span> = -<span class="variable">x</span>;
52 }
53}</code></pre> \ No newline at end of file
diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html
deleted file mode 100644
index 8d0b38f95..000000000
--- a/crates/ra_ide/src/snapshots/highlighting.html
+++ /dev/null
@@ -1,117 +0,0 @@
1
2<style>
3body { margin: 0; }
4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
5
6.lifetime { color: #DFAF8F; font-style: italic; }
7.comment { color: #7F9F7F; }
8.documentation { color: #629755; }
9.injected { opacity: 0.65 ; }
10.struct, .enum { color: #7CB8BB; }
11.enum_variant { color: #BDE0F3; }
12.string_literal { color: #CC9393; }
13.field { color: #94BFF3; }
14.function { color: #93E0E3; }
15.function.unsafe { color: #BC8383; }
16.operator.unsafe { color: #BC8383; }
17.parameter { color: #94BFF3; }
18.text { color: #DCDCCC; }
19.type { color: #7CB8BB; }
20.builtin_type { color: #8CD0D3; }
21.type_param { color: #DFAF8F; }
22.attribute { color: #94BFF3; }
23.numeric_literal { color: #BFEBBF; }
24.bool_literal { color: #BFE6EB; }
25.macro { color: #94BFF3; }
26.module { color: #AFD8AF; }
27.variable { color: #DCDCCC; }
28.format_specifier { color: #CC696B; }
29.mutable { text-decoration: underline; }
30.unresolved_reference { color: #FC5555; }
31.escape_sequence { color: #94BFF3; }
32
33.keyword { color: #F0DFAF; font-weight: bold; }
34.keyword.unsafe { color: #BC8383; font-weight: bold; }
35.control { font-style: italic; }
36</style>
37<pre><code><span class="attribute">#[</span><span class="function attribute">derive</span><span class="attribute">(Clone, Debug)]</span>
38<span class="keyword">struct</span> <span class="struct declaration">Foo</span> {
39 <span class="keyword">pub</span> <span class="field declaration">x</span>: <span class="builtin_type">i32</span>,
40 <span class="keyword">pub</span> <span class="field declaration">y</span>: <span class="builtin_type">i32</span>,
41}
42
43<span class="keyword">trait</span> <span class="trait declaration">Bar</span> {
44 <span class="keyword">fn</span> <span class="function declaration">bar</span>(&<span class="self_keyword">self</span>) -&gt; <span class="builtin_type">i32</span>;
45}
46
47<span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> {
48 <span class="keyword">fn</span> <span class="function declaration">bar</span>(&<span class="self_keyword">self</span>) -&gt; <span class="builtin_type">i32</span> {
49 <span class="self_keyword">self</span>.<span class="field">x</span>
50 }
51}
52
53<span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable">STATIC_MUT</span>: <span class="builtin_type">i32</span> = <span class="numeric_literal">0</span>;
54
55<span class="keyword">fn</span> <span class="function declaration">foo</span>&lt;<span class="lifetime declaration">'a</span>, <span class="type_param declaration">T</span>&gt;() -&gt; <span class="type_param">T</span> {
56 <span class="function">foo</span>::&lt;<span class="lifetime">'a</span>, <span class="builtin_type">i32</span>&gt;()
57}
58
59<span class="macro">macro_rules!</span> <span class="macro declaration">def_fn</span> {
60 ($($tt:tt)*) =&gt; {$($tt)*}
61}
62
63<span class="macro">def_fn!</span> {
64 <span class="keyword">fn</span> <span class="function declaration">bar</span>() -&gt; <span class="builtin_type">u32</span> {
65 <span class="numeric_literal">100</span>
66 }
67}
68
69<span class="macro">macro_rules!</span> <span class="macro declaration">noop</span> {
70 ($expr:expr) =&gt; {
71 $expr
72 }
73}
74
75<span class="comment">// comment</span>
76<span class="keyword">fn</span> <span class="function declaration">main</span>() {
77 <span class="macro">println!</span>(<span class="string_literal">"Hello, {}!"</span>, <span class="numeric_literal">92</span>);
78
79 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">vec</span> = <span class="unresolved_reference">Vec</span>::<span class="unresolved_reference">new</span>();
80 <span class="keyword control">if</span> <span class="bool_literal">true</span> {
81 <span class="keyword">let</span> <span class="variable declaration">x</span> = <span class="numeric_literal">92</span>;
82 <span class="variable mutable">vec</span>.<span class="unresolved_reference">push</span>(<span class="struct">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="numeric_literal">1</span> });
83 }
84 <span class="keyword unsafe">unsafe</span> {
85 <span class="variable mutable">vec</span>.<span class="unresolved_reference">set_len</span>(<span class="numeric_literal">0</span>);
86 <span class="static mutable">STATIC_MUT</span> = <span class="numeric_literal">1</span>;
87 }
88
89 <span class="keyword control">for</span> <span class="variable declaration">e</span> <span class="keyword control">in</span> <span class="variable mutable">vec</span> {
90 <span class="comment">// Do nothing</span>
91 }
92
93 <span class="macro">noop!</span>(<span class="macro">noop</span><span class="macro">!</span>(<span class="numeric_literal">1</span>));
94
95 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">x</span> = <span class="numeric_literal">42</span>;
96 <span class="keyword">let</span> <span class="variable declaration mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>;
97 <span class="keyword">let</span> <span class="variable declaration">z</span> = &<span class="variable mutable">y</span>;
98
99 <span class="keyword">let</span> <span class="struct">Foo</span> { <span class="field">x</span>: <span class="variable declaration">z</span>, <span class="field">y</span> } = <span class="struct">Foo</span> { <span class="field">x</span>: <span class="variable">z</span>, <span class="field">y</span> };
100
101 <span class="variable">y</span>;
102}
103
104<span class="keyword">enum</span> <span class="enum declaration">Option</span>&lt;<span class="type_param declaration">T</span>&gt; {
105 <span class="enum_variant declaration">Some</span>(<span class="type_param">T</span>),
106 <span class="enum_variant declaration">None</span>,
107}
108<span class="keyword">use</span> <span class="enum">Option</span>::*;
109
110<span class="keyword">impl</span>&lt;<span class="type_param declaration">T</span>&gt; <span class="enum">Option</span>&lt;<span class="type_param">T</span>&gt; {
111 <span class="keyword">fn</span> <span class="function declaration">and</span>&lt;<span class="type_param declaration">U</span>&gt;(<span class="self_keyword">self</span>, <span class="variable declaration">other</span>: <span class="enum">Option</span>&lt;<span class="type_param">U</span>&gt;) -&gt; <span class="enum">Option</span>&lt;(<span class="type_param">T</span>, <span class="type_param">U</span>)&gt; {
112 <span class="keyword control">match</span> <span class="variable">other</span> {
113 <span class="enum_variant">None</span> =&gt; <span class="macro">unimplemented!</span>(),
114 <span class="variable declaration">Nope</span> =&gt; <span class="variable">Nope</span>,
115 }
116 }
117}</code></pre> \ No newline at end of file
diff --git a/crates/ra_ide/src/snapshots/rainbow_highlighting.html b/crates/ra_ide/src/snapshots/rainbow_highlighting.html
deleted file mode 100644
index 9516c7441..000000000
--- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html
+++ /dev/null
@@ -1,48 +0,0 @@
1
2<style>
3body { margin: 0; }
4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
5
6.lifetime { color: #DFAF8F; font-style: italic; }
7.comment { color: #7F9F7F; }
8.documentation { color: #629755; }
9.injected { opacity: 0.65 ; }
10.struct, .enum { color: #7CB8BB; }
11.enum_variant { color: #BDE0F3; }
12.string_literal { color: #CC9393; }
13.field { color: #94BFF3; }
14.function { color: #93E0E3; }
15.function.unsafe { color: #BC8383; }
16.operator.unsafe { color: #BC8383; }
17.parameter { color: #94BFF3; }
18.text { color: #DCDCCC; }
19.type { color: #7CB8BB; }
20.builtin_type { color: #8CD0D3; }
21.type_param { color: #DFAF8F; }
22.attribute { color: #94BFF3; }
23.numeric_literal { color: #BFEBBF; }
24.bool_literal { color: #BFE6EB; }
25.macro { color: #94BFF3; }
26.module { color: #AFD8AF; }
27.variable { color: #DCDCCC; }
28.format_specifier { color: #CC696B; }
29.mutable { text-decoration: underline; }
30.unresolved_reference { color: #FC5555; }
31.escape_sequence { color: #94BFF3; }
32
33.keyword { color: #F0DFAF; font-weight: bold; }
34.keyword.unsafe { color: #BC8383; font-weight: bold; }
35.control { font-style: italic; }
36</style>
37<pre><code><span class="keyword">fn</span> <span class="function declaration">main</span>() {
38 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>;
39 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="2705725358298919760" style="color: hsl(17,51%,74%);">x</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.<span class="unresolved_reference">to_string</span>();
40 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="3365759661443752373" style="color: hsl(127,76%,66%);">y</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.<span class="unresolved_reference">to_string</span>();
41
42 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span> = <span class="string_literal">"other color please!"</span>;
43 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="6717528807933952652" style="color: hsl(85,49%,84%);">y</span> = <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span>.<span class="unresolved_reference">to_string</span>();
44}
45
46<span class="keyword">fn</span> <span class="function declaration">bar</span>() {
47 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>;
48}</code></pre> \ No newline at end of file
diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs
index 6cb96608b..b3e9e5dfe 100644
--- a/crates/ra_ide/src/ssr.rs
+++ b/crates/ra_ide/src/ssr.rs
@@ -4,12 +4,24 @@ use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase};
4use crate::SourceFileEdit; 4use crate::SourceFileEdit;
5use ra_ssr::{MatchFinder, SsrError, SsrRule}; 5use ra_ssr::{MatchFinder, SsrError, SsrRule};
6 6
7// Feature: Structural Seach and Replace 7// Feature: Structural Search and Replace
8// 8//
9// Search and replace with named wildcards that will match any expression, type, path, pattern or item. 9// Search and replace with named wildcards that will match any expression, type, path, pattern or item.
10// The syntax for a structural search replace command is `<search_pattern> ==>> <replace_pattern>`. 10// The syntax for a structural search replace command is `<search_pattern> ==>> <replace_pattern>`.
11// A `$<name>` placeholder in the search pattern will match any AST node and `$<name>` will reference it in the replacement. 11// A `$<name>` placeholder in the search pattern will match any AST node and `$<name>` will reference it in the replacement.
12// Within a macro call, a placeholder will match up until whatever token follows the placeholder. 12// Within a macro call, a placeholder will match up until whatever token follows the placeholder.
13//
14// Placeholders may be given constraints by writing them as `${<name>:<constraint1>:<constraint2>...}`.
15//
16// Supported constraints:
17//
18// |===
19// | Constraint | Restricts placeholder
20//
21// | kind(literal) | Is a literal (e.g. `42` or `"forty two"`)
22// | not(a) | Negates the constraint `a`
23// |===
24//
13// Available via the command `rust-analyzer.ssr`. 25// Available via the command `rust-analyzer.ssr`.
14// 26//
15// ```rust 27// ```rust
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index b7fad9719..aa7c887d6 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -1,6 +1,7 @@
1use std::fs; 1use std::fs;
2 2
3use test_utils::{assert_eq_text, project_dir, read_text}; 3use expect::{expect_file, ExpectFile};
4use test_utils::project_dir;
4 5
5use crate::{mock_analysis::single_file, FileRange, TextRange}; 6use crate::{mock_analysis::single_file, FileRange, TextRange};
6 7
@@ -91,7 +92,7 @@ impl<T> Option<T> {
91} 92}
92"# 93"#
93 .trim(), 94 .trim(),
94 "crates/ra_ide/src/snapshots/highlighting.html", 95 expect_file!["crates/ra_ide/test_data/highlighting.html"],
95 false, 96 false,
96 ); 97 );
97} 98}
@@ -114,7 +115,7 @@ fn bar() {
114} 115}
115"# 116"#
116 .trim(), 117 .trim(),
117 "crates/ra_ide/src/snapshots/rainbow_highlighting.html", 118 expect_file!["crates/ra_ide/test_data/rainbow_highlighting.html"],
118 true, 119 true,
119 ); 120 );
120} 121}
@@ -167,7 +168,7 @@ fn main() {
167 ); 168 );
168}"## 169}"##
169 .trim(), 170 .trim(),
170 "crates/ra_ide/src/snapshots/highlight_injection.html", 171 expect_file!["crates/ra_ide/test_data/highlight_injection.html"],
171 false, 172 false,
172 ); 173 );
173} 174}
@@ -250,7 +251,7 @@ fn main() {
250 println!("{ничоси}", ничоси = 92); 251 println!("{ничоси}", ничоси = 92);
251}"# 252}"#
252 .trim(), 253 .trim(),
253 "crates/ra_ide/src/snapshots/highlight_strings.html", 254 expect_file!["crates/ra_ide/test_data/highlight_strings.html"],
254 false, 255 false,
255 ); 256 );
256} 257}
@@ -278,7 +279,7 @@ fn main() {
278} 279}
279"# 280"#
280 .trim(), 281 .trim(),
281 "crates/ra_ide/src/snapshots/highlight_unsafe.html", 282 expect_file!["crates/ra_ide/test_data/highlight_unsafe.html"],
282 false, 283 false,
283 ); 284 );
284} 285}
@@ -354,7 +355,7 @@ macro_rules! noop {
354} 355}
355"# 356"#
356 .trim(), 357 .trim(),
357 "crates/ra_ide/src/snapshots/highlight_doctest.html", 358 expect_file!["crates/ra_ide/test_data/highlight_doctest.html"],
358 false, 359 false,
359 ); 360 );
360} 361}
@@ -362,11 +363,8 @@ macro_rules! noop {
362/// Highlights the code given by the `ra_fixture` argument, renders the 363/// Highlights the code given by the `ra_fixture` argument, renders the
363/// result as HTML, and compares it with the HTML file given as `snapshot`. 364/// result as HTML, and compares it with the HTML file given as `snapshot`.
364/// Note that the `snapshot` file is overwritten by the rendered HTML. 365/// Note that the `snapshot` file is overwritten by the rendered HTML.
365fn check_highlighting(ra_fixture: &str, snapshot: &str, rainbow: bool) { 366fn check_highlighting(ra_fixture: &str, expect: ExpectFile, rainbow: bool) {
366 let (analysis, file_id) = single_file(ra_fixture); 367 let (analysis, file_id) = single_file(ra_fixture);
367 let dst_file = project_dir().join(snapshot);
368 let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap(); 368 let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap();
369 let expected_html = &read_text(&dst_file); 369 expect.assert_eq(actual_html)
370 fs::write(dst_file, &actual_html).unwrap();
371 assert_eq_text!(expected_html, actual_html);
372} 370}