diff options
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r-- | crates/ra_analysis/src/db.rs | 9 | ||||
-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 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_analysis/src/loc2id.rs | 69 |
9 files changed, 57 insertions, 80 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 1b2dd4b3d..2bc1c8f8f 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs | |||
@@ -5,9 +5,8 @@ use salsa::{self, Database}; | |||
5 | use ra_db::{LocationIntener, BaseDatabase}; | 5 | use ra_db::{LocationIntener, BaseDatabase}; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | hir, | 8 | hir::{self, DefId, DefLoc, FnId, SourceItemId}, |
9 | symbol_index, | 9 | symbol_index, |
10 | loc2id::{IdMaps, DefId, DefLoc, FnId}, | ||
11 | }; | 10 | }; |
12 | 11 | ||
13 | #[derive(Debug)] | 12 | #[derive(Debug)] |
@@ -21,6 +20,12 @@ pub(crate) struct RootDatabase { | |||
21 | id_maps: Arc<IdMaps>, | 20 | id_maps: Arc<IdMaps>, |
22 | } | 21 | } |
23 | 22 | ||
23 | #[derive(Debug, Default)] | ||
24 | struct IdMaps { | ||
25 | fns: LocationIntener<SourceItemId, FnId>, | ||
26 | defs: LocationIntener<DefLoc, DefId>, | ||
27 | } | ||
28 | |||
24 | impl salsa::Database for RootDatabase { | 29 | impl salsa::Database for RootDatabase { |
25 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { | 30 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { |
26 | &self.runtime | 31 | &self.runtime |
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, |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 012d36b8e..5b6e4df8c 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -20,7 +20,6 @@ macro_rules! ctry { | |||
20 | 20 | ||
21 | mod arena; | 21 | mod arena; |
22 | mod db; | 22 | mod db; |
23 | mod loc2id; | ||
24 | mod imp; | 23 | mod imp; |
25 | mod completion; | 24 | mod completion; |
26 | mod hir; | 25 | mod hir; |
diff --git a/crates/ra_analysis/src/loc2id.rs b/crates/ra_analysis/src/loc2id.rs deleted file mode 100644 index 7956431ab..000000000 --- a/crates/ra_analysis/src/loc2id.rs +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | use ra_db::SourceRootId; | ||
2 | |||
3 | use crate::{ | ||
4 | hir::{SourceItemId, ModuleId}, | ||
5 | }; | ||
6 | |||
7 | use ra_db::{NumericId, LocationIntener}; | ||
8 | |||
9 | macro_rules! impl_numeric_id { | ||
10 | ($id:ident) => { | ||
11 | impl NumericId for $id { | ||
12 | fn from_u32(id: u32) -> Self { | ||
13 | $id(id) | ||
14 | } | ||
15 | fn to_u32(self) -> u32 { | ||
16 | self.0 | ||
17 | } | ||
18 | } | ||
19 | }; | ||
20 | } | ||
21 | |||
22 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
23 | pub(crate) struct FnId(u32); | ||
24 | impl_numeric_id!(FnId); | ||
25 | |||
26 | impl FnId { | ||
27 | pub(crate) fn from_loc( | ||
28 | db: &impl AsRef<LocationIntener<SourceItemId, FnId>>, | ||
29 | loc: &SourceItemId, | ||
30 | ) -> FnId { | ||
31 | db.as_ref().loc2id(loc) | ||
32 | } | ||
33 | pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<SourceItemId, FnId>>) -> SourceItemId { | ||
34 | db.as_ref().id2loc(self) | ||
35 | } | ||
36 | } | ||
37 | |||
38 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
39 | pub(crate) struct DefId(u32); | ||
40 | impl_numeric_id!(DefId); | ||
41 | |||
42 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
43 | pub(crate) enum DefLoc { | ||
44 | Module { | ||
45 | id: ModuleId, | ||
46 | source_root: SourceRootId, | ||
47 | }, | ||
48 | Item { | ||
49 | source_item_id: SourceItemId, | ||
50 | }, | ||
51 | } | ||
52 | |||
53 | impl DefId { | ||
54 | pub(crate) fn loc(self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefLoc { | ||
55 | db.as_ref().id2loc(self) | ||
56 | } | ||
57 | } | ||
58 | |||
59 | impl DefLoc { | ||
60 | pub(crate) fn id(&self, db: &impl AsRef<LocationIntener<DefLoc, DefId>>) -> DefId { | ||
61 | db.as_ref().loc2id(&self) | ||
62 | } | ||
63 | } | ||
64 | |||
65 | #[derive(Debug, Default)] | ||
66 | pub(crate) struct IdMaps { | ||
67 | pub(crate) fns: LocationIntener<SourceItemId, FnId>, | ||
68 | pub(crate) defs: LocationIntener<DefLoc, DefId>, | ||
69 | } | ||