From c2abd17f57fa14960e8a175bdabe49eb365a585f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 28 Nov 2018 02:13:52 +0300 Subject: Use ItemPtr for id --- crates/ra_analysis/src/hir/function/mod.rs | 10 ++++++---- crates/ra_analysis/src/hir/query_definitions.rs | 4 ++-- crates/ra_analysis/src/loc2id.rs | 9 ++++----- crates/ra_analysis/src/syntax_ptr.rs | 7 ------- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/crates/ra_analysis/src/hir/function/mod.rs b/crates/ra_analysis/src/hir/function/mod.rs index 9ca8f4e7c..280218fd4 100644 --- a/crates/ra_analysis/src/hir/function/mod.rs +++ b/crates/ra_analysis/src/hir/function/mod.rs @@ -11,8 +11,8 @@ use ra_syntax::{ }; use crate::{ - hir::HirDatabase, - syntax_ptr::SyntaxPtr, FileId, + hir::{HirDatabase, SourceItemId}, + FileId, }; pub(crate) use self::scope::FnScopes; @@ -20,8 +20,10 @@ pub(crate) use crate::loc2id::FnId; impl FnId { pub(crate) fn get(db: &impl HirDatabase, file_id: FileId, fn_def: ast::FnDef) -> FnId { - let ptr = SyntaxPtr::new(file_id, fn_def.syntax()); - db.id_maps().fn_id(ptr) + let file_items = db.file_items(file_id); + let item_id = file_items.id_of(fn_def.syntax()); + let item_id = SourceItemId { file_id, item_id }; + db.id_maps().fn_id(item_id) } } diff --git a/crates/ra_analysis/src/hir/query_definitions.rs b/crates/ra_analysis/src/hir/query_definitions.rs index cdd986ce4..6c633e9ab 100644 --- a/crates/ra_analysis/src/hir/query_definitions.rs +++ b/crates/ra_analysis/src/hir/query_definitions.rs @@ -26,8 +26,8 @@ use crate::{ /// Resolve `FnId` to the corresponding `SyntaxNode` pub(super) fn fn_syntax(db: &impl HirDatabase, fn_id: FnId) -> FnDefNode { - let ptr = db.id_maps().fn_ptr(fn_id); - let syntax = db.resolve_syntax_ptr(ptr); + let item_id = db.id_maps().fn_item_id(fn_id); + let syntax = db.file_item(item_id); FnDef::cast(syntax.borrowed()).unwrap().owned() } diff --git a/crates/ra_analysis/src/loc2id.rs b/crates/ra_analysis/src/loc2id.rs index 5b2c0f615..204708942 100644 --- a/crates/ra_analysis/src/loc2id.rs +++ b/crates/ra_analysis/src/loc2id.rs @@ -9,7 +9,6 @@ use rustc_hash::FxHashMap; use crate::{ hir::{SourceItemId, ModuleId}, - syntax_ptr::SyntaxPtr, input::SourceRootId, }; @@ -112,10 +111,10 @@ pub(crate) struct IdMaps { } impl IdMaps { - pub(crate) fn fn_id(&self, ptr: SyntaxPtr) -> FnId { - self.inner.fns.lock().loc2id(&ptr) + pub(crate) fn fn_id(&self, item_id: SourceItemId) -> FnId { + self.inner.fns.lock().loc2id(&item_id) } - pub(crate) fn fn_ptr(&self, fn_id: FnId) -> SyntaxPtr { + pub(crate) fn fn_item_id(&self, fn_id: FnId) -> SourceItemId { self.inner.fns.lock().id2loc(fn_id) } @@ -129,6 +128,6 @@ impl IdMaps { #[derive(Debug, Default)] struct IdMapsInner { - fns: Mutex>, + fns: Mutex>, defs: Mutex>, } diff --git a/crates/ra_analysis/src/syntax_ptr.rs b/crates/ra_analysis/src/syntax_ptr.rs index ca8efc9b2..7bbf1fc33 100644 --- a/crates/ra_analysis/src/syntax_ptr.rs +++ b/crates/ra_analysis/src/syntax_ptr.rs @@ -17,13 +17,6 @@ pub(crate) struct SyntaxPtr { local: LocalSyntaxPtr, } -impl SyntaxPtr { - pub(crate) fn new(file_id: FileId, node: SyntaxNodeRef) -> SyntaxPtr { - let local = LocalSyntaxPtr::new(node); - SyntaxPtr { file_id, local } - } -} - /// A pionter to a syntax node inside a file. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub(crate) struct LocalSyntaxPtr { -- cgit v1.2.3