mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Move Source to hir_expand
This commit is contained in:
parent
2d142a17ef
commit
b8533413cf
4 changed files with 23 additions and 20 deletions
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
|
ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use hir_def::Source;
|
pub use hir_expand::Source;
|
||||||
|
|
||||||
pub trait HasSource {
|
pub trait HasSource {
|
||||||
type Ast;
|
type Ast;
|
||||||
|
|
|
@ -62,7 +62,7 @@ pub use crate::{
|
||||||
adt::VariantDef,
|
adt::VariantDef,
|
||||||
code_model::{
|
code_model::{
|
||||||
docs::{DocDef, Docs, Documentation},
|
docs::{DocDef, Docs, Documentation},
|
||||||
src::{HasBodySource, HasSource, Source},
|
src::{HasBodySource, HasSource},
|
||||||
Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
|
Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
|
||||||
EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef,
|
EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef,
|
||||||
ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
|
ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
|
||||||
|
@ -85,4 +85,4 @@ pub use hir_def::{
|
||||||
path::{Path, PathKind},
|
path::{Path, PathKind},
|
||||||
type_ref::Mutability,
|
type_ref::Mutability,
|
||||||
};
|
};
|
||||||
pub use hir_expand::{either::Either, name::Name};
|
pub use hir_expand::{either::Either, name::Name, Source};
|
||||||
|
|
|
@ -19,19 +19,13 @@ pub mod nameres;
|
||||||
|
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId};
|
use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, Source};
|
||||||
use ra_arena::{impl_arena_id, RawId};
|
use ra_arena::{impl_arena_id, RawId};
|
||||||
use ra_db::{salsa, CrateId, FileId};
|
use ra_db::{salsa, CrateId, FileId};
|
||||||
use ra_syntax::{ast, AstNode, SyntaxNode};
|
use ra_syntax::{ast, AstNode, SyntaxNode};
|
||||||
|
|
||||||
use crate::{builtin_type::BuiltinType, db::InternDatabase};
|
use crate::{builtin_type::BuiltinType, db::InternDatabase};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
|
||||||
pub struct Source<T> {
|
|
||||||
pub file_id: HirFileId,
|
|
||||||
pub ast: T,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum ModuleSource {
|
pub enum ModuleSource {
|
||||||
SourceFile(ast::SourceFile),
|
SourceFile(ast::SourceFile),
|
||||||
Module(ast::Module),
|
Module(ast::Module),
|
||||||
|
@ -94,15 +88,6 @@ impl ModuleSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Source<T> {
|
|
||||||
pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> {
|
|
||||||
Source { file_id: self.file_id, ast: f(self.ast) }
|
|
||||||
}
|
|
||||||
pub fn file_syntax(&self, db: &impl AstDatabase) -> SyntaxNode {
|
|
||||||
db.parse_or_expand(self.file_id).expect("source created from invalid file")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct ModuleId {
|
pub struct ModuleId {
|
||||||
pub krate: CrateId,
|
pub krate: CrateId,
|
||||||
|
|
|
@ -13,7 +13,10 @@ pub mod hygiene;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
use ra_db::{salsa, CrateId, FileId};
|
use ra_db::{salsa, CrateId, FileId};
|
||||||
use ra_syntax::ast::{self, AstNode};
|
use ra_syntax::{
|
||||||
|
ast::{self, AstNode},
|
||||||
|
SyntaxNode,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::ast_id_map::FileAstId;
|
use crate::ast_id_map::FileAstId;
|
||||||
|
|
||||||
|
@ -151,3 +154,18 @@ impl<N: AstNode> AstId<N> {
|
||||||
db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root)
|
db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
|
pub struct Source<T> {
|
||||||
|
pub file_id: HirFileId,
|
||||||
|
pub ast: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Source<T> {
|
||||||
|
pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> {
|
||||||
|
Source { file_id: self.file_id, ast: f(self.ast) }
|
||||||
|
}
|
||||||
|
pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode {
|
||||||
|
db.parse_or_expand(self.file_id).expect("source created from invalid file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue