diff options
Diffstat (limited to 'crates/ra_ide_api/src/expand_macro.rs')
-rw-r--r-- | crates/ra_ide_api/src/expand_macro.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/crates/ra_ide_api/src/expand_macro.rs b/crates/ra_ide_api/src/expand_macro.rs index bd557d455..44e77ba50 100644 --- a/crates/ra_ide_api/src/expand_macro.rs +++ b/crates/ra_ide_api/src/expand_macro.rs | |||
@@ -11,7 +11,12 @@ use ra_syntax::{ | |||
11 | AstNode, NodeOrToken, SyntaxKind, SyntaxNode, WalkEvent, | 11 | AstNode, NodeOrToken, SyntaxKind, SyntaxNode, WalkEvent, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<(String, String)> { | 14 | pub struct ExpandedMacro { |
15 | pub name: String, | ||
16 | pub expansion: String, | ||
17 | } | ||
18 | |||
19 | pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<ExpandedMacro> { | ||
15 | let parse = db.parse(position.file_id); | 20 | let parse = db.parse(position.file_id); |
16 | let file = parse.tree(); | 21 | let file = parse.tree(); |
17 | let name_ref = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset)?; | 22 | let name_ref = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset)?; |
@@ -23,8 +28,8 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option< | |||
23 | // FIXME: | 28 | // FIXME: |
24 | // macro expansion may lose all white space information | 29 | // macro expansion may lose all white space information |
25 | // But we hope someday we can use ra_fmt for that | 30 | // But we hope someday we can use ra_fmt for that |
26 | let res = insert_whitespaces(expanded); | 31 | let expansion = insert_whitespaces(expanded); |
27 | Some((name_ref.text().to_string(), res)) | 32 | Some(ExpandedMacro { name: name_ref.text().to_string(), expansion }) |
28 | } | 33 | } |
29 | 34 | ||
30 | fn expand_macro_recur( | 35 | fn expand_macro_recur( |
@@ -87,7 +92,8 @@ mod tests { | |||
87 | let (analysis, pos) = analysis_and_position(fixture); | 92 | let (analysis, pos) = analysis_and_position(fixture); |
88 | 93 | ||
89 | let result = analysis.expand_macro(pos).unwrap().unwrap(); | 94 | let result = analysis.expand_macro(pos).unwrap().unwrap(); |
90 | assert_eq!(result, (expected.0.to_string(), expected.1.to_string())); | 95 | assert_eq!(result.name, expected.0.to_string()); |
96 | assert_eq!(result.expansion, expected.1.to_string()); | ||
91 | } | 97 | } |
92 | 98 | ||
93 | #[test] | 99 | #[test] |