From cb22a799d60c6c5f81ad0f3d0361f575264f3bc2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 18 Nov 2018 15:44:24 +0300 Subject: Add Loc2IdMap --- crates/ra_analysis/src/descriptors/module/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'crates/ra_analysis/src/descriptors') 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 { #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] pub(crate) struct ModuleId(u32); +impl crate::loc2id::NumericId for ModuleId { + fn from_u32(id: u32) -> Self { + ModuleId(id) + } + fn to_u32(self) -> u32 { + self.0 + } +} + #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] pub(crate) struct LinkId(u32); -- cgit v1.2.3 From 4e48917c00d24e1e1785e1959a2f3495a902410b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 18 Nov 2018 16:21:23 +0300 Subject: use loc2id for FnIds --- crates/ra_analysis/src/descriptors/function/imp.rs | 4 ++-- crates/ra_analysis/src/descriptors/function/mod.rs | 13 +++++++------ crates/ra_analysis/src/descriptors/mod.rs | 3 ++- 3 files changed, 11 insertions(+), 9 deletions(-) (limited to 'crates/ra_analysis/src/descriptors') 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::{ }; /// Resolve `FnId` to the corresponding `SyntaxNode` -/// TODO: this should return something more type-safe then `SyntaxNode` pub(crate) fn fn_syntax(db: &impl DescriptorDatabase, fn_id: FnId) -> FnDefNode { - let syntax = db.resolve_syntax_ptr(fn_id.0); + let ptr = db.id_maps().fn_ptr(fn_id); + let syntax = db.resolve_syntax_ptr(ptr); FnDef::cast(syntax.borrowed()).unwrap().owned() } 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::{ TextRange, TextUnit, }; -use crate::{syntax_ptr::SyntaxPtr, FileId}; +use crate::{ + syntax_ptr::SyntaxPtr, FileId, + loc2id::IdDatabase, +}; pub(crate) use self::scope::{resolve_local_name, FnScopes}; - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub(crate) struct FnId(SyntaxPtr); +pub(crate) use crate::loc2id::FnId; impl FnId { - pub(crate) fn new(file_id: FileId, fn_def: ast::FnDef) -> FnId { + pub(crate) fn get(db: &impl IdDatabase, file_id: FileId, fn_def: ast::FnDef) -> FnId { let ptr = SyntaxPtr::new(file_id, fn_def.syntax()); - FnId(ptr) + db.id_maps().fn_id(ptr) } } 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::{ descriptors::function::{resolve_local_name, FnId, FnScopes}, descriptors::module::{ModuleId, ModuleScope, ModuleTree, ModuleSource}, input::SourceRootId, + loc2id::IdDatabase, syntax_ptr::LocalSyntaxPtr, Cancelable, }; salsa::query_group! { - pub(crate) trait DescriptorDatabase: SyntaxDatabase { + pub(crate) trait DescriptorDatabase: SyntaxDatabase + IdDatabase { fn module_tree(source_root_id: SourceRootId) -> Cancelable> { type ModuleTreeQuery; use fn module::imp::module_tree; -- cgit v1.2.3