From 9027a21f9a1c7fcee0a59a1e28928fed29781dd8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 28 Nov 2018 01:53:54 +0300 Subject: Introduce SourceItemId --- crates/ra_analysis/src/hir/db.rs | 4 ++-- crates/ra_analysis/src/hir/mod.rs | 7 +++++++ crates/ra_analysis/src/hir/module/nameres.rs | 14 ++++++++++---- crates/ra_analysis/src/hir/query_definitions.rs | 10 +++------- crates/ra_analysis/src/loc2id.rs | 6 ++---- 5 files changed, 24 insertions(+), 17 deletions(-) (limited to 'crates') diff --git a/crates/ra_analysis/src/hir/db.rs b/crates/ra_analysis/src/hir/db.rs index e74fcc8ad..0998295f5 100644 --- a/crates/ra_analysis/src/hir/db.rs +++ b/crates/ra_analysis/src/hir/db.rs @@ -8,7 +8,7 @@ use ra_syntax::{ use crate::{ FileId, db::SyntaxDatabase, - hir::{SourceFileItems, SourceFileItemId}, + hir::{SourceFileItems, SourceItemId}, hir::query_definitions, hir::function::{FnId, FnScopes}, hir::module::{ @@ -39,7 +39,7 @@ pub(crate) trait HirDatabase: SyntaxDatabase { use fn query_definitions::file_items; } - fn file_item(file_id: FileId, file_item_id: SourceFileItemId) -> SyntaxNode { + fn file_item(source_item_id: SourceItemId) -> SyntaxNode { type FileItemQuery; storage dependencies; use fn query_definitions::file_item; diff --git a/crates/ra_analysis/src/hir/mod.rs b/crates/ra_analysis/src/hir/mod.rs index aa416df20..9527cc33f 100644 --- a/crates/ra_analysis/src/hir/mod.rs +++ b/crates/ra_analysis/src/hir/mod.rs @@ -16,6 +16,7 @@ use std::ops::Index; use ra_syntax::{SyntaxNodeRef, SyntaxNode}; use crate::{ + FileId, hir::db::HirDatabase, loc2id::{DefId, DefLoc}, Cancelable, @@ -53,6 +54,12 @@ impl DefId { /// it's OK to use it as a salsa key/value. pub(crate) type SourceFileItemId = Id; +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub(crate) struct SourceItemId { + file_id: FileId, + item_id: SourceFileItemId, +} + /// Maps item's `SyntaxNode`s to `SourceFileItemId` and back. #[derive(Debug, PartialEq, Eq, Default)] pub(crate) struct SourceFileItems { diff --git a/crates/ra_analysis/src/hir/module/nameres.rs b/crates/ra_analysis/src/hir/module/nameres.rs index 9dc54f6c0..f22832eda 100644 --- a/crates/ra_analysis/src/hir/module/nameres.rs +++ b/crates/ra_analysis/src/hir/module/nameres.rs @@ -30,7 +30,7 @@ use crate::{ Cancelable, FileId, loc2id::{DefId, DefLoc}, hir::{ - SourceFileItemId, SourceFileItems, + SourceItemId, SourceFileItemId, SourceFileItems, Path, PathKind, HirDatabase, module::{ModuleId, ModuleTree}, @@ -99,7 +99,11 @@ pub(crate) struct NamedImport { impl NamedImport { pub(crate) fn range(&self, db: &impl HirDatabase, file_id: FileId) -> TextRange { - let syntax = db.file_item(file_id, self.file_item_id); + let source_item_id = SourceItemId { + file_id, + item_id: self.file_item_id, + }; + let syntax = db.file_item(source_item_id); let offset = syntax.borrowed().range().start(); self.relative_range + offset } @@ -247,8 +251,10 @@ where continue; } let def_loc = DefLoc::Item { - file_id, - id: item.id, + source_item_id: SourceItemId { + file_id, + item_id: item.id, + }, }; let def_id = self.db.id_maps().def_id(def_loc); let resolution = Resolution { diff --git a/crates/ra_analysis/src/hir/query_definitions.rs b/crates/ra_analysis/src/hir/query_definitions.rs index 53926cf16..ae292e964 100644 --- a/crates/ra_analysis/src/hir/query_definitions.rs +++ b/crates/ra_analysis/src/hir/query_definitions.rs @@ -12,7 +12,7 @@ use ra_syntax::{ use crate::{ FileId, Cancelable, hir::{ - SourceFileItems, SourceFileItemId, + SourceFileItems, SourceItemId, db::HirDatabase, function::{FnId, FnScopes}, module::{ @@ -52,12 +52,8 @@ pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc SyntaxNode { - db.file_items(file_id)[file_item_id].clone() +pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> SyntaxNode { + db.file_items(source_item_id.file_id)[source_item_id.item_id].clone() } pub(crate) fn submodules( diff --git a/crates/ra_analysis/src/loc2id.rs b/crates/ra_analysis/src/loc2id.rs index 49af19c75..5b2c0f615 100644 --- a/crates/ra_analysis/src/loc2id.rs +++ b/crates/ra_analysis/src/loc2id.rs @@ -8,8 +8,7 @@ use std::{ use rustc_hash::FxHashMap; use crate::{ - FileId, - hir::{SourceFileItemId, ModuleId}, + hir::{SourceItemId, ModuleId}, syntax_ptr::SyntaxPtr, input::SourceRootId, }; @@ -103,8 +102,7 @@ pub(crate) enum DefLoc { source_root: SourceRootId, }, Item { - file_id: FileId, - id: SourceFileItemId, + source_item_id: SourceItemId, }, } -- cgit v1.2.3