aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-11-19 14:56:48 +0000
committerEdwin Cheng <[email protected]>2019-11-19 14:56:48 +0000
commit4012da07fd22223660a21c65d54d10a9a632eda0 (patch)
tree1081edcfc24b16ba0d0433d40e499458039aa5f3 /crates/ra_ide_api
parent94c63d280246971983cad4fa6ce2d333e3ba9f02 (diff)
Change return type of expand_macro
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/expand_macro.rs14
-rw-r--r--crates/ra_ide_api/src/lib.rs3
2 files changed, 12 insertions, 5 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
14pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<(String, String)> { 14pub struct ExpandedMacro {
15 pub name: String,
16 pub expansion: String,
17}
18
19pub(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
30fn expand_macro_recur( 35fn 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]
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index d1b73ef6f..57ed97147 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -66,6 +66,7 @@ pub use crate::{
66 completion::{CompletionItem, CompletionItemKind, InsertTextFormat}, 66 completion::{CompletionItem, CompletionItemKind, InsertTextFormat},
67 diagnostics::Severity, 67 diagnostics::Severity,
68 display::{file_structure, FunctionSignature, NavigationTarget, StructureNode}, 68 display::{file_structure, FunctionSignature, NavigationTarget, StructureNode},
69 expand_macro::ExpandedMacro,
69 feature_flags::FeatureFlags, 70 feature_flags::FeatureFlags,
70 folding_ranges::{Fold, FoldKind}, 71 folding_ranges::{Fold, FoldKind},
71 hover::HoverResult, 72 hover::HoverResult,
@@ -297,7 +298,7 @@ impl Analysis {
297 self.with_db(|db| syntax_tree::syntax_tree(&db, file_id, text_range)) 298 self.with_db(|db| syntax_tree::syntax_tree(&db, file_id, text_range))
298 } 299 }
299 300
300 pub fn expand_macro(&self, position: FilePosition) -> Cancelable<Option<(String, String)>> { 301 pub fn expand_macro(&self, position: FilePosition) -> Cancelable<Option<ExpandedMacro>> {
301 self.with_db(|db| expand_macro::expand_macro(db, position)) 302 self.with_db(|db| expand_macro::expand_macro(db, position))
302 } 303 }
303 304