From 5e7f4202cf4d64f565d6d035cd2e854acfc336ab Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 28 Nov 2018 01:45:36 +0300 Subject: Move FileItems up --- crates/ra_analysis/src/hir/db.rs | 3 +- crates/ra_analysis/src/hir/mod.rs | 38 ++++++++++++++++++++++++- crates/ra_analysis/src/hir/module/nameres.rs | 36 ++--------------------- crates/ra_analysis/src/hir/query_definitions.rs | 3 +- 4 files changed, 43 insertions(+), 37 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/hir/db.rs b/crates/ra_analysis/src/hir/db.rs index c6dbde79b..a226e8205 100644 --- a/crates/ra_analysis/src/hir/db.rs +++ b/crates/ra_analysis/src/hir/db.rs @@ -8,11 +8,12 @@ use ra_syntax::{ use crate::{ FileId, db::SyntaxDatabase, + hir::{FileItems, FileItemId}, hir::query_definitions, hir::function::{FnId, FnScopes}, hir::module::{ ModuleId, ModuleTree, ModuleSource, - nameres::{ItemMap, InputModuleItems, FileItems, FileItemId} + nameres::{ItemMap, InputModuleItems} }, input::SourceRootId, Cancelable, diff --git a/crates/ra_analysis/src/hir/mod.rs b/crates/ra_analysis/src/hir/mod.rs index 863ffd919..3d4a55ca4 100644 --- a/crates/ra_analysis/src/hir/mod.rs +++ b/crates/ra_analysis/src/hir/mod.rs @@ -11,15 +11,20 @@ mod function; mod module; mod path; +use std::ops::Index; + +use ra_syntax::{SyntaxNodeRef, SyntaxNode}; + use crate::{ hir::db::HirDatabase, loc2id::{DefId, DefLoc}, Cancelable, + arena::{Arena, Id}, }; pub(crate) use self::{ path::{Path, PathKind}, - module::{Module, ModuleId, Problem, nameres::FileItemId}, + module::{Module, ModuleId, Problem}, function::{Function, FnScopes}, }; @@ -43,3 +48,34 @@ impl DefId { Ok(res) } } + +/// Identifier of item within a specific file. This is stable over reparses, so +/// it's OK to use it as a salsa key/value. +pub(crate) type FileItemId = Id; + +/// Maps item's `SyntaxNode`s to `FileItemId` and back. +#[derive(Debug, PartialEq, Eq, Default)] +pub(crate) struct FileItems { + arena: Arena, +} + +impl FileItems { + fn alloc(&mut self, item: SyntaxNode) -> FileItemId { + self.arena.alloc(item) + } + fn id_of(&self, item: SyntaxNodeRef) -> FileItemId { + let (id, _item) = self + .arena + .iter() + .find(|(_id, i)| i.borrowed() == item) + .unwrap(); + id + } +} + +impl Index for FileItems { + type Output = SyntaxNode; + fn index(&self, idx: FileItemId) -> &SyntaxNode { + &self.arena[idx] + } +} diff --git a/crates/ra_analysis/src/hir/module/nameres.rs b/crates/ra_analysis/src/hir/module/nameres.rs index d38940085..f7d8c8e8c 100644 --- a/crates/ra_analysis/src/hir/module/nameres.rs +++ b/crates/ra_analysis/src/hir/module/nameres.rs @@ -16,13 +16,12 @@ //! structure itself is modified. use std::{ sync::Arc, - ops::Index, }; use rustc_hash::FxHashMap; use ra_syntax::{ - SyntaxNode, SyntaxNodeRef, TextRange, + TextRange, SmolStr, SyntaxKind::{self, *}, ast::{self, AstNode} }; @@ -31,45 +30,14 @@ use crate::{ Cancelable, FileId, loc2id::{DefId, DefLoc}, hir::{ + FileItemId, FileItems, Path, PathKind, HirDatabase, module::{ModuleId, ModuleTree}, }, input::SourceRootId, - arena::{Arena, Id} }; -/// Identifier of item within a specific file. This is stable over reparses, so -/// it's OK to use it as a salsa key/value. -pub(crate) type FileItemId = Id; - -/// Maps item's `SyntaxNode`s to `FileItemId` and back. -#[derive(Debug, PartialEq, Eq, Default)] -pub(crate) struct FileItems { - arena: Arena, -} - -impl FileItems { - pub(crate) fn alloc(&mut self, item: SyntaxNode) -> FileItemId { - self.arena.alloc(item) - } - fn id_of(&self, item: SyntaxNodeRef) -> FileItemId { - let (id, _item) = self - .arena - .iter() - .find(|(_id, i)| i.borrowed() == item) - .unwrap(); - id - } -} - -impl Index for FileItems { - type Output = SyntaxNode; - fn index(&self, idx: FileItemId) -> &SyntaxNode { - &self.arena[idx] - } -} - /// Item map is the result of the name resolution. Item map contains, for each /// module, the set of visible items. #[derive(Default, Debug, PartialEq, Eq)] diff --git a/crates/ra_analysis/src/hir/query_definitions.rs b/crates/ra_analysis/src/hir/query_definitions.rs index 8584a8d64..e6bfbc6cf 100644 --- a/crates/ra_analysis/src/hir/query_definitions.rs +++ b/crates/ra_analysis/src/hir/query_definitions.rs @@ -12,12 +12,13 @@ use ra_syntax::{ use crate::{ FileId, Cancelable, hir::{ + FileItems, FileItemId, db::HirDatabase, function::{FnId, FnScopes}, module::{ ModuleSource, ModuleSourceNode, ModuleId, imp::Submodule, - nameres::{FileItems, FileItemId, InputModuleItems, ItemMap, Resolver}, + nameres::{InputModuleItems, ItemMap, Resolver}, }, }, input::SourceRootId, -- cgit v1.2.3