aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/attr.rs3
-rw-r--r--crates/ra_hir_def/src/hygiene.rs40
-rw-r--r--crates/ra_hir_def/src/lib.rs1
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs6
-rw-r--r--crates/ra_hir_def/src/path.rs3
5 files changed, 6 insertions, 47 deletions
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
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_expand::hygiene::Hygiene;
5use mbe::ast_to_token_tree; 6use mbe::ast_to_token_tree;
6use ra_cfg::CfgOptions; 7use ra_cfg::CfgOptions;
7use ra_syntax::{ 8use ra_syntax::{
@@ -10,7 +11,7 @@ use ra_syntax::{
10}; 11};
11use tt::Subtree; 12use tt::Subtree;
12 13
13use crate::{hygiene::Hygiene, path::Path}; 14use crate::path::Path;
14 15
15#[derive(Debug, Clone, PartialEq, Eq)] 16#[derive(Debug, Clone, PartialEq, Eq)]
16pub struct Attr { 17pub struct Attr {
diff --git a/crates/ra_hir_def/src/hygiene.rs b/crates/ra_hir_def/src/hygiene.rs
deleted file mode 100644
index 94de2c57c..000000000
--- a/crates/ra_hir_def/src/hygiene.rs
+++ /dev/null
@@ -1,40 +0,0 @@
1//! This modules handles hygiene information.
2//!
3//! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at
4//! this moment, this is horribly incomplete and handles only `$crate`.
5// Should this be moved to `hir_expand`? Seems like it.
6
7use hir_expand::{
8 db::AstDatabase,
9 either::Either,
10 name::{AsName, Name},
11 HirFileId,
12};
13use ra_db::CrateId;
14use ra_syntax::ast;
15
16#[derive(Debug)]
17pub struct Hygiene {
18 // This is what `$crate` expands to
19 def_crate: Option<CrateId>,
20}
21
22impl Hygiene {
23 pub fn new(db: &impl AstDatabase, file_id: HirFileId) -> Hygiene {
24 Hygiene { def_crate: file_id.macro_crate(db) }
25 }
26
27 pub(crate) fn new_unhygienic() -> Hygiene {
28 Hygiene { def_crate: None }
29 }
30
31 // FIXME: this should just return name
32 pub(crate) fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> {
33 if let Some(def_crate) = self.def_crate {
34 if name_ref.text() == "$crate" {
35 return Either::B(def_crate);
36 }
37 }
38 Either::A(name_ref.as_name())
39 }
40}
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;
11pub mod attr; 11pub mod attr;
12pub mod path; 12pub mod path;
13pub mod type_ref; 13pub mod type_ref;
14pub mod hygiene;
15 14
16// FIXME: this should be private 15// FIXME: this should be private
17pub mod nameres; 16pub 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};
11use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; 12use 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
17use crate::{ 18use 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
5use hir_expand::{ 5use hir_expand::{
6 either::Either, 6 either::Either,
7 hygiene::Hygiene,
7 name::{self, AsName, Name}, 8 name::{self, AsName, Name},
8}; 9};
9use ra_db::CrateId; 10use ra_db::CrateId;
@@ -12,7 +13,7 @@ use ra_syntax::{
12 AstNode, 13 AstNode,
13}; 14};
14 15
15use crate::{hygiene::Hygiene, type_ref::TypeRef, Source}; 16use crate::{type_ref::TypeRef, Source};
16 17
17#[derive(Debug, Clone, PartialEq, Eq, Hash)] 18#[derive(Debug, Clone, PartialEq, Eq, Hash)]
18pub struct Path { 19pub struct Path {