diff options
-rw-r--r-- | crates/ra_hir/src/expr/lower.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_def/src/attr.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/hygiene.rs (renamed from crates/ra_hir_def/src/hygiene.rs) | 22 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 12 |
8 files changed, 28 insertions, 29 deletions
diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs index 241ad68fd..6463dd65e 100644 --- a/crates/ra_hir/src/expr/lower.rs +++ b/crates/ra_hir/src/expr/lower.rs | |||
@@ -1,7 +1,10 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir_def::{hygiene::Hygiene, path::GenericArgs, type_ref::TypeRef}; | 3 | use hir_def::{path::GenericArgs, type_ref::TypeRef}; |
4 | use hir_expand::name::{self, AsName, Name}; | 4 | use hir_expand::{ |
5 | hygiene::Hygiene, | ||
6 | name::{self, AsName, Name}, | ||
7 | }; | ||
5 | use ra_arena::Arena; | 8 | use ra_arena::Arena; |
6 | use ra_syntax::{ | 9 | use ra_syntax::{ |
7 | ast::{ | 10 | ast::{ |
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 9e4a40017..b1a014074 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -3,7 +3,8 @@ | |||
3 | use rustc_hash::FxHashMap; | 3 | use rustc_hash::FxHashMap; |
4 | use std::sync::Arc; | 4 | use std::sync::Arc; |
5 | 5 | ||
6 | use hir_def::{attr::Attr, hygiene::Hygiene, type_ref::TypeRef}; | 6 | use hir_def::{attr::Attr, type_ref::TypeRef}; |
7 | use hir_expand::hygiene::Hygiene; | ||
7 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 8 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; |
8 | use ra_cfg::CfgOptions; | 9 | use ra_cfg::CfgOptions; |
9 | use ra_syntax::{ | 10 | use ra_syntax::{ |
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index 71f92adc2..0e961ca12 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use hir_expand::hygiene::Hygiene; | ||
5 | use mbe::ast_to_token_tree; | 6 | use mbe::ast_to_token_tree; |
6 | use ra_cfg::CfgOptions; | 7 | use ra_cfg::CfgOptions; |
7 | use ra_syntax::{ | 8 | use ra_syntax::{ |
@@ -10,7 +11,7 @@ use ra_syntax::{ | |||
10 | }; | 11 | }; |
11 | use tt::Subtree; | 12 | use tt::Subtree; |
12 | 13 | ||
13 | use crate::{hygiene::Hygiene, path::Path}; | 14 | use crate::path::Path; |
14 | 15 | ||
15 | #[derive(Debug, Clone, PartialEq, Eq)] | 16 | #[derive(Debug, Clone, PartialEq, Eq)] |
16 | pub struct Attr { | 17 | pub struct Attr { |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 5135dda56..7a6c7b301 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -11,7 +11,6 @@ pub mod db; | |||
11 | pub mod attr; | 11 | pub mod attr; |
12 | pub mod path; | 12 | pub mod path; |
13 | pub mod type_ref; | 13 | pub mod type_ref; |
14 | pub mod hygiene; | ||
15 | 14 | ||
16 | // FIXME: this should be private | 15 | // FIXME: this should be private |
17 | pub mod nameres; | 16 | pub mod nameres; |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 56831e409..86c05d602 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -6,6 +6,7 @@ use hir_expand::{ | |||
6 | ast_id_map::AstIdMap, | 6 | ast_id_map::AstIdMap, |
7 | db::AstDatabase, | 7 | db::AstDatabase, |
8 | either::Either, | 8 | either::Either, |
9 | hygiene::Hygiene, | ||
9 | name::{AsName, Name}, | 10 | name::{AsName, Name}, |
10 | }; | 11 | }; |
11 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 12 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; |
@@ -14,10 +15,7 @@ use ra_syntax::{ | |||
14 | AstNode, AstPtr, SourceFile, | 15 | AstNode, AstPtr, SourceFile, |
15 | }; | 16 | }; |
16 | 17 | ||
17 | use crate::{ | 18 | use crate::{attr::Attr, db::DefDatabase2, path::Path, FileAstId, HirFileId, ModuleSource, Source}; |
18 | attr::Attr, db::DefDatabase2, hygiene::Hygiene, path::Path, FileAstId, HirFileId, ModuleSource, | ||
19 | Source, | ||
20 | }; | ||
21 | 19 | ||
22 | /// `RawItems` is a set of top-level items in a file (except for impls). | 20 | /// `RawItems` is a set of top-level items in a file (except for impls). |
23 | /// | 21 | /// |
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index d0b842a6b..ddabc7ca6 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs | |||
@@ -4,6 +4,7 @@ use std::{iter, sync::Arc}; | |||
4 | 4 | ||
5 | use hir_expand::{ | 5 | use hir_expand::{ |
6 | either::Either, | 6 | either::Either, |
7 | hygiene::Hygiene, | ||
7 | name::{self, AsName, Name}, | 8 | name::{self, AsName, Name}, |
8 | }; | 9 | }; |
9 | use ra_db::CrateId; | 10 | use ra_db::CrateId; |
@@ -12,7 +13,7 @@ use ra_syntax::{ | |||
12 | AstNode, | 13 | AstNode, |
13 | }; | 14 | }; |
14 | 15 | ||
15 | use crate::{hygiene::Hygiene, type_ref::TypeRef, Source}; | 16 | use crate::{type_ref::TypeRef, Source}; |
16 | 17 | ||
17 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 18 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
18 | pub struct Path { | 19 | pub struct Path { |
diff --git a/crates/ra_hir_def/src/hygiene.rs b/crates/ra_hir_expand/src/hygiene.rs index 94de2c57c..77428ec99 100644 --- a/crates/ra_hir_def/src/hygiene.rs +++ b/crates/ra_hir_expand/src/hygiene.rs | |||
@@ -2,16 +2,15 @@ | |||
2 | //! | 2 | //! |
3 | //! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at | 3 | //! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at |
4 | //! this moment, this is horribly incomplete and handles only `$crate`. | 4 | //! this moment, this is horribly incomplete and handles only `$crate`. |
5 | // Should this be moved to `hir_expand`? Seems like it. | 5 | use ra_db::CrateId; |
6 | use ra_syntax::ast; | ||
6 | 7 | ||
7 | use hir_expand::{ | 8 | use crate::{ |
8 | db::AstDatabase, | 9 | db::AstDatabase, |
9 | either::Either, | 10 | either::Either, |
10 | name::{AsName, Name}, | 11 | name::{AsName, Name}, |
11 | HirFileId, | 12 | HirFileId, HirFileIdRepr, |
12 | }; | 13 | }; |
13 | use ra_db::CrateId; | ||
14 | use ra_syntax::ast; | ||
15 | 14 | ||
16 | #[derive(Debug)] | 15 | #[derive(Debug)] |
17 | pub struct Hygiene { | 16 | pub struct Hygiene { |
@@ -21,15 +20,22 @@ pub struct Hygiene { | |||
21 | 20 | ||
22 | impl Hygiene { | 21 | impl Hygiene { |
23 | pub fn new(db: &impl AstDatabase, file_id: HirFileId) -> Hygiene { | 22 | pub fn new(db: &impl AstDatabase, file_id: HirFileId) -> Hygiene { |
24 | Hygiene { def_crate: file_id.macro_crate(db) } | 23 | let def_crate = match file_id.0 { |
24 | HirFileIdRepr::FileId(_) => None, | ||
25 | HirFileIdRepr::MacroFile(macro_file) => { | ||
26 | let loc = db.lookup_intern_macro(macro_file.macro_call_id); | ||
27 | Some(loc.def.krate) | ||
28 | } | ||
29 | }; | ||
30 | Hygiene { def_crate } | ||
25 | } | 31 | } |
26 | 32 | ||
27 | pub(crate) fn new_unhygienic() -> Hygiene { | 33 | pub fn new_unhygienic() -> Hygiene { |
28 | Hygiene { def_crate: None } | 34 | Hygiene { def_crate: None } |
29 | } | 35 | } |
30 | 36 | ||
31 | // FIXME: this should just return name | 37 | // FIXME: this should just return name |
32 | pub(crate) fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> { | 38 | pub fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> { |
33 | if let Some(def_crate) = self.def_crate { | 39 | if let Some(def_crate) = self.def_crate { |
34 | if name_ref.text() == "$crate" { | 40 | if name_ref.text() == "$crate" { |
35 | return Either::B(def_crate); | 41 | return Either::B(def_crate); |
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index cf28de3d8..5a0e5a19c 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -8,6 +8,7 @@ pub mod db; | |||
8 | pub mod ast_id_map; | 8 | pub mod ast_id_map; |
9 | pub mod either; | 9 | pub mod either; |
10 | pub mod name; | 10 | pub mod name; |
11 | pub mod hygiene; | ||
11 | 12 | ||
12 | use std::hash::{Hash, Hasher}; | 13 | use std::hash::{Hash, Hasher}; |
13 | 14 | ||
@@ -61,17 +62,6 @@ impl HirFileId { | |||
61 | } | 62 | } |
62 | } | 63 | } |
63 | } | 64 | } |
64 | |||
65 | /// Get the crate which the macro lives in, if it is a macro file. | ||
66 | pub fn macro_crate(self, db: &dyn db::AstDatabase) -> Option<CrateId> { | ||
67 | match self.0 { | ||
68 | HirFileIdRepr::FileId(_) => None, | ||
69 | HirFileIdRepr::MacroFile(macro_file) => { | ||
70 | let loc = db.lookup_intern_macro(macro_file.macro_call_id); | ||
71 | Some(loc.def.krate) | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | } | 65 | } |
76 | 66 | ||
77 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 67 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |