ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
};
-pub use hir_def::Source;
+pub use hir_expand::Source;
pub trait HasSource {
type Ast;
adt::VariantDef,
code_model::{
docs::{DocDef, Docs, Documentation},
- src::{HasBodySource, HasSource, Source},
+ src::{HasBodySource, HasSource},
Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef,
ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
path::{Path, PathKind},
type_ref::Mutability,
};
-pub use hir_expand::{either::Either, name::Name};
+pub use hir_expand::{either::Either, name::Name, Source};
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_db::{salsa, CrateId, FileId};
use ra_syntax::{ast, AstNode, SyntaxNode};
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 {
SourceFile(ast::SourceFile),
Module(ast::Module),
}
}
-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)]
pub struct ModuleId {
pub krate: CrateId,
use std::hash::{Hash, Hasher};
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;
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")
+ }
+}