Move FileItems up
This commit is contained in:
parent
b9100d769a
commit
5e7f4202cf
4 changed files with 43 additions and 37 deletions
|
@ -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,
|
||||
|
|
|
@ -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<SyntaxNode>;
|
||||
|
||||
/// Maps item's `SyntaxNode`s to `FileItemId` and back.
|
||||
#[derive(Debug, PartialEq, Eq, Default)]
|
||||
pub(crate) struct FileItems {
|
||||
arena: Arena<SyntaxNode>,
|
||||
}
|
||||
|
||||
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<FileItemId> for FileItems {
|
||||
type Output = SyntaxNode;
|
||||
fn index(&self, idx: FileItemId) -> &SyntaxNode {
|
||||
&self.arena[idx]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<SyntaxNode>;
|
||||
|
||||
/// Maps item's `SyntaxNode`s to `FileItemId` and back.
|
||||
#[derive(Debug, PartialEq, Eq, Default)]
|
||||
pub(crate) struct FileItems {
|
||||
arena: Arena<SyntaxNode>,
|
||||
}
|
||||
|
||||
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<FileItemId> 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)]
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue