diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 9 | ||||
-rw-r--r-- | crates/ra_hir/src/docs.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 30 |
4 files changed, 21 insertions, 27 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index cf16ed94d..27850028b 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -939,6 +939,15 @@ pub struct MacroDef { | |||
939 | pub(crate) id: MacroDefId, | 939 | pub(crate) id: MacroDefId, |
940 | } | 940 | } |
941 | 941 | ||
942 | impl MacroDef { | ||
943 | pub fn source( | ||
944 | &self, | ||
945 | db: &(impl DefDatabase + AstDatabase), | ||
946 | ) -> (HirFileId, TreeArc<ast::MacroCall>) { | ||
947 | (self.id.0.file_id(), self.id.0.to_node(db)) | ||
948 | } | ||
949 | } | ||
950 | |||
942 | pub enum Container { | 951 | pub enum Container { |
943 | Trait(Trait), | 952 | Trait(Trait), |
944 | ImplBlock(ImplBlock), | 953 | ImplBlock(ImplBlock), |
diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs index 900fd2aa8..1b0f84de5 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/docs.rs | |||
@@ -4,7 +4,7 @@ use ra_syntax::ast; | |||
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | HirDatabase, DefDatabase, AstDatabase, | 6 | HirDatabase, DefDatabase, AstDatabase, |
7 | Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource | 7 | Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource, MacroDef, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 10 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
@@ -20,6 +20,7 @@ pub enum DocDef { | |||
20 | Union(Union), | 20 | Union(Union), |
21 | Trait(Trait), | 21 | Trait(Trait), |
22 | TypeAlias(TypeAlias), | 22 | TypeAlias(TypeAlias), |
23 | MacroDef(MacroDef), | ||
23 | } | 24 | } |
24 | 25 | ||
25 | impl_froms!( | 26 | impl_froms!( |
@@ -33,7 +34,8 @@ impl_froms!( | |||
33 | Function, | 34 | Function, |
34 | Union, | 35 | Union, |
35 | Trait, | 36 | Trait, |
36 | TypeAlias | 37 | TypeAlias, |
38 | MacroDef | ||
37 | ); | 39 | ); |
38 | 40 | ||
39 | /// Holds documentation | 41 | /// Holds documentation |
@@ -83,6 +85,7 @@ pub(crate) fn documentation_query( | |||
83 | DocDef::Union(it) => docs_from_ast(&*it.source(db).1), | 85 | DocDef::Union(it) => docs_from_ast(&*it.source(db).1), |
84 | DocDef::Trait(it) => docs_from_ast(&*it.source(db).1), | 86 | DocDef::Trait(it) => docs_from_ast(&*it.source(db).1), |
85 | DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).1), | 87 | DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).1), |
88 | DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).1), | ||
86 | } | 89 | } |
87 | } | 90 | } |
88 | 91 | ||
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 18dea5f17..0e4aaf678 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,MacroByExampleDef}, | 72 | source_binder::{SourceAnalyzer, PathResolution, ScopeEntryWithSyntax}, |
73 | }; | 73 | }; |
74 | 74 | ||
75 | pub use self::code_model::{ | 75 | pub use self::code_model::{ |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 6a5799622..410064d45 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; | |||
10 | use rustc_hash::{FxHashSet, FxHashMap}; | 10 | use rustc_hash::{FxHashSet, FxHashMap}; |
11 | use ra_db::{FileId, FilePosition}; | 11 | use ra_db::{FileId, FilePosition}; |
12 | use ra_syntax::{ | 12 | use ra_syntax::{ |
13 | SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, TextRange,TreeArc, | 13 | SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, TextRange, |
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,10 +18,9 @@ use ra_syntax::{ | |||
18 | 18 | ||
19 | use crate::{ | 19 | use 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,Path, | 21 | AsName, Module, HirFileId, Crate, Trait, Resolver, Ty, Path, MacroDef, |
22 | expr::{BodySourceMap, scope::{ScopeId, ExprScopes}}, | 22 | expr::{BodySourceMap, scope::{ScopeId, ExprScopes}}, |
23 | ids::{LocationCtx, MacroDefId}, | 23 | ids::LocationCtx, |
24 | docs::{docs_from_ast,Documentation}, | ||
25 | expr, AstId, | 24 | expr, AstId, |
26 | }; | 25 | }; |
27 | 26 | ||
@@ -182,27 +181,10 @@ pub enum PathResolution { | |||
182 | /// A generic parameter | 181 | /// A generic parameter |
183 | GenericParam(u32), | 182 | GenericParam(u32), |
184 | SelfType(crate::ImplBlock), | 183 | SelfType(crate::ImplBlock), |
185 | Macro(MacroByExampleDef), | 184 | Macro(MacroDef), |
186 | AssocItem(crate::ImplItem), | 185 | AssocItem(crate::ImplItem), |
187 | } | 186 | } |
188 | 187 | ||
189 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
190 | pub struct MacroByExampleDef { | ||
191 | pub(crate) id: MacroDefId, | ||
192 | } | ||
193 | |||
194 | impl MacroByExampleDef { | ||
195 | pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::MacroCall>) { | ||
196 | (self.id.0.file_id(), self.id.0.to_node(db)) | ||
197 | } | ||
198 | } | ||
199 | |||
200 | impl crate::Docs for MacroByExampleDef { | ||
201 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { | ||
202 | docs_from_ast(&*self.source(db).1) | ||
203 | } | ||
204 | } | ||
205 | |||
206 | #[derive(Debug, Clone, PartialEq, Eq)] | 188 | #[derive(Debug, Clone, PartialEq, Eq)] |
207 | pub struct ScopeEntryWithSyntax { | 189 | pub struct ScopeEntryWithSyntax { |
208 | pub(crate) name: Name, | 190 | pub(crate) name: Name, |
@@ -284,10 +266,10 @@ impl SourceAnalyzer { | |||
284 | &self, | 266 | &self, |
285 | db: &impl HirDatabase, | 267 | db: &impl HirDatabase, |
286 | macro_call: &ast::MacroCall, | 268 | macro_call: &ast::MacroCall, |
287 | ) -> Option<MacroByExampleDef> { | 269 | ) -> Option<MacroDef> { |
288 | let id = | 270 | let id = |
289 | self.resolver.resolve_macro_call(db, macro_call.path().and_then(Path::from_ast))?; | 271 | self.resolver.resolve_macro_call(db, macro_call.path().and_then(Path::from_ast))?; |
290 | Some(MacroByExampleDef { id }) | 272 | Some(MacroDef { id }) |
291 | } | 273 | } |
292 | 274 | ||
293 | pub fn resolve_hir_path( | 275 | pub fn resolve_hir_path( |