aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/lib.rs4
-rw-r--r--crates/ra_hir/src/source_binder.rs43
2 files changed, 42 insertions, 5 deletions
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 4411715de..03b1063b6 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -69,7 +69,7 @@ pub use self::{
69 expr::ExprScopes, 69 expr::ExprScopes,
70 resolve::Resolution, 70 resolve::Resolution,
71 generics::{GenericParams, GenericParam, HasGenericParams}, 71 generics::{GenericParams, GenericParam, HasGenericParams},
72 source_binder::{SourceAnalyzer, PathResolution, ScopeEntryWithSyntax}, 72 source_binder::{SourceAnalyzer, PathResolution, ScopeEntryWithSyntax,MacroByExampleDef},
73}; 73};
74 74
75pub use self::code_model_api::{ 75pub use self::code_model_api::{
@@ -80,5 +80,5 @@ pub use self::code_model_api::{
80 Function, FnSignature, 80 Function, FnSignature,
81 StructField, FieldSource, 81 StructField, FieldSource,
82 Static, Const, ConstSignature, 82 Static, Const, ConstSignature,
83 Trait, TypeAlias, Container, 83 Trait, TypeAlias, Container
84}; 84};
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 2ec1a7692..31bf13425 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -10,7 +10,7 @@ use std::sync::Arc;
10use rustc_hash::{FxHashSet, FxHashMap}; 10use rustc_hash::{FxHashSet, FxHashMap};
11use ra_db::{FileId, FilePosition}; 11use ra_db::{FileId, FilePosition};
12use ra_syntax::{ 12use ra_syntax::{
13 SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, TextRange, 13 SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, TextRange,TreeArc,
14 ast::{self, AstNode, NameOwner}, 14 ast::{self, AstNode, NameOwner},
15 algo::find_node_at_offset, 15 algo::find_node_at_offset,
16 SyntaxKind::*, 16 SyntaxKind::*,
@@ -18,9 +18,10 @@ use ra_syntax::{
18 18
19use crate::{ 19use crate::{
20 HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name, 20 HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name,
21 AsName, Module, HirFileId, Crate, Trait, Resolver, Ty, 21 AsName, Module, HirFileId, Crate, Trait, Resolver, Ty,Path,
22 expr::{BodySourceMap, scope::{ScopeId, ExprScopes}}, 22 expr::{BodySourceMap, scope::{ScopeId, ExprScopes}},
23 ids::LocationCtx, 23 ids::{LocationCtx,MacroCallId},
24 docs::{docs_from_ast,Documentation},
24 expr, AstId, 25 expr, AstId,
25}; 26};
26 27
@@ -184,9 +185,28 @@ pub enum PathResolution {
184 /// A generic parameter 185 /// A generic parameter
185 GenericParam(u32), 186 GenericParam(u32),
186 SelfType(crate::ImplBlock), 187 SelfType(crate::ImplBlock),
188 Macro(MacroByExampleDef),
187 AssocItem(crate::ImplItem), 189 AssocItem(crate::ImplItem),
188} 190}
189 191
192#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
193pub struct MacroByExampleDef {
194 pub(crate) id: MacroCallId,
195}
196
197impl MacroByExampleDef {
198 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::MacroCall>) {
199 let loc = self.id.loc(db);
200 (self.id.into(), loc.def.0.to_node(db))
201 }
202}
203
204impl crate::Docs for MacroByExampleDef {
205 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
206 docs_from_ast(&*self.source(db).1)
207 }
208}
209
190#[derive(Debug, Clone, PartialEq, Eq)] 210#[derive(Debug, Clone, PartialEq, Eq)]
191pub struct ScopeEntryWithSyntax { 211pub struct ScopeEntryWithSyntax {
192 pub(crate) name: Name, 212 pub(crate) name: Name,
@@ -264,6 +284,23 @@ impl SourceAnalyzer {
264 self.infer.as_ref()?.field_resolution(expr_id) 284 self.infer.as_ref()?.field_resolution(expr_id)
265 } 285 }
266 286
287 pub fn resolve_macro_call(
288 &self,
289 db: &impl HirDatabase,
290 file_id: FileId,
291 macro_call: &ast::MacroCall,
292 ) -> Option<MacroByExampleDef> {
293 let hir_id = file_id.into();
294 let ast_id = db.ast_id_map(hir_id).ast_id(macro_call).with_file_id(hir_id);
295 let call_id = self.resolver.resolve_macro_call(
296 db,
297 macro_call.path().and_then(Path::from_ast),
298 ast_id,
299 );
300
301 call_id.map(|id| MacroByExampleDef { id })
302 }
303
267 pub fn resolve_hir_path( 304 pub fn resolve_hir_path(
268 &self, 305 &self,
269 db: &impl HirDatabase, 306 db: &impl HirDatabase,