diff options
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir_def/src/db.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir_def/src/type_alias.rs (renamed from crates/ra_hir/src/type_alias.rs) | 16 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/builtin_macro.rs | 27 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/name.rs | 1 |
8 files changed, 44 insertions, 20 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 5690040a7..72c9b466f 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -937,7 +937,7 @@ impl TypeAlias { | |||
937 | } | 937 | } |
938 | 938 | ||
939 | pub fn type_ref(self, db: &impl DefDatabase) -> Option<TypeRef> { | 939 | pub fn type_ref(self, db: &impl DefDatabase) -> Option<TypeRef> { |
940 | db.type_alias_data(self).type_ref.clone() | 940 | db.type_alias_data(self.id).type_ref.clone() |
941 | } | 941 | } |
942 | 942 | ||
943 | pub fn ty(self, db: &impl HirDatabase) -> Ty { | 943 | pub fn ty(self, db: &impl HirDatabase) -> Ty { |
@@ -945,7 +945,7 @@ impl TypeAlias { | |||
945 | } | 945 | } |
946 | 946 | ||
947 | pub fn name(self, db: &impl DefDatabase) -> Name { | 947 | pub fn name(self, db: &impl DefDatabase) -> Name { |
948 | db.type_alias_data(self).name.clone() | 948 | db.type_alias_data(self.id).name.clone() |
949 | } | 949 | } |
950 | } | 950 | } |
951 | 951 | ||
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 1f63be3b9..1cfcb2fd2 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -16,16 +16,15 @@ use crate::{ | |||
16 | CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef, | 16 | CallableDef, FnSig, GenericPredicate, InferenceResult, Namespace, Substs, Ty, TypableDef, |
17 | TypeCtor, | 17 | TypeCtor, |
18 | }, | 18 | }, |
19 | type_alias::TypeAliasData, | ||
20 | Const, ConstData, Crate, DefWithBody, FnData, Function, GenericDef, ImplBlock, Module, Static, | 19 | Const, ConstData, Crate, DefWithBody, FnData, Function, GenericDef, ImplBlock, Module, Static, |
21 | StructField, Trait, TypeAlias, | 20 | StructField, Trait, |
22 | }; | 21 | }; |
23 | 22 | ||
24 | pub use hir_def::db::{ | 23 | pub use hir_def::db::{ |
25 | BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage, | 24 | BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage, |
26 | EnumDataQuery, ExprScopesQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, | 25 | EnumDataQuery, ExprScopesQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, |
27 | InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery, | 26 | InternDatabaseStorage, RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery, |
28 | TraitDataQuery, | 27 | TraitDataQuery, TypeAliasDataQuery, |
29 | }; | 28 | }; |
30 | pub use hir_expand::db::{ | 29 | pub use hir_expand::db::{ |
31 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, | 30 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, |
@@ -39,9 +38,6 @@ pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { | |||
39 | #[salsa::invoke(FnData::fn_data_query)] | 38 | #[salsa::invoke(FnData::fn_data_query)] |
40 | fn fn_data(&self, func: Function) -> Arc<FnData>; | 39 | fn fn_data(&self, func: Function) -> Arc<FnData>; |
41 | 40 | ||
42 | #[salsa::invoke(TypeAliasData::type_alias_data_query)] | ||
43 | fn type_alias_data(&self, typ: TypeAlias) -> Arc<TypeAliasData>; | ||
44 | |||
45 | #[salsa::invoke(ConstData::const_data_query)] | 41 | #[salsa::invoke(ConstData::const_data_query)] |
46 | fn const_data(&self, konst: Const) -> Arc<ConstData>; | 42 | fn const_data(&self, konst: Const) -> Arc<ConstData>; |
47 | 43 | ||
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 915ca46fb..8535629ca 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -32,7 +32,6 @@ pub mod db; | |||
32 | pub mod source_binder; | 32 | pub mod source_binder; |
33 | 33 | ||
34 | mod ids; | 34 | mod ids; |
35 | mod type_alias; | ||
36 | mod ty; | 35 | mod ty; |
37 | mod impl_block; | 36 | mod impl_block; |
38 | mod expr; | 37 | mod expr; |
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index 844f8bbe8..5bbdaa4b2 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs | |||
@@ -15,7 +15,8 @@ use crate::{ | |||
15 | CrateDefMap, | 15 | CrateDefMap, |
16 | }, | 16 | }, |
17 | traits::TraitData, | 17 | traits::TraitData, |
18 | DefWithBodyId, EnumId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId, | 18 | type_alias::TypeAliasData, |
19 | DefWithBodyId, EnumId, GenericDefId, ImplId, ItemLoc, StructOrUnionId, TraitId, TypeAliasId, | ||
19 | }; | 20 | }; |
20 | 21 | ||
21 | #[salsa::query_group(InternDatabaseStorage)] | 22 | #[salsa::query_group(InternDatabaseStorage)] |
@@ -64,6 +65,9 @@ pub trait DefDatabase2: InternDatabase + AstDatabase { | |||
64 | #[salsa::invoke(TraitData::trait_data_query)] | 65 | #[salsa::invoke(TraitData::trait_data_query)] |
65 | fn trait_data(&self, e: TraitId) -> Arc<TraitData>; | 66 | fn trait_data(&self, e: TraitId) -> Arc<TraitData>; |
66 | 67 | ||
68 | #[salsa::invoke(TypeAliasData::type_alias_data_query)] | ||
69 | fn type_alias_data(&self, e: TypeAliasId) -> Arc<TypeAliasData>; | ||
70 | |||
67 | #[salsa::invoke(Body::body_with_source_map_query)] | 71 | #[salsa::invoke(Body::body_with_source_map_query)] |
68 | fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>); | 72 | fn body_with_source_map(&self, def: DefWithBodyId) -> (Arc<Body>, Arc<BodySourceMap>); |
69 | 73 | ||
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index d579f5c7e..268144462 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -20,6 +20,7 @@ pub mod body; | |||
20 | pub mod generics; | 20 | pub mod generics; |
21 | pub mod traits; | 21 | pub mod traits; |
22 | pub mod resolver; | 22 | pub mod resolver; |
23 | pub mod type_alias; | ||
23 | 24 | ||
24 | #[cfg(test)] | 25 | #[cfg(test)] |
25 | mod test_db; | 26 | mod test_db; |
diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir_def/src/type_alias.rs index 392f244cf..c0b49aa7c 100644 --- a/crates/ra_hir/src/type_alias.rs +++ b/crates/ra_hir_def/src/type_alias.rs | |||
@@ -2,28 +2,24 @@ | |||
2 | 2 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use hir_def::type_ref::TypeRef; | ||
6 | use hir_expand::name::{AsName, Name}; | 5 | use hir_expand::name::{AsName, Name}; |
7 | 6 | ||
8 | use ra_syntax::ast::NameOwner; | 7 | use ra_syntax::ast::NameOwner; |
9 | 8 | ||
10 | use crate::{ | 9 | use crate::{db::DefDatabase2, type_ref::TypeRef, HasSource, Lookup, TypeAliasId}; |
11 | db::{AstDatabase, DefDatabase}, | ||
12 | HasSource, TypeAlias, | ||
13 | }; | ||
14 | 10 | ||
15 | #[derive(Debug, Clone, PartialEq, Eq)] | 11 | #[derive(Debug, Clone, PartialEq, Eq)] |
16 | pub struct TypeAliasData { | 12 | pub struct TypeAliasData { |
17 | pub(crate) name: Name, | 13 | pub name: Name, |
18 | pub(crate) type_ref: Option<TypeRef>, | 14 | pub type_ref: Option<TypeRef>, |
19 | } | 15 | } |
20 | 16 | ||
21 | impl TypeAliasData { | 17 | impl TypeAliasData { |
22 | pub(crate) fn type_alias_data_query( | 18 | pub(crate) fn type_alias_data_query( |
23 | db: &(impl DefDatabase + AstDatabase), | 19 | db: &impl DefDatabase2, |
24 | typ: TypeAlias, | 20 | typ: TypeAliasId, |
25 | ) -> Arc<TypeAliasData> { | 21 | ) -> Arc<TypeAliasData> { |
26 | let node = typ.source(db).value; | 22 | let node = typ.lookup(db).source(db).value; |
27 | let name = node.name().map_or_else(Name::missing, |n| n.as_name()); | 23 | let name = node.name().map_or_else(Name::missing, |n| n.as_name()); |
28 | let type_ref = node.type_ref().map(TypeRef::from_ast); | 24 | let type_ref = node.type_ref().map(TypeRef::from_ast); |
29 | Arc::new(TypeAliasData { name, type_ref }) | 25 | Arc::new(TypeAliasData { name, type_ref }) |
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index 97fb0cb55..9628666d4 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs | |||
@@ -11,6 +11,7 @@ use crate::quote; | |||
11 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 11 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
12 | pub enum BuiltinExpander { | 12 | pub enum BuiltinExpander { |
13 | Line, | 13 | Line, |
14 | Stringify, | ||
14 | } | 15 | } |
15 | 16 | ||
16 | impl BuiltinExpander { | 17 | impl BuiltinExpander { |
@@ -22,6 +23,7 @@ impl BuiltinExpander { | |||
22 | ) -> Result<tt::Subtree, mbe::ExpandError> { | 23 | ) -> Result<tt::Subtree, mbe::ExpandError> { |
23 | match self { | 24 | match self { |
24 | BuiltinExpander::Line => line_expand(db, id, tt), | 25 | BuiltinExpander::Line => line_expand(db, id, tt), |
26 | BuiltinExpander::Stringify => stringify_expand(db, id, tt), | ||
25 | } | 27 | } |
26 | } | 28 | } |
27 | } | 29 | } |
@@ -34,6 +36,8 @@ pub fn find_builtin_macro( | |||
34 | // FIXME: Better registering method | 36 | // FIXME: Better registering method |
35 | if ident == &name::LINE_MACRO { | 37 | if ident == &name::LINE_MACRO { |
36 | Some(MacroDefId { krate, ast_id, kind: MacroDefKind::BuiltIn(BuiltinExpander::Line) }) | 38 | Some(MacroDefId { krate, ast_id, kind: MacroDefKind::BuiltIn(BuiltinExpander::Line) }) |
39 | } else if ident == &name::STRINGIFY_MACRO { | ||
40 | Some(MacroDefId { krate, ast_id, kind: MacroDefKind::BuiltIn(BuiltinExpander::Stringify) }) | ||
37 | } else { | 41 | } else { |
38 | None | 42 | None |
39 | } | 43 | } |
@@ -78,3 +82,26 @@ fn line_expand( | |||
78 | 82 | ||
79 | Ok(expanded) | 83 | Ok(expanded) |
80 | } | 84 | } |
85 | |||
86 | fn stringify_expand( | ||
87 | db: &dyn AstDatabase, | ||
88 | id: MacroCallId, | ||
89 | _tt: &tt::Subtree, | ||
90 | ) -> Result<tt::Subtree, mbe::ExpandError> { | ||
91 | let loc = db.lookup_intern_macro(id); | ||
92 | let macro_call = loc.ast_id.to_node(db); | ||
93 | |||
94 | let macro_content = { | ||
95 | let arg = macro_call.token_tree().ok_or_else(|| mbe::ExpandError::UnexpectedToken)?; | ||
96 | let macro_args = arg.syntax().clone(); | ||
97 | let text = macro_args.text(); | ||
98 | let without_parens = TextUnit::of_char('(')..text.len() - TextUnit::of_char(')'); | ||
99 | text.slice(without_parens).to_string() | ||
100 | }; | ||
101 | |||
102 | let expanded = quote! { | ||
103 | #macro_content | ||
104 | }; | ||
105 | |||
106 | Ok(expanded) | ||
107 | } | ||
diff --git a/crates/ra_hir_expand/src/name.rs b/crates/ra_hir_expand/src/name.rs index 1bf17d12b..c3f7e77a5 100644 --- a/crates/ra_hir_expand/src/name.rs +++ b/crates/ra_hir_expand/src/name.rs | |||
@@ -143,3 +143,4 @@ pub const BOX_TYPE: Name = Name::new_inline_ascii(3, b"Box"); | |||
143 | 143 | ||
144 | // Builtin Macros | 144 | // Builtin Macros |
145 | pub const LINE_MACRO: Name = Name::new_inline_ascii(4, b"line"); | 145 | pub const LINE_MACRO: Name = Name::new_inline_ascii(4, b"line"); |
146 | pub const STRINGIFY_MACRO: Name = Name::new_inline_ascii(9, b"stringify"); | ||