diff options
author | Florian Diebold <[email protected]> | 2019-12-06 18:30:15 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-12-06 20:25:22 +0000 |
commit | a565072ddeac519eea3b415a57e9fd208e20e562 (patch) | |
tree | 4c76dbe6729de22de2f00862b56ed5dfd46d699b /crates/ra_hir_expand/src | |
parent | eae425b10fd7803ae67d2d39e9aca902daa353ba (diff) |
Try to make go to definition work in format!
SourceAnalyzer didn't work properly within expression macro expansions because
it didn't find the enclosing function. Fix this by going up the expansion chain
to find ancestors. This makes the test work, but apparently in real usage it's
still not working.
Diffstat (limited to 'crates/ra_hir_expand/src')
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 59c69b91b..0c1dc87e6 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -76,6 +76,17 @@ impl HirFileId { | |||
76 | } | 76 | } |
77 | } | 77 | } |
78 | 78 | ||
79 | /// If this is a macro call, returns the syntax node of the call. | ||
80 | pub fn call_node(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxNode>> { | ||
81 | match self.0 { | ||
82 | HirFileIdRepr::FileId(_) => None, | ||
83 | HirFileIdRepr::MacroFile(macro_file) => { | ||
84 | let loc = db.lookup_intern_macro(macro_file.macro_call_id); | ||
85 | Some(loc.kind.node(db)) | ||
86 | } | ||
87 | } | ||
88 | } | ||
89 | |||
79 | /// Return expansion information if it is a macro-expansion file | 90 | /// Return expansion information if it is a macro-expansion file |
80 | pub fn expansion_info(self, db: &dyn db::AstDatabase) -> Option<ExpansionInfo> { | 91 | pub fn expansion_info(self, db: &dyn db::AstDatabase) -> Option<ExpansionInfo> { |
81 | match self.0 { | 92 | match self.0 { |
@@ -176,6 +187,13 @@ impl MacroCallKind { | |||
176 | } | 187 | } |
177 | } | 188 | } |
178 | 189 | ||
190 | pub fn node(&self, db: &dyn db::AstDatabase) -> InFile<SyntaxNode> { | ||
191 | match self { | ||
192 | MacroCallKind::FnLike(ast_id) => ast_id.with_value(ast_id.to_node(db).syntax().clone()), | ||
193 | MacroCallKind::Attr(ast_id) => ast_id.with_value(ast_id.to_node(db).syntax().clone()), | ||
194 | } | ||
195 | } | ||
196 | |||
179 | pub fn arg(&self, db: &dyn db::AstDatabase) -> Option<SyntaxNode> { | 197 | pub fn arg(&self, db: &dyn db::AstDatabase) -> Option<SyntaxNode> { |
180 | match self { | 198 | match self { |
181 | MacroCallKind::FnLike(ast_id) => { | 199 | MacroCallKind::FnLike(ast_id) => { |