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/adt.rs2
-rw-r--r--crates/ra_hir_def/src/attr.rs3
-rw-r--r--crates/ra_hir_def/src/body.rs3
-rw-r--r--crates/ra_hir_def/src/data.rs5
-rw-r--r--crates/ra_hir_def/src/docs.rs6
-rw-r--r--crates/ra_hir_def/src/generics.rs3
-rw-r--r--crates/ra_hir_def/src/lib.rs54
-rw-r--r--crates/ra_hir_def/src/src.rs54
8 files changed, 72 insertions, 58 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index 3d21dedee..9ab829aab 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -11,7 +11,7 @@ use ra_arena::{map::ArenaMap, Arena};
11use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; 11use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
12 12
13use crate::{ 13use crate::{
14 db::DefDatabase, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId, HasChildSource, 14 db::DefDatabase, src::HasChildSource, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId,
15 LocalEnumVariantId, LocalStructFieldId, StructId, UnionId, VariantId, 15 LocalEnumVariantId, LocalStructFieldId, StructId, UnionId, VariantId,
16}; 16};
17 17
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index 346019f88..bc7ade921 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -11,7 +11,8 @@ use ra_syntax::{
11use tt::Subtree; 11use tt::Subtree;
12 12
13use crate::{ 13use crate::{
14 db::DefDatabase, path::Path, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup, 14 db::DefDatabase, path::Path, src::HasChildSource, src::HasSource, AdtId, AstItemDef, AttrDefId,
15 Lookup,
15}; 16};
16 17
17#[derive(Default, Debug, Clone, PartialEq, Eq)] 18#[derive(Default, Debug, Clone, PartialEq, Eq)]
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index f21937f10..69508dd8a 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -17,7 +17,8 @@ use crate::{
17 expr::{Expr, ExprId, Pat, PatId}, 17 expr::{Expr, ExprId, Pat, PatId},
18 nameres::CrateDefMap, 18 nameres::CrateDefMap,
19 path::Path, 19 path::Path,
20 DefWithBodyId, HasModule, HasSource, Lookup, ModuleId, 20 src::HasSource,
21 DefWithBodyId, HasModule, Lookup, ModuleId,
21}; 22};
22 23
23struct Expander { 24struct Expander {
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs
index fee10b237..095d7064a 100644
--- a/crates/ra_hir_def/src/data.rs
+++ b/crates/ra_hir_def/src/data.rs
@@ -10,9 +10,10 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
10 10
11use crate::{ 11use crate::{
12 db::DefDatabase, 12 db::DefDatabase,
13 src::HasSource,
13 type_ref::{Mutability, TypeRef}, 14 type_ref::{Mutability, TypeRef},
14 AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource, 15 AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, ImplId,
15 ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc, 16 Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
16}; 17};
17 18
18#[derive(Debug, Clone, PartialEq, Eq)] 19#[derive(Debug, Clone, PartialEq, Eq)]
diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs
index 34ed9b7a5..ec944373d 100644
--- a/crates/ra_hir_def/src/docs.rs
+++ b/crates/ra_hir_def/src/docs.rs
@@ -8,7 +8,11 @@ use std::sync::Arc;
8use hir_expand::either::Either; 8use hir_expand::either::Either;
9use ra_syntax::ast; 9use ra_syntax::ast;
10 10
11use crate::{db::DefDatabase, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup}; 11use crate::{
12 db::DefDatabase,
13 src::{HasChildSource, HasSource},
14 AdtId, AstItemDef, AttrDefId, Lookup,
15};
12 16
13/// Holds documentation 17/// Holds documentation
14#[derive(Debug, Clone, PartialEq, Eq)] 18#[derive(Debug, Clone, PartialEq, Eq)]
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs
index 3f94e40e4..5f648ffc3 100644
--- a/crates/ra_hir_def/src/generics.rs
+++ b/crates/ra_hir_def/src/generics.rs
@@ -9,8 +9,9 @@ use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner};
9 9
10use crate::{ 10use crate::{
11 db::DefDatabase, 11 db::DefDatabase,
12 src::HasSource,
12 type_ref::{TypeBound, TypeRef}, 13 type_ref::{TypeBound, TypeRef},
13 AdtId, AstItemDef, ContainerId, GenericDefId, HasSource, Lookup, 14 AdtId, AstItemDef, ContainerId, GenericDefId, Lookup,
14}; 15};
15 16
16/// Data about a generic parameter (to a function, struct, impl, ...). 17/// Data about a generic parameter (to a function, struct, impl, ...).
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 6daf7d3a3..cfeacfded 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -29,6 +29,8 @@ pub mod resolver;
29mod trace; 29mod trace;
30pub mod nameres; 30pub mod nameres;
31 31
32pub mod src;
33
32#[cfg(test)] 34#[cfg(test)]
33mod test_db; 35mod test_db;
34#[cfg(test)] 36#[cfg(test)]
@@ -37,7 +39,7 @@ mod marks;
37use std::hash::{Hash, Hasher}; 39use std::hash::{Hash, Hasher};
38 40
39use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, InFile, MacroDefId}; 41use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, InFile, MacroDefId};
40use ra_arena::{impl_arena_id, map::ArenaMap, RawId}; 42use ra_arena::{impl_arena_id, RawId};
41use ra_db::{impl_intern_key, salsa, CrateId}; 43use ra_db::{impl_intern_key, salsa, CrateId};
42use ra_syntax::{ast, AstNode}; 44use ra_syntax::{ast, AstNode};
43 45
@@ -514,53 +516,3 @@ impl HasModule for StaticLoc {
514 self.container 516 self.container
515 } 517 }
516} 518}
517
518pub trait HasSource {
519 type Value;
520 fn source(&self, db: &impl db::DefDatabase) -> InFile<Self::Value>;
521}
522
523impl HasSource for FunctionLoc {
524 type Value = ast::FnDef;
525
526 fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::FnDef> {
527 let node = self.ast_id.to_node(db);
528 InFile::new(self.ast_id.file_id, node)
529 }
530}
531
532impl HasSource for TypeAliasLoc {
533 type Value = ast::TypeAliasDef;
534
535 fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::TypeAliasDef> {
536 let node = self.ast_id.to_node(db);
537 InFile::new(self.ast_id.file_id, node)
538 }
539}
540
541impl HasSource for ConstLoc {
542 type Value = ast::ConstDef;
543
544 fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::ConstDef> {
545 let node = self.ast_id.to_node(db);
546 InFile::new(self.ast_id.file_id, node)
547 }
548}
549
550impl HasSource for StaticLoc {
551 type Value = ast::StaticDef;
552
553 fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::StaticDef> {
554 let node = self.ast_id.to_node(db);
555 InFile::new(self.ast_id.file_id, node)
556 }
557}
558
559pub trait HasChildSource {
560 type ChildId;
561 type Value;
562 fn child_source(
563 &self,
564 db: &impl db::DefDatabase,
565 ) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
566}
diff --git a/crates/ra_hir_def/src/src.rs b/crates/ra_hir_def/src/src.rs
new file mode 100644
index 000000000..27caa02cc
--- /dev/null
+++ b/crates/ra_hir_def/src/src.rs
@@ -0,0 +1,54 @@
1//! Utilities for mapping between hir IDs and the surface syntax.
2
3use hir_expand::InFile;
4use ra_arena::map::ArenaMap;
5use ra_syntax::ast;
6
7use crate::{db::DefDatabase, ConstLoc, FunctionLoc, StaticLoc, TypeAliasLoc};
8
9pub trait HasSource {
10 type Value;
11 fn source(&self, db: &impl DefDatabase) -> InFile<Self::Value>;
12}
13
14impl HasSource for FunctionLoc {
15 type Value = ast::FnDef;
16
17 fn source(&self, db: &impl DefDatabase) -> InFile<ast::FnDef> {
18 let node = self.ast_id.to_node(db);
19 InFile::new(self.ast_id.file_id, node)
20 }
21}
22
23impl HasSource for TypeAliasLoc {
24 type Value = ast::TypeAliasDef;
25
26 fn source(&self, db: &impl DefDatabase) -> InFile<ast::TypeAliasDef> {
27 let node = self.ast_id.to_node(db);
28 InFile::new(self.ast_id.file_id, node)
29 }
30}
31
32impl HasSource for ConstLoc {
33 type Value = ast::ConstDef;
34
35 fn source(&self, db: &impl DefDatabase) -> InFile<ast::ConstDef> {
36 let node = self.ast_id.to_node(db);
37 InFile::new(self.ast_id.file_id, node)
38 }
39}
40
41impl HasSource for StaticLoc {
42 type Value = ast::StaticDef;
43
44 fn source(&self, db: &impl DefDatabase) -> InFile<ast::StaticDef> {
45 let node = self.ast_id.to_node(db);
46 InFile::new(self.ast_id.file_id, node)
47 }
48}
49
50pub trait HasChildSource {
51 type ChildId;
52 type Value;
53 fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
54}