migrate ra_hir to the new rowan

This commit is contained in:
Aleksey Kladov 2019-07-19 10:43:01 +03:00
parent 7e02aa0eff
commit e2b28f5bb8
22 changed files with 206 additions and 210 deletions

View file

@ -71,21 +71,21 @@ pub(crate) fn documentation_query(
def: DocDef,
) -> Option<Documentation> {
match def {
DocDef::Module(it) => docs_from_ast(&*it.declaration_source(db)?.ast),
DocDef::Module(it) => docs_from_ast(&it.declaration_source(db)?.ast),
DocDef::StructField(it) => match it.source(db).ast {
FieldSource::Named(named) => docs_from_ast(&*named),
FieldSource::Named(named) => docs_from_ast(&named),
FieldSource::Pos(..) => None,
},
DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast),
DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast),
DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast),
DocDef::Static(it) => docs_from_ast(&*it.source(db).ast),
DocDef::Const(it) => docs_from_ast(&*it.source(db).ast),
DocDef::Function(it) => docs_from_ast(&*it.source(db).ast),
DocDef::Union(it) => docs_from_ast(&*it.source(db).ast),
DocDef::Trait(it) => docs_from_ast(&*it.source(db).ast),
DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).ast),
DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).ast),
DocDef::Struct(it) => docs_from_ast(&it.source(db).ast),
DocDef::Enum(it) => docs_from_ast(&it.source(db).ast),
DocDef::EnumVariant(it) => docs_from_ast(&it.source(db).ast),
DocDef::Static(it) => docs_from_ast(&it.source(db).ast),
DocDef::Const(it) => docs_from_ast(&it.source(db).ast),
DocDef::Function(it) => docs_from_ast(&it.source(db).ast),
DocDef::Union(it) => docs_from_ast(&it.source(db).ast),
DocDef::Trait(it) => docs_from_ast(&it.source(db).ast),
DocDef::TypeAlias(it) => docs_from_ast(&it.source(db).ast),
DocDef::MacroDef(it) => docs_from_ast(&it.source(db).ast),
}
}

View file

@ -1,4 +1,4 @@
use ra_syntax::{ast, TreeArc};
use ra_syntax::ast;
use crate::{
ids::AstItemDef, AstDatabase, Const, DefDatabase, Enum, EnumVariant, FieldSource, Function,
@ -34,7 +34,7 @@ impl Module {
pub fn declaration_source(
self,
db: &(impl DefDatabase + AstDatabase),
) -> Option<Source<TreeArc<ast::Module>>> {
) -> Option<Source<ast::Module>> {
let def_map = db.crate_def_map(self.krate);
let decl = def_map[self.module_id].declaration?;
let ast = decl.to_node(db);
@ -49,62 +49,62 @@ impl HasSource for StructField {
}
}
impl HasSource for Struct {
type Ast = TreeArc<ast::StructDef>;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
type Ast = ast::StructDef;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::StructDef> {
self.id.source(db)
}
}
impl HasSource for Union {
type Ast = TreeArc<ast::StructDef>;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
type Ast = ast::StructDef;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::StructDef> {
self.id.source(db)
}
}
impl HasSource for Enum {
type Ast = TreeArc<ast::EnumDef>;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> {
type Ast = ast::EnumDef;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::EnumDef> {
self.id.source(db)
}
}
impl HasSource for EnumVariant {
type Ast = TreeArc<ast::EnumVariant>;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumVariant>> {
type Ast = ast::EnumVariant;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::EnumVariant> {
self.source_impl(db)
}
}
impl HasSource for Function {
type Ast = TreeArc<ast::FnDef>;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::FnDef>> {
type Ast = ast::FnDef;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::FnDef> {
self.id.source(db)
}
}
impl HasSource for Const {
type Ast = TreeArc<ast::ConstDef>;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ConstDef>> {
type Ast = ast::ConstDef;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::ConstDef> {
self.id.source(db)
}
}
impl HasSource for Static {
type Ast = TreeArc<ast::StaticDef>;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StaticDef>> {
type Ast = ast::StaticDef;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::StaticDef> {
self.id.source(db)
}
}
impl HasSource for Trait {
type Ast = TreeArc<ast::TraitDef>;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TraitDef>> {
type Ast = ast::TraitDef;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::TraitDef> {
self.id.source(db)
}
}
impl HasSource for TypeAlias {
type Ast = TreeArc<ast::TypeAliasDef>;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TypeAliasDef>> {
type Ast = ast::TypeAliasDef;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::TypeAliasDef> {
self.id.source(db)
}
}
impl HasSource for MacroDef {
type Ast = TreeArc<ast::MacroCall>;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::MacroCall>> {
type Ast = ast::MacroCall;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::MacroCall> {
Source { file_id: self.id.0.file_id(), ast: self.id.0.to_node(db) }
}
}