diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-18 13:34:46 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-18 13:34:46 +0000 |
commit | 57a253f3f2d62a83fa63485b2fc75fc55b300bb3 (patch) | |
tree | 0ae3a1f3c92ce9e308934e023d6a24385b4260d6 /crates/ra_analysis/src/descriptors | |
parent | f1d8558cd5fe20a351496c39dbb8e15aa028803c (diff) | |
parent | 4e48917c00d24e1e1785e1959a2f3495a902410b (diff) |
Merge #232
232: Add id assignment infrastructure r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/descriptors')
-rw-r--r-- | crates/ra_analysis/src/descriptors/function/imp.rs | 4 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/function/mod.rs | 13 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/mod.rs | 3 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/mod.rs | 9 |
4 files changed, 20 insertions, 9 deletions
diff --git a/crates/ra_analysis/src/descriptors/function/imp.rs b/crates/ra_analysis/src/descriptors/function/imp.rs index a989a04cd..a7257acf9 100644 --- a/crates/ra_analysis/src/descriptors/function/imp.rs +++ b/crates/ra_analysis/src/descriptors/function/imp.rs | |||
@@ -8,9 +8,9 @@ use crate::descriptors::{ | |||
8 | }; | 8 | }; |
9 | 9 | ||
10 | /// Resolve `FnId` to the corresponding `SyntaxNode` | 10 | /// Resolve `FnId` to the corresponding `SyntaxNode` |
11 | /// TODO: this should return something more type-safe then `SyntaxNode` | ||
12 | pub(crate) fn fn_syntax(db: &impl DescriptorDatabase, fn_id: FnId) -> FnDefNode { | 11 | pub(crate) fn fn_syntax(db: &impl DescriptorDatabase, fn_id: FnId) -> FnDefNode { |
13 | let syntax = db.resolve_syntax_ptr(fn_id.0); | 12 | let ptr = db.id_maps().fn_ptr(fn_id); |
13 | let syntax = db.resolve_syntax_ptr(ptr); | ||
14 | FnDef::cast(syntax.borrowed()).unwrap().owned() | 14 | FnDef::cast(syntax.borrowed()).unwrap().owned() |
15 | } | 15 | } |
16 | 16 | ||
diff --git a/crates/ra_analysis/src/descriptors/function/mod.rs b/crates/ra_analysis/src/descriptors/function/mod.rs index d5db28a64..86eee5e93 100644 --- a/crates/ra_analysis/src/descriptors/function/mod.rs +++ b/crates/ra_analysis/src/descriptors/function/mod.rs | |||
@@ -8,17 +8,18 @@ use ra_syntax::{ | |||
8 | TextRange, TextUnit, | 8 | TextRange, TextUnit, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{syntax_ptr::SyntaxPtr, FileId}; | 11 | use crate::{ |
12 | syntax_ptr::SyntaxPtr, FileId, | ||
13 | loc2id::IdDatabase, | ||
14 | }; | ||
12 | 15 | ||
13 | pub(crate) use self::scope::{resolve_local_name, FnScopes}; | 16 | pub(crate) use self::scope::{resolve_local_name, FnScopes}; |
14 | 17 | pub(crate) use crate::loc2id::FnId; | |
15 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
16 | pub(crate) struct FnId(SyntaxPtr); | ||
17 | 18 | ||
18 | impl FnId { | 19 | impl FnId { |
19 | pub(crate) fn new(file_id: FileId, fn_def: ast::FnDef) -> FnId { | 20 | pub(crate) fn get(db: &impl IdDatabase, file_id: FileId, fn_def: ast::FnDef) -> FnId { |
20 | let ptr = SyntaxPtr::new(file_id, fn_def.syntax()); | 21 | let ptr = SyntaxPtr::new(file_id, fn_def.syntax()); |
21 | FnId(ptr) | 22 | db.id_maps().fn_id(ptr) |
22 | } | 23 | } |
23 | } | 24 | } |
24 | 25 | ||
diff --git a/crates/ra_analysis/src/descriptors/mod.rs b/crates/ra_analysis/src/descriptors/mod.rs index 56bde3849..d602c4e04 100644 --- a/crates/ra_analysis/src/descriptors/mod.rs +++ b/crates/ra_analysis/src/descriptors/mod.rs | |||
@@ -13,12 +13,13 @@ use crate::{ | |||
13 | descriptors::function::{resolve_local_name, FnId, FnScopes}, | 13 | descriptors::function::{resolve_local_name, FnId, FnScopes}, |
14 | descriptors::module::{ModuleId, ModuleScope, ModuleTree, ModuleSource}, | 14 | descriptors::module::{ModuleId, ModuleScope, ModuleTree, ModuleSource}, |
15 | input::SourceRootId, | 15 | input::SourceRootId, |
16 | loc2id::IdDatabase, | ||
16 | syntax_ptr::LocalSyntaxPtr, | 17 | syntax_ptr::LocalSyntaxPtr, |
17 | Cancelable, | 18 | Cancelable, |
18 | }; | 19 | }; |
19 | 20 | ||
20 | salsa::query_group! { | 21 | salsa::query_group! { |
21 | pub(crate) trait DescriptorDatabase: SyntaxDatabase { | 22 | pub(crate) trait DescriptorDatabase: SyntaxDatabase + IdDatabase { |
22 | fn module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> { | 23 | fn module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> { |
23 | type ModuleTreeQuery; | 24 | type ModuleTreeQuery; |
24 | use fn module::imp::module_tree; | 25 | use fn module::imp::module_tree; |
diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index bc1148b22..055a56b54 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs | |||
@@ -58,6 +58,15 @@ enum ModuleSourceNode { | |||
58 | #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] | 58 | #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] |
59 | pub(crate) struct ModuleId(u32); | 59 | pub(crate) struct ModuleId(u32); |
60 | 60 | ||
61 | impl crate::loc2id::NumericId for ModuleId { | ||
62 | fn from_u32(id: u32) -> Self { | ||
63 | ModuleId(id) | ||
64 | } | ||
65 | fn to_u32(self) -> u32 { | ||
66 | self.0 | ||
67 | } | ||
68 | } | ||
69 | |||
61 | #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] | 70 | #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] |
62 | pub(crate) struct LinkId(u32); | 71 | pub(crate) struct LinkId(u32); |
63 | 72 | ||