diff options
author | Aleksey Kladov <[email protected]> | 2019-06-08 12:48:56 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-06-08 12:48:56 +0100 |
commit | 1b783e33e953f2c63c96c1d7fa54d2e64fbd2d9a (patch) | |
tree | 391c4e4ca264830a19045b2016034bb1bdbb98d9 /crates | |
parent | 2c28f5245dd8ede715d99b55fdad0ceb3de9dbe7 (diff) |
one macro def should be enough
Diffstat (limited to 'crates')
-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 | ||||
-rw-r--r-- | crates/ra_ide_api/src/display/navigation_target.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_api/src/name_ref_kind.rs | 5 |
6 files changed, 25 insertions, 33 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( |
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index e19c071b0..45002d098 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs | |||
@@ -238,10 +238,7 @@ impl NavigationTarget { | |||
238 | } | 238 | } |
239 | } | 239 | } |
240 | 240 | ||
241 | pub(crate) fn from_macro_def( | 241 | pub(crate) fn from_macro_def(db: &RootDatabase, macro_call: hir::MacroDef) -> NavigationTarget { |
242 | db: &RootDatabase, | ||
243 | macro_call: hir::MacroByExampleDef, | ||
244 | ) -> NavigationTarget { | ||
245 | let (file_id, node) = macro_call.source(db); | 242 | let (file_id, node) = macro_call.source(db); |
246 | log::debug!("nav target {}", node.syntax().debug_dump()); | 243 | log::debug!("nav target {}", node.syntax().debug_dump()); |
247 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 244 | NavigationTarget::from_named(file_id.original_file(db), &*node) |
diff --git a/crates/ra_ide_api/src/name_ref_kind.rs b/crates/ra_ide_api/src/name_ref_kind.rs index 90972bc58..000036db4 100644 --- a/crates/ra_ide_api/src/name_ref_kind.rs +++ b/crates/ra_ide_api/src/name_ref_kind.rs | |||
@@ -1,11 +1,12 @@ | |||
1 | use ra_syntax::{AstNode, AstPtr, ast}; | 1 | use ra_syntax::{AstNode, AstPtr, ast}; |
2 | use hir::Either; | 2 | use hir::Either; |
3 | use crate::db::RootDatabase; | ||
4 | use test_utils::tested_by; | 3 | use test_utils::tested_by; |
5 | 4 | ||
5 | use crate::db::RootDatabase; | ||
6 | |||
6 | pub enum NameRefKind { | 7 | pub enum NameRefKind { |
7 | Method(hir::Function), | 8 | Method(hir::Function), |
8 | Macro(hir::MacroByExampleDef), | 9 | Macro(hir::MacroDef), |
9 | FieldAccess(hir::StructField), | 10 | FieldAccess(hir::StructField), |
10 | AssocItem(hir::ImplItem), | 11 | AssocItem(hir::ImplItem), |
11 | Def(hir::ModuleDef), | 12 | Def(hir::ModuleDef), |