From ccd1b0800a5de5e046e6e9a4b6f49030c1ce3639 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 28 Nov 2019 12:50:26 +0300 Subject: Rename Source -> InFile --- crates/ra_hir/src/from_source.rs | 62 ++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'crates/ra_hir/src/from_source.rs') diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 9f7c22b21..82bf641dc 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs @@ -10,46 +10,46 @@ use ra_syntax::{ use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, AssocItem, Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, - Local, MacroDef, Module, ModuleDef, ModuleSource, Source, Static, Struct, StructField, Trait, + InFile, Local, MacroDef, Module, ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef, }; pub trait FromSource: Sized { type Ast; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option; + fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option; } impl FromSource for Struct { type Ast = ast::StructDef; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { + fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { let id = from_source(db, src)?; Some(Struct { id }) } } impl FromSource for Union { type Ast = ast::UnionDef; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { + fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { let id = from_source(db, src)?; Some(Union { id }) } } impl FromSource for Enum { type Ast = ast::EnumDef; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { + fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { let id = from_source(db, src)?; Some(Enum { id }) } } impl FromSource for Trait { type Ast = ast::TraitDef; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { + fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { let id = from_source(db, src)?; Some(Trait { id }) } } impl FromSource for Function { type Ast = ast::FnDef; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { + fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? { Container::Trait(it) => it.items(db), Container::ImplBlock(it) => it.items(db), @@ -76,7 +76,7 @@ impl FromSource for Function { impl FromSource for Const { type Ast = ast::ConstDef; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { + fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? { Container::Trait(it) => it.items(db), Container::ImplBlock(it) => it.items(db), @@ -102,7 +102,7 @@ impl FromSource for Const { } impl FromSource for Static { type Ast = ast::StaticDef; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { + fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { let module = match Container::find(db, src.as_ref().map(|it| it.syntax()))? { Container::Module(it) => it, Container::Trait(_) | Container::ImplBlock(_) => return None, @@ -120,7 +120,7 @@ impl FromSource for Static { impl FromSource for TypeAlias { type Ast = ast::TypeAliasDef; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { + fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? { Container::Trait(it) => it.items(db), Container::ImplBlock(it) => it.items(db), @@ -147,11 +147,11 @@ impl FromSource for TypeAlias { impl FromSource for MacroDef { type Ast = ast::MacroCall; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { + fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { let kind = MacroDefKind::Declarative; let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); - let module = Module::from_definition(db, Source::new(src.file_id, module_src))?; + let module = Module::from_definition(db, InFile::new(src.file_id, module_src))?; let krate = module.krate().crate_id(); let ast_id = AstId::new(src.file_id, db.ast_id_map(src.file_id).ast_id(&src.value)); @@ -163,7 +163,7 @@ impl FromSource for MacroDef { impl FromSource for ImplBlock { type Ast = ast::ImplBlock; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { + fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { let id = from_source(db, src)?; Some(ImplBlock { id }) } @@ -171,9 +171,9 @@ impl FromSource for ImplBlock { impl FromSource for EnumVariant { type Ast = ast::EnumVariant; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { + fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { let parent_enum = src.value.parent_enum(); - let src_enum = Source { file_id: src.file_id, value: parent_enum }; + let src_enum = InFile { file_id: src.file_id, value: parent_enum }; let variants = Enum::from_source(db, src_enum)?.variants(db); variants.into_iter().find(|v| same_source(&v.source(db), &src)) } @@ -181,17 +181,17 @@ impl FromSource for EnumVariant { impl FromSource for StructField { type Ast = FieldSource; - fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { + fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option { let variant_def: VariantDef = match src.value { FieldSource::Named(ref field) => { let value = field.syntax().ancestors().find_map(ast::StructDef::cast)?; - let src = Source { file_id: src.file_id, value }; + let src = InFile { file_id: src.file_id, value }; let def = Struct::from_source(db, src)?; VariantDef::from(def) } FieldSource::Pos(ref field) => { let value = field.syntax().ancestors().find_map(ast::EnumVariant::cast)?; - let src = Source { file_id: src.file_id, value }; + let src = InFile { file_id: src.file_id, value }; let def = EnumVariant::from_source(db, src)?; VariantDef::from(def) } @@ -206,14 +206,14 @@ impl FromSource for StructField { } impl Local { - pub fn from_source(db: &impl HirDatabase, src: Source) -> Option { + pub fn from_source(db: &impl HirDatabase, src: InFile) -> Option { let file_id = src.file_id; let parent: DefWithBody = src.value.syntax().ancestors().find_map(|it| { let res = match_ast! { match it { - ast::ConstDef(value) => { Const::from_source(db, Source { value, file_id})?.into() }, - ast::StaticDef(value) => { Static::from_source(db, Source { value, file_id})?.into() }, - ast::FnDef(value) => { Function::from_source(db, Source { value, file_id})?.into() }, + ast::ConstDef(value) => { Const::from_source(db, InFile { value, file_id})?.into() }, + ast::StaticDef(value) => { Static::from_source(db, InFile { value, file_id})?.into() }, + ast::FnDef(value) => { Function::from_source(db, InFile { value, file_id})?.into() }, _ => return None, } }; @@ -227,16 +227,16 @@ impl Local { } impl Module { - pub fn from_declaration(db: &impl DefDatabase, src: Source) -> Option { + pub fn from_declaration(db: &impl DefDatabase, src: InFile) -> Option { let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast); let parent_module = match parent_declaration { Some(parent_declaration) => { - let src_parent = Source { file_id: src.file_id, value: parent_declaration }; + let src_parent = InFile { file_id: src.file_id, value: parent_declaration }; Module::from_declaration(db, src_parent) } _ => { - let src_parent = Source { + let src_parent = InFile { file_id: src.file_id, value: ModuleSource::new(db, Some(src.file_id.original_file(db)), None), }; @@ -248,13 +248,13 @@ impl Module { parent_module.child(db, &child_name.as_name()) } - pub fn from_definition(db: &impl DefDatabase, src: Source) -> Option { + pub fn from_definition(db: &impl DefDatabase, src: InFile) -> Option { match src.value { ModuleSource::Module(ref module) => { assert!(!module.has_semi()); return Module::from_declaration( db, - Source { file_id: src.file_id, value: module.clone() }, + InFile { file_id: src.file_id, value: module.clone() }, ); } ModuleSource::SourceFile(_) => (), @@ -271,13 +271,13 @@ impl Module { } } -fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option +fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile) -> Option where N: AstNode, DEF: AstItemDef, { let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); - let module = Module::from_definition(db, Source::new(src.file_id, module_src))?; + let module = Module::from_definition(db, InFile::new(src.file_id, module_src))?; let ctx = LocationCtx::new(db, module.id, src.file_id); let items = db.ast_id_map(src.file_id); let item_id = items.ast_id(&src.value); @@ -291,7 +291,7 @@ enum Container { } impl Container { - fn find(db: &impl DefDatabase, src: Source<&SyntaxNode>) -> Option { + fn find(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> Option { // FIXME: this doesn't try to handle nested declarations for container in src.value.ancestors() { let res = match_ast! { @@ -322,6 +322,6 @@ impl Container { /// In general, we do not guarantee that we have exactly one instance of a /// syntax tree for each file. We probably should add such guarantee, but, for /// the time being, we will use identity-less AstPtr comparison. -fn same_source(s1: &Source, s2: &Source) -> bool { +fn same_source(s1: &InFile, s2: &InFile) -> bool { s1.as_ref().map(AstPtr::new) == s2.as_ref().map(AstPtr::new) } -- cgit v1.2.3