aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-16 13:49:26 +0000
committerAleksey Kladov <[email protected]>2019-11-16 14:00:54 +0000
commit2eaa8c94a8a6b5cd86139c5e010ae95268b28658 (patch)
treeba86bbb6e4e82fb1a85ab6a830173c00f2415d5e /crates/ra_hir
parent786cae520ad62c9a0a13f5ab18e5bd7e5b0c9825 (diff)
Goto definition works inside macros
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/source_binder.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 5764dc26d..75a467fb3 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -11,7 +11,7 @@ use hir_def::{
11 expr::{ExprId, PatId}, 11 expr::{ExprId, PatId},
12 path::known, 12 path::known,
13}; 13};
14use hir_expand::{name::AsName, Source}; 14use hir_expand::{name::AsName, AstId, MacroCallId, MacroCallLoc, MacroFileKind, Source};
15use ra_syntax::{ 15use ra_syntax::{
16 ast::{self, AstNode}, 16 ast::{self, AstNode},
17 match_ast, AstPtr, 17 match_ast, AstPtr,
@@ -126,6 +126,20 @@ pub struct ReferenceDescriptor {
126 pub name: String, 126 pub name: String,
127} 127}
128 128
129pub struct Expansion {
130 macro_call_id: MacroCallId,
131}
132
133impl Expansion {
134 pub fn translate_offset(&self, db: &impl HirDatabase, offset: TextUnit) -> Option<TextUnit> {
135 let exp_info = self.file_id().expansion_info(db)?;
136 exp_info.translate_offset(offset)
137 }
138 pub fn file_id(&self) -> HirFileId {
139 self.macro_call_id.as_file(MacroFileKind::Items)
140 }
141}
142
129impl SourceAnalyzer { 143impl SourceAnalyzer {
130 pub fn new( 144 pub fn new(
131 db: &impl HirDatabase, 145 db: &impl HirDatabase,
@@ -386,6 +400,13 @@ impl SourceAnalyzer {
386 implements_trait(&canonical_ty, db, &self.resolver, krate, std_future_trait) 400 implements_trait(&canonical_ty, db, &self.resolver, krate, std_future_trait)
387 } 401 }
388 402
403 pub fn expand(&self, db: &impl HirDatabase, macro_call: &ast::MacroCall) -> Option<Expansion> {
404 let def = self.resolve_macro_call(db, macro_call)?.id;
405 let ast_id = AstId::new(self.file_id, db.ast_id_map(self.file_id).ast_id(macro_call));
406 let macro_call_loc = MacroCallLoc { def, ast_id };
407 Some(Expansion { macro_call_id: db.intern_macro(macro_call_loc) })
408 }
409
389 #[cfg(test)] 410 #[cfg(test)]
390 pub(crate) fn body_source_map(&self) -> Arc<BodySourceMap> { 411 pub(crate) fn body_source_map(&self) -> Arc<BodySourceMap> {
391 self.body_source_map.clone().unwrap() 412 self.body_source_map.clone().unwrap()