mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Encode edition within FileId in the hir layer
This commit is contained in:
parent
92268627a8
commit
5264f86242
160 changed files with 1117 additions and 824 deletions
|
@ -3,8 +3,8 @@ use std::borrow::Borrow;
|
|||
|
||||
use either::Either;
|
||||
use span::{
|
||||
AstIdNode, ErasedFileAstId, FileAstId, FileId, FileRange, HirFileId, HirFileIdRepr,
|
||||
MacroFileId, SyntaxContextId,
|
||||
AstIdNode, EditionedFileId, ErasedFileAstId, FileAstId, HirFileId, HirFileIdRepr, MacroFileId,
|
||||
SyntaxContextId,
|
||||
};
|
||||
use syntax::{AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize};
|
||||
|
||||
|
@ -27,7 +27,36 @@ pub struct InFileWrapper<FileKind, T> {
|
|||
}
|
||||
pub type InFile<T> = InFileWrapper<HirFileId, T>;
|
||||
pub type InMacroFile<T> = InFileWrapper<MacroFileId, T>;
|
||||
pub type InRealFile<T> = InFileWrapper<FileId, T>;
|
||||
pub type InRealFile<T> = InFileWrapper<EditionedFileId, T>;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
||||
pub struct FilePositionWrapper<FileKind> {
|
||||
pub file_id: FileKind,
|
||||
pub offset: TextSize,
|
||||
}
|
||||
pub type HirFilePosition = FilePositionWrapper<HirFileId>;
|
||||
pub type MacroFilePosition = FilePositionWrapper<MacroFileId>;
|
||||
pub type FilePosition = FilePositionWrapper<EditionedFileId>;
|
||||
|
||||
impl From<FilePositionWrapper<EditionedFileId>> for FilePositionWrapper<span::FileId> {
|
||||
fn from(value: FilePositionWrapper<EditionedFileId>) -> Self {
|
||||
FilePositionWrapper { file_id: value.file_id.into(), offset: value.offset }
|
||||
}
|
||||
}
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
||||
pub struct FileRangeWrapper<FileKind> {
|
||||
pub file_id: FileKind,
|
||||
pub range: TextRange,
|
||||
}
|
||||
pub type HirFileRange = FileRangeWrapper<HirFileId>;
|
||||
pub type MacroFileRange = FileRangeWrapper<MacroFileId>;
|
||||
pub type FileRange = FileRangeWrapper<EditionedFileId>;
|
||||
|
||||
impl From<FileRangeWrapper<EditionedFileId>> for FileRangeWrapper<span::FileId> {
|
||||
fn from(value: FileRangeWrapper<EditionedFileId>) -> Self {
|
||||
FileRangeWrapper { file_id: value.file_id.into(), range: value.range }
|
||||
}
|
||||
}
|
||||
|
||||
/// `AstId` points to an AST node in any file.
|
||||
///
|
||||
|
@ -128,7 +157,7 @@ trait FileIdToSyntax: Copy {
|
|||
fn file_syntax(self, db: &dyn db::ExpandDatabase) -> SyntaxNode;
|
||||
}
|
||||
|
||||
impl FileIdToSyntax for FileId {
|
||||
impl FileIdToSyntax for EditionedFileId {
|
||||
fn file_syntax(self, db: &dyn db::ExpandDatabase) -> SyntaxNode {
|
||||
db.parse(self).syntax_node()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue