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