aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/hir')
-rw-r--r--crates/ra_analysis/src/hir/db.rs2
-rw-r--r--crates/ra_analysis/src/hir/function/mod.rs3
-rw-r--r--crates/ra_analysis/src/hir/mod.rs45
-rw-r--r--crates/ra_analysis/src/hir/module/mod.rs3
-rw-r--r--crates/ra_analysis/src/hir/module/nameres.rs2
-rw-r--r--crates/ra_analysis/src/hir/query_definitions.rs3
6 files changed, 50 insertions, 8 deletions
diff --git a/crates/ra_analysis/src/hir/db.rs b/crates/ra_analysis/src/hir/db.rs
index 0ae2086ff..c8ae551c5 100644
--- a/crates/ra_analysis/src/hir/db.rs
+++ b/crates/ra_analysis/src/hir/db.rs
@@ -9,13 +9,13 @@ use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase};
9use crate::{ 9use crate::{
10 FileId, 10 FileId,
11 hir::{ 11 hir::{
12 DefLoc, DefId, FnId,
12 SourceFileItems, SourceItemId, 13 SourceFileItems, SourceItemId,
13 query_definitions, 14 query_definitions,
14 function::{FnScopes}, 15 function::{FnScopes},
15 module::{ModuleId, ModuleTree, ModuleSource, 16 module::{ModuleId, ModuleTree, ModuleSource,
16 nameres::{ItemMap, InputModuleItems}}, 17 nameres::{ItemMap, InputModuleItems}},
17 }, 18 },
18 loc2id::{DefLoc, DefId, FnId},
19 Cancelable, 19 Cancelable,
20}; 20};
21 21
diff --git a/crates/ra_analysis/src/hir/function/mod.rs b/crates/ra_analysis/src/hir/function/mod.rs
index e64a9f045..a399d2a9e 100644
--- a/crates/ra_analysis/src/hir/function/mod.rs
+++ b/crates/ra_analysis/src/hir/function/mod.rs
@@ -11,12 +11,11 @@ use ra_syntax::{
11}; 11};
12 12
13use crate::{ 13use crate::{
14 hir::{HirDatabase, SourceItemId}, 14 hir::{FnId, HirDatabase, SourceItemId},
15 FileId, 15 FileId,
16}; 16};
17 17
18pub(crate) use self::scope::FnScopes; 18pub(crate) use self::scope::FnScopes;
19pub(crate) use crate::loc2id::FnId;
20 19
21impl FnId { 20impl FnId {
22 pub(crate) fn get(db: &impl HirDatabase, file_id: FileId, fn_def: ast::FnDef) -> FnId { 21 pub(crate) fn get(db: &impl HirDatabase, file_id: FileId, fn_def: ast::FnDef) -> FnId {
diff --git a/crates/ra_analysis/src/hir/mod.rs b/crates/ra_analysis/src/hir/mod.rs
index 61e6c9913..83131384d 100644
--- a/crates/ra_analysis/src/hir/mod.rs
+++ b/crates/ra_analysis/src/hir/mod.rs
@@ -14,11 +14,11 @@ mod path;
14use std::ops::Index; 14use std::ops::Index;
15 15
16use ra_syntax::{SyntaxNodeRef, SyntaxNode}; 16use ra_syntax::{SyntaxNodeRef, SyntaxNode};
17use ra_db::{LocationIntener, SourceRootId};
17 18
18use crate::{ 19use crate::{
19 FileId, 20 FileId,
20 hir::db::HirDatabase, 21 hir::db::HirDatabase,
21 loc2id::{DefId, DefLoc},
22 Cancelable, 22 Cancelable,
23 arena::{Arena, Id}, 23 arena::{Arena, Id},
24}; 24};
@@ -31,6 +31,49 @@ pub(crate) use self::{
31 31
32pub use self::function::FnSignatureInfo; 32pub use self::function::FnSignatureInfo;
33 33
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
35pub(crate) struct FnId(u32);
36ra_db::impl_numeric_id!(FnId);
37
38impl FnId {
39 pub(crate) fn from_loc(
40 db: &impl AsRef<LocationIntener<SourceItemId, FnId>>,
41 loc: &SourceItemId,
42 ) -> FnId {
43 db.as_ref().loc2id(loc)
44 }
45 pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<SourceItemId, FnId>>) -> SourceItemId {
46 db.as_ref().id2loc(self)
47 }
48}
49
50#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
51pub(crate) struct DefId(u32);
52ra_db::impl_numeric_id!(DefId);
53
54#[derive(Clone, Debug, PartialEq, Eq, Hash)]
55pub(crate) enum DefLoc {
56 Module {
57 id: ModuleId,
58 source_root: SourceRootId,
59 },
60 Item {
61 source_item_id: SourceItemId,
62 },
63}
64
65impl DefId {
66 pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc {
67 db.as_ref().id2loc(self)
68 }
69}
70
71impl DefLoc {
72 pub(crate) fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId {
73 db.as_ref().loc2id(&self)
74 }
75}
76
34pub(crate) enum Def { 77pub(crate) enum Def {
35 Module(Module), 78 Module(Module),
36 Item, 79 Item,
diff --git a/crates/ra_analysis/src/hir/module/mod.rs b/crates/ra_analysis/src/hir/module/mod.rs
index 683cb5d4c..d2096b01e 100644
--- a/crates/ra_analysis/src/hir/module/mod.rs
+++ b/crates/ra_analysis/src/hir/module/mod.rs
@@ -15,9 +15,8 @@ use relative_path::RelativePathBuf;
15 15
16use crate::{ 16use crate::{
17 FileId, FilePosition, Cancelable, 17 FileId, FilePosition, Cancelable,
18 hir::{Path, PathKind, HirDatabase, SourceItemId}, 18 hir::{DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId},
19 arena::{Arena, Id}, 19 arena::{Arena, Id},
20 loc2id::{DefLoc, DefId},
21}; 20};
22 21
23pub(crate) use self::nameres::ModuleScope; 22pub(crate) use self::nameres::ModuleScope;
diff --git a/crates/ra_analysis/src/hir/module/nameres.rs b/crates/ra_analysis/src/hir/module/nameres.rs
index 5c87e7af2..d4ecc010b 100644
--- a/crates/ra_analysis/src/hir/module/nameres.rs
+++ b/crates/ra_analysis/src/hir/module/nameres.rs
@@ -28,8 +28,8 @@ use ra_db::SourceRootId;
28 28
29use crate::{ 29use crate::{
30 Cancelable, FileId, 30 Cancelable, FileId,
31 loc2id::{DefId, DefLoc},
32 hir::{ 31 hir::{
32 DefId, DefLoc,
33 SourceItemId, SourceFileItemId, SourceFileItems, 33 SourceItemId, SourceFileItemId, SourceFileItems,
34 Path, PathKind, 34 Path, PathKind,
35 HirDatabase, 35 HirDatabase,
diff --git a/crates/ra_analysis/src/hir/query_definitions.rs b/crates/ra_analysis/src/hir/query_definitions.rs
index fbdf8eb67..00237b633 100644
--- a/crates/ra_analysis/src/hir/query_definitions.rs
+++ b/crates/ra_analysis/src/hir/query_definitions.rs
@@ -13,9 +13,10 @@ use ra_db::SourceRootId;
13use crate::{ 13use crate::{
14 FileId, Cancelable, 14 FileId, Cancelable,
15 hir::{ 15 hir::{
16 FnId,
16 SourceFileItems, SourceItemId, 17 SourceFileItems, SourceItemId,
17 db::HirDatabase, 18 db::HirDatabase,
18 function::{FnId, FnScopes}, 19 function::FnScopes,
19 module::{ 20 module::{
20 ModuleSource, ModuleSourceNode, ModuleId, 21 ModuleSource, ModuleSourceNode, ModuleId,
21 imp::Submodule, 22 imp::Submodule,