diff options
Diffstat (limited to 'crates/ra_analysis/src/hir')
-rw-r--r-- | crates/ra_analysis/src/hir/db.rs | 2 | ||||
-rw-r--r-- | crates/ra_analysis/src/hir/function/mod.rs | 3 | ||||
-rw-r--r-- | crates/ra_analysis/src/hir/mod.rs | 45 | ||||
-rw-r--r-- | crates/ra_analysis/src/hir/module/mod.rs | 3 | ||||
-rw-r--r-- | crates/ra_analysis/src/hir/module/nameres.rs | 2 | ||||
-rw-r--r-- | crates/ra_analysis/src/hir/query_definitions.rs | 3 |
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}; | |||
9 | use crate::{ | 9 | use 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 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | hir::{HirDatabase, SourceItemId}, | 14 | hir::{FnId, HirDatabase, SourceItemId}, |
15 | FileId, | 15 | FileId, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | pub(crate) use self::scope::FnScopes; | 18 | pub(crate) use self::scope::FnScopes; |
19 | pub(crate) use crate::loc2id::FnId; | ||
20 | 19 | ||
21 | impl FnId { | 20 | impl 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; | |||
14 | use std::ops::Index; | 14 | use std::ops::Index; |
15 | 15 | ||
16 | use ra_syntax::{SyntaxNodeRef, SyntaxNode}; | 16 | use ra_syntax::{SyntaxNodeRef, SyntaxNode}; |
17 | use ra_db::{LocationIntener, SourceRootId}; | ||
17 | 18 | ||
18 | use crate::{ | 19 | use 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 | ||
32 | pub use self::function::FnSignatureInfo; | 32 | pub use self::function::FnSignatureInfo; |
33 | 33 | ||
34 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
35 | pub(crate) struct FnId(u32); | ||
36 | ra_db::impl_numeric_id!(FnId); | ||
37 | |||
38 | impl 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)] | ||
51 | pub(crate) struct DefId(u32); | ||
52 | ra_db::impl_numeric_id!(DefId); | ||
53 | |||
54 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
55 | pub(crate) enum DefLoc { | ||
56 | Module { | ||
57 | id: ModuleId, | ||
58 | source_root: SourceRootId, | ||
59 | }, | ||
60 | Item { | ||
61 | source_item_id: SourceItemId, | ||
62 | }, | ||
63 | } | ||
64 | |||
65 | impl DefId { | ||
66 | pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc { | ||
67 | db.as_ref().id2loc(self) | ||
68 | } | ||
69 | } | ||
70 | |||
71 | impl DefLoc { | ||
72 | pub(crate) fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId { | ||
73 | db.as_ref().loc2id(&self) | ||
74 | } | ||
75 | } | ||
76 | |||
34 | pub(crate) enum Def { | 77 | pub(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 | ||
16 | use crate::{ | 16 | use 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 | ||
23 | pub(crate) use self::nameres::ModuleScope; | 22 | pub(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 | ||
29 | use crate::{ | 29 | use 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; | |||
13 | use crate::{ | 13 | use 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, |