mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
use MFile
This commit is contained in:
parent
4161466918
commit
289391e163
7 changed files with 62 additions and 30 deletions
|
@ -57,11 +57,18 @@ pub use self::function::FnSignatureInfo;
|
|||
|
||||
/// An `MFileId` is like a `FileId`, but it can also refer to code generated by
|
||||
/// macros.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum MFileId {
|
||||
File(FileId),
|
||||
Macro(MacroCallId),
|
||||
}
|
||||
|
||||
impl From<FileId> for MFileId {
|
||||
fn from(file_id: FileId) -> MFileId {
|
||||
MFileId::File(file_id)
|
||||
}
|
||||
}
|
||||
|
||||
/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc)
|
||||
/// in a specific module.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
|
@ -163,7 +170,7 @@ pub(crate) type SourceFileItemId = Id<SyntaxNode>;
|
|||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct SourceItemId {
|
||||
file_id: FileId,
|
||||
mfile_id: MFileId,
|
||||
/// None for the whole file.
|
||||
item_id: Option<SourceFileItemId>,
|
||||
}
|
||||
|
@ -171,14 +178,14 @@ pub struct SourceItemId {
|
|||
/// Maps item's `SyntaxNode`s to `SourceFileItemId` and back.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct SourceFileItems {
|
||||
file_id: FileId,
|
||||
mfile_id: MFileId,
|
||||
arena: Arena<SyntaxNode>,
|
||||
}
|
||||
|
||||
impl SourceFileItems {
|
||||
fn new(file_id: FileId, source_file: SourceFile) -> SourceFileItems {
|
||||
fn new(mfile_id: MFileId, source_file: SourceFile) -> SourceFileItems {
|
||||
let mut res = SourceFileItems {
|
||||
file_id,
|
||||
mfile_id,
|
||||
arena: Arena::default(),
|
||||
};
|
||||
res.init(source_file);
|
||||
|
@ -198,11 +205,11 @@ impl SourceFileItems {
|
|||
fn alloc(&mut self, item: SyntaxNode) -> SourceFileItemId {
|
||||
self.arena.alloc(item)
|
||||
}
|
||||
pub fn id_of(&self, file_id: FileId, item: SyntaxNodeRef) -> SourceFileItemId {
|
||||
pub fn id_of(&self, mfile_id: MFileId, item: SyntaxNodeRef) -> SourceFileItemId {
|
||||
assert_eq!(
|
||||
self.file_id, file_id,
|
||||
self.mfile_id, mfile_id,
|
||||
"SourceFileItems: wrong file, expected {:?}, got {:?}",
|
||||
self.file_id, file_id
|
||||
self.mfile_id, mfile_id
|
||||
);
|
||||
self.id_of_unchecked(item)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue