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_assists/src/assist_ctx.rs | 4 +- crates/ra_assists/src/assists/add_new.rs | 6 +-- crates/ra_hir/src/code_model.rs | 6 +-- crates/ra_hir/src/code_model/src.rs | 36 ++++++------- crates/ra_hir/src/from_source.rs | 62 +++++++++++----------- crates/ra_hir/src/lib.rs | 2 +- crates/ra_hir/src/source_binder.rs | 28 +++++----- crates/ra_hir_def/src/adt.rs | 6 +-- crates/ra_hir_def/src/attr.rs | 6 +-- crates/ra_hir_def/src/body.rs | 14 ++--- crates/ra_hir_def/src/body/scope.rs | 6 +-- crates/ra_hir_def/src/diagnostics.rs | 6 +-- crates/ra_hir_def/src/lib.rs | 26 ++++----- crates/ra_hir_def/src/nameres.rs | 14 ++--- crates/ra_hir_def/src/nameres/raw.rs | 6 +-- crates/ra_hir_def/src/path.rs | 4 +- crates/ra_hir_expand/src/diagnostics.rs | 4 +- crates/ra_hir_expand/src/lib.rs | 42 +++++++-------- crates/ra_hir_ty/src/diagnostics.rs | 14 ++--- crates/ra_hir_ty/src/tests.rs | 4 +- crates/ra_ide/src/call_info.rs | 2 +- crates/ra_ide/src/completion/completion_context.rs | 4 +- crates/ra_ide/src/diagnostics.rs | 2 +- crates/ra_ide/src/display/navigation_target.rs | 4 +- crates/ra_ide/src/expand.rs | 8 +-- crates/ra_ide/src/expand_macro.rs | 8 +-- crates/ra_ide/src/goto_definition.rs | 8 +-- crates/ra_ide/src/hover.rs | 2 +- crates/ra_ide/src/impls.rs | 10 ++-- crates/ra_ide/src/inlay_hints.rs | 2 +- crates/ra_ide/src/parent_module.rs | 4 +- crates/ra_ide/src/references.rs | 8 +-- crates/ra_ide/src/references/classify.rs | 6 +-- crates/ra_ide/src/references/rename.rs | 2 +- crates/ra_ide/src/runnables.rs | 6 +-- crates/ra_ide/src/syntax_highlighting.rs | 6 +-- 36 files changed, 189 insertions(+), 189 deletions(-) diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 0ea84d548..993aebc47 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs @@ -1,5 +1,5 @@ //! This module defines `AssistCtx` -- the API surface that is exposed to assists. -use hir::{db::HirDatabase, SourceAnalyzer}; +use hir::{db::HirDatabase, InFile, SourceAnalyzer}; use ra_db::FileRange; use ra_fmt::{leading_indent, reindent}; use ra_syntax::{ @@ -117,7 +117,7 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> { node: &SyntaxNode, offset: Option, ) -> SourceAnalyzer { - SourceAnalyzer::new(self.db, hir::Source::new(self.frange.file_id.into(), node), offset) + SourceAnalyzer::new(self.db, InFile::new(self.frange.file_id.into(), node), offset) } pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement { diff --git a/crates/ra_assists/src/assists/add_new.rs b/crates/ra_assists/src/assists/add_new.rs index 8f68bd5fb..f977547fb 100644 --- a/crates/ra_assists/src/assists/add_new.rs +++ b/crates/ra_assists/src/assists/add_new.rs @@ -1,5 +1,5 @@ use format_buf::format; -use hir::{db::HirDatabase, FromSource}; +use hir::{db::HirDatabase, FromSource, InFile}; use join_to_string::join; use ra_syntax::{ ast::{ @@ -141,7 +141,7 @@ fn find_struct_impl( })?; let struct_ty = { - let src = hir::Source { file_id: ctx.frange.file_id.into(), value: strukt.clone() }; + let src = InFile { file_id: ctx.frange.file_id.into(), value: strukt.clone() }; hir::Struct::from_source(db, src).unwrap().ty(db) }; @@ -152,7 +152,7 @@ fn find_struct_impl( return false; } - let src = hir::Source { file_id: ctx.frange.file_id.into(), value: impl_blk.clone() }; + let src = InFile { file_id: ctx.frange.file_id.into(), value: impl_blk.clone() }; let blk = hir::ImplBlock::from_source(db, src).unwrap(); let same_ty = blk.target_ty(db) == struct_ty; diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 38d66c2a7..dddac915b 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -30,7 +30,7 @@ use crate::{ db::{DefDatabase, HirDatabase}, ty::display::HirFormatter, ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk}, - CallableDef, Either, HirDisplay, Name, Source, + CallableDef, Either, HirDisplay, InFile, Name, }; /// hir::Crate describes a single crate. It's the main interface with which @@ -118,7 +118,7 @@ impl ModuleSource { } } - pub fn from_child_node(db: &impl DefDatabase, child: Source<&SyntaxNode>) -> ModuleSource { + pub fn from_child_node(db: &impl DefDatabase, child: InFile<&SyntaxNode>) -> ModuleSource { if let Some(m) = child.value.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) { @@ -901,7 +901,7 @@ impl Local { Type { krate, ty: InEnvironment { value: ty, environment } } } - pub fn source(self, db: &impl HirDatabase) -> Source> { + pub fn source(self, db: &impl HirDatabase) -> InFile> { let (_body, source_map) = db.body_with_source_map(self.parent.into()); let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm... let root = src.file_syntax(db); diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index bf3ee0834..6fd4e7987 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs @@ -9,18 +9,18 @@ use crate::{ Module, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, }; -pub use hir_expand::Source; +pub use hir_expand::InFile; pub trait HasSource { type Ast; - fn source(self, db: &impl DefDatabase) -> Source; + fn source(self, db: &impl DefDatabase) -> InFile; } /// NB: Module is !HasSource, because it has two source nodes at the same time: /// definition and declaration. impl Module { /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. - pub fn definition_source(self, db: &impl DefDatabase) -> Source { + pub fn definition_source(self, db: &impl DefDatabase) -> InFile { let def_map = db.crate_def_map(self.id.krate); let src = def_map[self.id.local_id].definition_source(db); src.map(|it| match it { @@ -31,7 +31,7 @@ impl Module { /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. /// `None` for the crate root. - pub fn declaration_source(self, db: &impl DefDatabase) -> Option> { + pub fn declaration_source(self, db: &impl DefDatabase) -> Option> { let def_map = db.crate_def_map(self.id.krate); def_map[self.id.local_id].declaration_source(db) } @@ -39,7 +39,7 @@ impl Module { impl HasSource for StructField { type Ast = FieldSource; - fn source(self, db: &impl DefDatabase) -> Source { + fn source(self, db: &impl DefDatabase) -> InFile { let var = VariantId::from(self.parent); let src = var.child_source(db); src.map(|it| match it[self.id].clone() { @@ -50,67 +50,67 @@ impl HasSource for StructField { } impl HasSource for Struct { type Ast = ast::StructDef; - fn source(self, db: &impl DefDatabase) -> Source { + fn source(self, db: &impl DefDatabase) -> InFile { self.id.source(db) } } impl HasSource for Union { type Ast = ast::UnionDef; - fn source(self, db: &impl DefDatabase) -> Source { + fn source(self, db: &impl DefDatabase) -> InFile { self.id.source(db) } } impl HasSource for Enum { type Ast = ast::EnumDef; - fn source(self, db: &impl DefDatabase) -> Source { + fn source(self, db: &impl DefDatabase) -> InFile { self.id.source(db) } } impl HasSource for EnumVariant { type Ast = ast::EnumVariant; - fn source(self, db: &impl DefDatabase) -> Source { + fn source(self, db: &impl DefDatabase) -> InFile { self.parent.id.child_source(db).map(|map| map[self.id].clone()) } } impl HasSource for Function { type Ast = ast::FnDef; - fn source(self, db: &impl DefDatabase) -> Source { + fn source(self, db: &impl DefDatabase) -> InFile { self.id.lookup(db).source(db) } } impl HasSource for Const { type Ast = ast::ConstDef; - fn source(self, db: &impl DefDatabase) -> Source { + fn source(self, db: &impl DefDatabase) -> InFile { self.id.lookup(db).source(db) } } impl HasSource for Static { type Ast = ast::StaticDef; - fn source(self, db: &impl DefDatabase) -> Source { + fn source(self, db: &impl DefDatabase) -> InFile { self.id.lookup(db).source(db) } } impl HasSource for Trait { type Ast = ast::TraitDef; - fn source(self, db: &impl DefDatabase) -> Source { + fn source(self, db: &impl DefDatabase) -> InFile { self.id.source(db) } } impl HasSource for TypeAlias { type Ast = ast::TypeAliasDef; - fn source(self, db: &impl DefDatabase) -> Source { + fn source(self, db: &impl DefDatabase) -> InFile { self.id.lookup(db).source(db) } } impl HasSource for MacroDef { type Ast = ast::MacroCall; - fn source(self, db: &impl DefDatabase) -> Source { - Source { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) } + fn source(self, db: &impl DefDatabase) -> InFile { + InFile { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) } } } impl HasSource for ImplBlock { type Ast = ast::ImplBlock; - fn source(self, db: &impl DefDatabase) -> Source { + fn source(self, db: &impl DefDatabase) -> InFile { self.id.source(db) } } @@ -118,7 +118,7 @@ impl HasSource for Import { type Ast = Either; /// Returns the syntax of the last path segment corresponding to this import - fn source(self, db: &impl DefDatabase) -> Source { + fn source(self, db: &impl DefDatabase) -> InFile { let src = self.parent.definition_source(db); let (_, source_map) = db.raw_items_with_source_map(src.file_id); let root = db.parse_or_expand(src.file_id).unwrap(); 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) } diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 3c12c61f0..88d2f6e02 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -63,5 +63,5 @@ pub use hir_def::{ type_ref::Mutability, }; pub use hir_expand::{ - either::Either, name::Name, HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Source, + either::Either, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, }; diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 76c493f1a..1661d92a2 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -18,7 +18,7 @@ use hir_def::{ AssocItemId, DefWithBodyId, }; use hir_expand::{ - hygiene::Hygiene, name::AsName, AstId, HirFileId, MacroCallId, MacroFileKind, Source, + hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroFileKind, }; use ra_syntax::{ ast::{self, AstNode}, @@ -37,7 +37,7 @@ use crate::{ GenericParam, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, }; -fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option { +fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option { match_ast! { match (node.value) { ast::Module(it) => { @@ -71,7 +71,7 @@ fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) - fn def_with_body_from_child_node( db: &impl HirDatabase, - child: Source<&SyntaxNode>, + child: InFile<&SyntaxNode>, ) -> Option { child.value.ancestors().find_map(|node| { match_ast! { @@ -141,8 +141,8 @@ impl Expansion { pub fn map_token_down( &self, db: &impl HirDatabase, - token: Source<&SyntaxToken>, - ) -> Option> { + token: InFile<&SyntaxToken>, + ) -> Option> { let exp_info = self.file_id().expansion_info(db)?; exp_info.map_token_down(token) } @@ -155,7 +155,7 @@ impl Expansion { impl SourceAnalyzer { pub fn new( db: &impl HirDatabase, - node: Source<&SyntaxNode>, + node: InFile<&SyntaxNode>, offset: Option, ) -> SourceAnalyzer { let def_with_body = def_with_body_from_child_node(db, node); @@ -192,12 +192,12 @@ impl SourceAnalyzer { } fn expr_id(&self, expr: &ast::Expr) -> Option { - let src = Source { file_id: self.file_id, value: expr }; + let src = InFile { file_id: self.file_id, value: expr }; self.body_source_map.as_ref()?.node_expr(src) } fn pat_id(&self, pat: &ast::Pat) -> Option { - let src = Source { file_id: self.file_id, value: pat }; + let src = InFile { file_id: self.file_id, value: pat }; self.body_source_map.as_ref()?.node_pat(src) } @@ -243,7 +243,7 @@ impl SourceAnalyzer { pub fn resolve_macro_call( &self, db: &impl HirDatabase, - macro_call: Source<&ast::MacroCall>, + macro_call: InFile<&ast::MacroCall>, ) -> Option { let hygiene = Hygiene::new(db, macro_call.file_id); let path = macro_call.value.path().and_then(|ast| Path::from_src(ast, &hygiene))?; @@ -318,7 +318,7 @@ impl SourceAnalyzer { let name = name_ref.as_name(); let source_map = self.body_source_map.as_ref()?; let scopes = self.scopes.as_ref()?; - let scope = scope_for(scopes, source_map, Source::new(self.file_id, name_ref.syntax()))?; + let scope = scope_for(scopes, source_map, InFile::new(self.file_id, name_ref.syntax()))?; let entry = scopes.resolve_name_in_scope(scope, &name)?; Some(ScopeEntryWithSyntax { name: entry.name().clone(), @@ -446,7 +446,7 @@ impl SourceAnalyzer { pub fn expand( &self, db: &impl HirDatabase, - macro_call: Source<&ast::MacroCall>, + macro_call: InFile<&ast::MacroCall>, ) -> Option { let def = self.resolve_macro_call(db, macro_call)?.id; let ast_id = AstId::new( @@ -463,19 +463,19 @@ impl SourceAnalyzer { fn scope_for( scopes: &ExprScopes, source_map: &BodySourceMap, - node: Source<&SyntaxNode>, + node: InFile<&SyntaxNode>, ) -> Option { node.value .ancestors() .filter_map(ast::Expr::cast) - .filter_map(|it| source_map.node_expr(Source::new(node.file_id, &it))) + .filter_map(|it| source_map.node_expr(InFile::new(node.file_id, &it))) .find_map(|it| scopes.scope_for(it)) } fn scope_for_offset( scopes: &ExprScopes, source_map: &BodySourceMap, - offset: Source, + offset: InFile, ) -> Option { scopes .scope_by_expr() diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index 3666529b0..3d21dedee 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use hir_expand::{ either::Either, name::{AsName, Name}, - Source, + InFile, }; use ra_arena::{map::ArenaMap, Arena}; use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; @@ -88,7 +88,7 @@ impl EnumData { impl HasChildSource for EnumId { type ChildId = LocalEnumVariantId; type Value = ast::EnumVariant; - fn child_source(&self, db: &impl DefDatabase) -> Source> { + fn child_source(&self, db: &impl DefDatabase) -> InFile> { let src = self.source(db); let mut trace = Trace::new_for_map(); lower_enum(&mut trace, &src.value); @@ -145,7 +145,7 @@ impl HasChildSource for VariantId { type ChildId = LocalStructFieldId; type Value = Either; - fn child_source(&self, db: &impl DefDatabase) -> Source> { + fn child_source(&self, db: &impl DefDatabase) -> InFile> { let src = match self { VariantId::EnumVariantId(it) => { // I don't really like the fact that we call into parent source diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index fffb22201..83783ac7a 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs @@ -2,7 +2,7 @@ use std::{ops, sync::Arc}; -use hir_expand::{either::Either, hygiene::Hygiene, AstId, Source}; +use hir_expand::{either::Either, hygiene::Hygiene, AstId, InFile}; use mbe::ast_to_token_tree; use ra_syntax::{ ast::{self, AstNode, AttrsOwner}, @@ -68,7 +68,7 @@ impl Attrs { } } - fn from_attrs_owner(db: &impl DefDatabase, owner: Source<&dyn AttrsOwner>) -> Attrs { + fn from_attrs_owner(db: &impl DefDatabase, owner: InFile<&dyn AttrsOwner>) -> Attrs { let hygiene = Hygiene::new(db, owner.file_id); Attrs::new(owner.value, &hygiene) } @@ -157,7 +157,7 @@ where N: ast::AttrsOwner, D: DefDatabase, { - let src = Source::new(src.file_id(), src.to_node(db)); + let src = InFile::new(src.file_id(), src.to_node(db)); Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner)) } diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index a57a0176d..f21937f10 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs @@ -6,7 +6,7 @@ pub mod scope; use std::{ops::Index, sync::Arc}; use hir_expand::{ - either::Either, hygiene::Hygiene, AstId, HirFileId, MacroDefId, MacroFileKind, Source, + either::Either, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId, MacroFileKind, }; use ra_arena::{map::ArenaMap, Arena}; use ra_syntax::{ast, AstNode, AstPtr}; @@ -73,8 +73,8 @@ impl Expander { std::mem::forget(mark); } - fn to_source(&self, value: T) -> Source { - Source { file_id: self.current_file_id, value } + fn to_source(&self, value: T) -> InFile { + InFile { file_id: self.current_file_id, value } } fn parse_path(&mut self, path: ast::Path) -> Option { @@ -115,10 +115,10 @@ pub struct Body { } pub type ExprPtr = Either, AstPtr>; -pub type ExprSource = Source; +pub type ExprSource = InFile; pub type PatPtr = Either, AstPtr>; -pub type PatSource = Source; +pub type PatSource = InFile; /// An item body together with the mapping from syntax nodes to HIR expression /// IDs. This is needed to go from e.g. a position in a file to the HIR @@ -205,7 +205,7 @@ impl BodySourceMap { self.expr_map_back.get(expr).copied() } - pub fn node_expr(&self, node: Source<&ast::Expr>) -> Option { + pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option { let src = node.map(|it| Either::A(AstPtr::new(it))); self.expr_map.get(&src).cloned() } @@ -214,7 +214,7 @@ impl BodySourceMap { self.pat_map_back.get(pat).copied() } - pub fn node_pat(&self, node: Source<&ast::Pat>) -> Option { + pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option { let src = node.map(|it| Either::A(AstPtr::new(it))); self.pat_map.get(&src).cloned() } diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs index 625aa39dd..ab6599b23 100644 --- a/crates/ra_hir_def/src/body/scope.rs +++ b/crates/ra_hir_def/src/body/scope.rs @@ -171,7 +171,7 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope #[cfg(test)] mod tests { - use hir_expand::{name::AsName, Source}; + use hir_expand::{name::AsName, InFile}; use ra_db::{fixture::WithFixture, FileId, SourceDatabase}; use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; use test_utils::{assert_eq_text, covers, extract_offset}; @@ -211,7 +211,7 @@ mod tests { let (_body, source_map) = db.body_with_source_map(function.into()); let expr_id = source_map - .node_expr(Source { file_id: file_id.into(), value: &marker.into() }) + .node_expr(InFile { file_id: file_id.into(), value: &marker.into() }) .unwrap(); let scope = scopes.scope_for(expr_id); @@ -318,7 +318,7 @@ mod tests { let expr_scope = { let expr_ast = name_ref.syntax().ancestors().find_map(ast::Expr::cast).unwrap(); let expr_id = - source_map.node_expr(Source { file_id: file_id.into(), value: &expr_ast }).unwrap(); + source_map.node_expr(InFile { file_id: file_id.into(), value: &expr_ast }).unwrap(); scopes.scope_for(expr_id).unwrap() }; diff --git a/crates/ra_hir_def/src/diagnostics.rs b/crates/ra_hir_def/src/diagnostics.rs index eda9b2269..095498429 100644 --- a/crates/ra_hir_def/src/diagnostics.rs +++ b/crates/ra_hir_def/src/diagnostics.rs @@ -6,7 +6,7 @@ use hir_expand::diagnostics::Diagnostic; use ra_db::RelativePathBuf; use ra_syntax::{ast, AstPtr, SyntaxNodePtr}; -use hir_expand::{HirFileId, Source}; +use hir_expand::{HirFileId, InFile}; #[derive(Debug)] pub struct UnresolvedModule { @@ -19,8 +19,8 @@ impl Diagnostic for UnresolvedModule { fn message(&self) -> String { "unresolved module".to_string() } - fn source(&self) -> Source { - Source { file_id: self.file, value: self.decl.into() } + fn source(&self) -> InFile { + InFile { file_id: self.file, value: self.decl.into() } } fn as_any(&self) -> &(dyn Any + Send + 'static) { self diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index bc5530896..9d89692bf 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -36,7 +36,7 @@ mod marks; use std::hash::{Hash, Hasher}; -use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, MacroDefId, Source}; +use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, InFile, MacroDefId}; use ra_arena::{impl_arena_id, map::ArenaMap, RawId}; use ra_db::{impl_intern_key, salsa, CrateId}; use ra_syntax::{ast, AstNode}; @@ -105,10 +105,10 @@ pub trait AstItemDef: salsa::InternKey + Clone { let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) }; Self::intern(ctx.db, loc) } - fn source(self, db: &(impl AstDatabase + InternDatabase)) -> Source { + fn source(self, db: &(impl AstDatabase + InternDatabase)) -> InFile { let loc = self.lookup_intern(db); let value = loc.ast_id.to_node(db); - Source { file_id: loc.ast_id.file_id(), value } + InFile { file_id: loc.ast_id.file_id(), value } } fn module(self, db: &impl InternDatabase) -> ModuleId { let loc = self.lookup_intern(db); @@ -517,42 +517,42 @@ impl HasModule for StaticLoc { pub trait HasSource { type Value; - fn source(&self, db: &impl db::DefDatabase) -> Source; + fn source(&self, db: &impl db::DefDatabase) -> InFile; } impl HasSource for FunctionLoc { type Value = ast::FnDef; - fn source(&self, db: &impl db::DefDatabase) -> Source { + fn source(&self, db: &impl db::DefDatabase) -> InFile { let node = self.ast_id.to_node(db); - Source::new(self.ast_id.file_id(), node) + InFile::new(self.ast_id.file_id(), node) } } impl HasSource for TypeAliasLoc { type Value = ast::TypeAliasDef; - fn source(&self, db: &impl db::DefDatabase) -> Source { + fn source(&self, db: &impl db::DefDatabase) -> InFile { let node = self.ast_id.to_node(db); - Source::new(self.ast_id.file_id(), node) + InFile::new(self.ast_id.file_id(), node) } } impl HasSource for ConstLoc { type Value = ast::ConstDef; - fn source(&self, db: &impl db::DefDatabase) -> Source { + fn source(&self, db: &impl db::DefDatabase) -> InFile { let node = self.ast_id.to_node(db); - Source::new(self.ast_id.file_id(), node) + InFile::new(self.ast_id.file_id(), node) } } impl HasSource for StaticLoc { type Value = ast::StaticDef; - fn source(&self, db: &impl db::DefDatabase) -> Source { + fn source(&self, db: &impl db::DefDatabase) -> InFile { let node = self.ast_id.to_node(db); - Source::new(self.ast_id.file_id(), node) + InFile::new(self.ast_id.file_id(), node) } } @@ -562,5 +562,5 @@ pub trait HasChildSource { fn child_source( &self, db: &impl db::DefDatabase, - ) -> Source>; + ) -> InFile>; } diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 2359386c2..1b369ea11 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -58,8 +58,8 @@ mod tests; use std::sync::Arc; use hir_expand::{ - ast_id_map::FileAstId, diagnostics::DiagnosticSink, either::Either, name::Name, MacroDefId, - Source, + ast_id_map::FileAstId, diagnostics::DiagnosticSink, either::Either, name::Name, InFile, + MacroDefId, }; use once_cell::sync::Lazy; use ra_arena::Arena; @@ -261,21 +261,21 @@ impl ModuleData { pub fn definition_source( &self, db: &impl DefDatabase, - ) -> Source> { + ) -> InFile> { if let Some(file_id) = self.definition { let sf = db.parse(file_id).tree(); - return Source::new(file_id.into(), Either::A(sf)); + return InFile::new(file_id.into(), Either::A(sf)); } let decl = self.declaration.unwrap(); - Source::new(decl.file_id(), Either::B(decl.to_node(db))) + InFile::new(decl.file_id(), Either::B(decl.to_node(db))) } /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. /// `None` for the crate root. - pub fn declaration_source(&self, db: &impl DefDatabase) -> Option> { + pub fn declaration_source(&self, db: &impl DefDatabase) -> Option> { let decl = self.declaration?; let value = decl.to_node(db); - Some(Source { file_id: decl.file_id(), value }) + Some(InFile { file_id: decl.file_id(), value }) } } diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 6eb106094..5196b67ca 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -22,8 +22,8 @@ use ra_syntax::{ use test_utils::tested_by; use crate::{ - attr::Attrs, db::DefDatabase, path::Path, trace::Trace, FileAstId, HirFileId, LocalImportId, - Source, + attr::Attrs, db::DefDatabase, path::Path, trace::Trace, FileAstId, HirFileId, InFile, + LocalImportId, }; /// `RawItems` is a set of top-level items in a file (except for impls). @@ -313,7 +313,7 @@ impl RawItemsCollector { let mut buf = Vec::new(); Path::expand_use_item( - Source { value: use_item, file_id: self.file_id }, + InFile { value: use_item, file_id: self.file_id }, &self.hygiene, |path, use_tree, is_glob, alias| { let import_data = ImportData { diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index 6810a26db..10688df4d 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs @@ -13,7 +13,7 @@ use ra_syntax::{ AstNode, }; -use crate::{type_ref::TypeRef, Source}; +use crate::{type_ref::TypeRef, InFile}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Path { @@ -67,7 +67,7 @@ pub enum PathKind { impl Path { /// Calls `cb` with all paths, represented by this use item. pub(crate) fn expand_use_item( - item_src: Source, + item_src: InFile, hygiene: &Hygiene, mut cb: impl FnMut(Path, &ast::UseTree, bool, Option), ) { diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs index 3d37e9335..108c1e38c 100644 --- a/crates/ra_hir_expand/src/diagnostics.rs +++ b/crates/ra_hir_expand/src/diagnostics.rs @@ -18,11 +18,11 @@ use std::{any::Any, fmt}; use ra_syntax::{SyntaxNode, SyntaxNodePtr, TextRange}; -use crate::{db::AstDatabase, Source}; +use crate::{db::AstDatabase, InFile}; pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { fn message(&self) -> String; - fn source(&self) -> Source; + fn source(&self) -> InFile; fn highlight_range(&self) -> TextRange { self.source().value.range() } diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index b6a739cda..2c5b6b2bb 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -90,9 +90,9 @@ impl HirFileId { let macro_arg = db.macro_arg(macro_file.macro_call_id)?; Some(ExpansionInfo { - expanded: Source::new(self, parse.syntax_node()), - arg: Source::new(loc.ast_id.file_id, arg_tt), - def: Source::new(loc.ast_id.file_id, def_tt), + expanded: InFile::new(self, parse.syntax_node()), + arg: InFile::new(loc.ast_id.file_id, arg_tt), + def: InFile::new(loc.ast_id.file_id, def_tt), macro_arg, macro_def, exp_map, @@ -167,9 +167,9 @@ impl MacroCallId { /// ExpansionInfo mainly describes how to map text range between src and expanded macro #[derive(Debug, Clone, PartialEq, Eq)] pub struct ExpansionInfo { - expanded: Source, - arg: Source, - def: Source, + expanded: InFile, + arg: InFile, + def: InFile, macro_def: Arc<(db::TokenExpander, mbe::TokenMap)>, macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>, @@ -177,7 +177,7 @@ pub struct ExpansionInfo { } impl ExpansionInfo { - pub fn map_token_down(&self, token: Source<&SyntaxToken>) -> Option> { + pub fn map_token_down(&self, token: InFile<&SyntaxToken>) -> Option> { assert_eq!(token.file_id, self.arg.file_id); let range = token.value.text_range().checked_sub(self.arg.value.syntax().text_range().start())?; @@ -191,7 +191,7 @@ impl ExpansionInfo { Some(self.expanded.with_value(token)) } - pub fn map_token_up(&self, token: Source<&SyntaxToken>) -> Option> { + pub fn map_token_up(&self, token: InFile<&SyntaxToken>) -> Option> { let token_id = self.exp_map.token_by_range(token.value.text_range())?; let (token_id, origin) = self.macro_def.0.map_id_up(token_id); @@ -254,33 +254,33 @@ impl AstId { } } -/// `Source` stores a value of `T` inside a particular file/syntax tree. +/// `InFile` stores a value of `T` inside a particular file/syntax tree. /// /// Typical usages are: /// -/// * `Source` -- syntax node in a file -/// * `Source` -- ast node in a file -/// * `Source` -- offset in a file +/// * `InFile` -- syntax node in a file +/// * `InFile` -- ast node in a file +/// * `InFile` -- offset in a file #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] -pub struct Source { +pub struct InFile { pub file_id: HirFileId, pub value: T, } -impl Source { - pub fn new(file_id: HirFileId, value: T) -> Source { - Source { file_id, value } +impl InFile { + pub fn new(file_id: HirFileId, value: T) -> InFile { + InFile { file_id, value } } // Similarly, naming here is stupid... - pub fn with_value(&self, value: U) -> Source { - Source::new(self.file_id, value) + pub fn with_value(&self, value: U) -> InFile { + InFile::new(self.file_id, value) } - pub fn map U, U>(self, f: F) -> Source { - Source::new(self.file_id, f(self.value)) + pub fn map U, U>(self, f: F) -> InFile { + InFile::new(self.file_id, f(self.value)) } - pub fn as_ref(&self) -> Source<&T> { + pub fn as_ref(&self) -> InFile<&T> { self.with_value(&self.value) } pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode { diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 4a13fac23..5054189cc 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs @@ -2,7 +2,7 @@ use std::any::Any; -use hir_expand::{db::AstDatabase, name::Name, HirFileId, Source}; +use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; pub use hir_def::diagnostics::UnresolvedModule; @@ -19,8 +19,8 @@ impl Diagnostic for NoSuchField { "no such field".to_string() } - fn source(&self) -> Source { - Source { file_id: self.file, value: self.field.into() } + fn source(&self) -> InFile { + InFile { file_id: self.file, value: self.field.into() } } fn as_any(&self) -> &(dyn Any + Send + 'static) { @@ -44,8 +44,8 @@ impl Diagnostic for MissingFields { } message } - fn source(&self) -> Source { - Source { file_id: self.file, value: self.field_list.into() } + fn source(&self) -> InFile { + InFile { file_id: self.file, value: self.field_list.into() } } fn as_any(&self) -> &(dyn Any + Send + 'static) { self @@ -72,8 +72,8 @@ impl Diagnostic for MissingOkInTailExpr { fn message(&self) -> String { "wrap return expression in Ok".to_string() } - fn source(&self) -> Source { - Source { file_id: self.file, value: self.expr.into() } + fn source(&self) -> InFile { + InFile { file_id: self.file, value: self.expr.into() } } fn as_any(&self) -> &(dyn Any + Send + 'static) { self diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index c8461b447..abbc1546c 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs @@ -8,7 +8,7 @@ use hir_def::{ body::BodySourceMap, db::DefDatabase, nameres::CrateDefMap, AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, }; -use hir_expand::Source; +use hir_expand::InFile; use insta::assert_snapshot; use ra_db::{fixture::WithFixture, salsa::Database, FilePosition, SourceDatabase}; use ra_syntax::{ @@ -4680,7 +4680,7 @@ fn type_at_pos(db: &TestDB, pos: FilePosition) -> String { for decl in crate_def_map[module.local_id].scope.declarations() { if let ModuleDefId::FunctionId(func) = decl { let (_body, source_map) = db.body_with_source_map(func.into()); - if let Some(expr_id) = source_map.node_expr(Source::new(pos.file_id.into(), &expr)) { + if let Some(expr_id) = source_map.node_expr(InFile::new(pos.file_id.into(), &expr)) { let infer = db.infer(func.into()); let ty = &infer[expr_id]; return ty.display(db).to_string(); diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index d559dc4d0..b3c323d38 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs @@ -18,7 +18,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option CompletionContext<'a> { let src = hir::ModuleSource::from_position(db, position); let module = hir::Module::from_definition( db, - hir::Source { file_id: position.file_id.into(), value: src }, + hir::InFile { file_id: position.file_id.into(), value: src }, ); let token = original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?; let analyzer = hir::SourceAnalyzer::new( db, - hir::Source::new(position.file_id.into(), &token.parent()), + hir::InFile::new(position.file_id.into(), &token.parent()), Some(position.offset), ); let mut ctx = CompletionContext { diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index cc1ccab4b..c50a70d99 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs @@ -96,7 +96,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec }); let source_file = db.parse(file_id).tree(); let src = - hir::Source { file_id: file_id.into(), value: hir::ModuleSource::SourceFile(source_file) }; + hir::InFile { file_id: file_id.into(), value: hir::ModuleSource::SourceFile(source_file) }; if let Some(m) = hir::Module::from_definition(db, src) { m.diagnostics(db, &mut sink); }; diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 6ac60722b..61dca14ac 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir::{AssocItem, Either, FieldSource, HasSource, ModuleSource, Source}; +use hir::{AssocItem, Either, FieldSource, HasSource, InFile, ModuleSource}; use ra_db::{FileId, SourceDatabase}; use ra_syntax::{ ast::{self, DocCommentsOwner, NameOwner}, @@ -141,7 +141,7 @@ impl NavigationTarget { /// Allows `NavigationTarget` to be created from a `NameOwner` pub(crate) fn from_named( db: &RootDatabase, - node: Source<&dyn ast::NameOwner>, + node: InFile<&dyn ast::NameOwner>, docs: Option, description: Option, ) -> NavigationTarget { diff --git a/crates/ra_ide/src/expand.rs b/crates/ra_ide/src/expand.rs index 2f1abf509..216d5cfec 100644 --- a/crates/ra_ide/src/expand.rs +++ b/crates/ra_ide/src/expand.rs @@ -1,13 +1,13 @@ //! Utilities to work with files, produced by macros. use std::iter::successors; -use hir::Source; +use hir::InFile; use ra_db::FileId; use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxToken}; use crate::{db::RootDatabase, FileRange}; -pub(crate) fn original_range(db: &RootDatabase, node: Source<&SyntaxNode>) -> FileRange { +pub(crate) fn original_range(db: &RootDatabase, node: InFile<&SyntaxNode>) -> FileRange { let expansion = match node.file_id.expansion_info(db) { None => { return FileRange { @@ -44,8 +44,8 @@ pub(crate) fn descend_into_macros( db: &RootDatabase, file_id: FileId, token: SyntaxToken, -) -> Source { - let src = Source::new(file_id.into(), token); +) -> InFile { + let src = InFile::new(file_id.into(), token); successors(Some(src), |token| { let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?; diff --git a/crates/ra_ide/src/expand_macro.rs b/crates/ra_ide/src/expand_macro.rs index abc602244..862c03304 100644 --- a/crates/ra_ide/src/expand_macro.rs +++ b/crates/ra_ide/src/expand_macro.rs @@ -22,7 +22,7 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option< let name_ref = find_node_at_offset::(file.syntax(), position.offset)?; let mac = name_ref.syntax().ancestors().find_map(ast::MacroCall::cast)?; - let source = hir::Source::new(position.file_id.into(), mac.syntax()); + let source = hir::InFile::new(position.file_id.into(), mac.syntax()); let expanded = expand_macro_recur(db, source, source.with_value(&mac))?; // FIXME: @@ -34,8 +34,8 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option< fn expand_macro_recur( db: &RootDatabase, - source: hir::Source<&SyntaxNode>, - macro_call: hir::Source<&ast::MacroCall>, + source: hir::InFile<&SyntaxNode>, + macro_call: hir::InFile<&ast::MacroCall>, ) -> Option { let analyzer = hir::SourceAnalyzer::new(db, source, None); let expansion = analyzer.expand(db, macro_call)?; @@ -46,7 +46,7 @@ fn expand_macro_recur( let mut replaces = FxHashMap::default(); for child in children.into_iter() { - let node = hir::Source::new(macro_file_id, &child); + let node = hir::InFile::new(macro_file_id, &child); if let Some(new_node) = expand_macro_recur(db, source, node) { // Replace the whole node if it is root // `replace_descendants` will not replace the parent node diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index c10a6c844..76a741207 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir::{db::AstDatabase, Source}; +use hir::{db::AstDatabase, InFile}; use ra_syntax::{ ast::{self, DocCommentsOwner}, match_ast, AstNode, SyntaxNode, @@ -58,7 +58,7 @@ impl ReferenceResult { pub(crate) fn reference_definition( db: &RootDatabase, - name_ref: Source<&ast::NameRef>, + name_ref: InFile<&ast::NameRef>, ) -> ReferenceResult { use self::ReferenceResult::*; @@ -94,7 +94,7 @@ pub(crate) fn reference_definition( pub(crate) fn name_definition( db: &RootDatabase, - name: Source<&ast::Name>, + name: InFile<&ast::Name>, ) -> Option> { let parent = name.value.syntax().parent()?; @@ -115,7 +115,7 @@ pub(crate) fn name_definition( None } -fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { +fn named_target(db: &RootDatabase, node: InFile<&SyntaxNode>) -> Option { match_ast! { match (node.value) { ast::StructDef(it) => { diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 260a7b869..d8185c688 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -227,7 +227,7 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option { .take_while(|it| it.text_range() == leaf_node.text_range()) .find(|it| ast::Expr::cast(it.clone()).is_some() || ast::Pat::cast(it.clone()).is_some())?; let analyzer = - hir::SourceAnalyzer::new(db, hir::Source::new(frange.file_id.into(), &node), None); + hir::SourceAnalyzer::new(db, hir::InFile::new(frange.file_id.into(), &node), None); let ty = if let Some(ty) = ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e)) { ty diff --git a/crates/ra_ide/src/impls.rs b/crates/ra_ide/src/impls.rs index aa480e399..9b165ee2a 100644 --- a/crates/ra_ide/src/impls.rs +++ b/crates/ra_ide/src/impls.rs @@ -16,7 +16,7 @@ pub(crate) fn goto_implementation( let src = hir::ModuleSource::from_position(db, position); let module = hir::Module::from_definition( db, - hir::Source { file_id: position.file_id.into(), value: src }, + hir::InFile { file_id: position.file_id.into(), value: src }, )?; if let Some(nominal_def) = find_node_at_offset::(&syntax, position.offset) { @@ -42,15 +42,15 @@ fn impls_for_def( ) -> Option> { let ty = match node { ast::NominalDef::StructDef(def) => { - let src = hir::Source { file_id: position.file_id.into(), value: def.clone() }; + let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; hir::Struct::from_source(db, src)?.ty(db) } ast::NominalDef::EnumDef(def) => { - let src = hir::Source { file_id: position.file_id.into(), value: def.clone() }; + let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; hir::Enum::from_source(db, src)?.ty(db) } ast::NominalDef::UnionDef(def) => { - let src = hir::Source { file_id: position.file_id.into(), value: def.clone() }; + let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() }; hir::Union::from_source(db, src)?.ty(db) } }; @@ -73,7 +73,7 @@ fn impls_for_trait( node: &ast::TraitDef, module: hir::Module, ) -> Option> { - let src = hir::Source { file_id: position.file_id.into(), value: node.clone() }; + let src = hir::InFile { file_id: position.file_id.into(), value: node.clone() }; let tr = hir::Trait::from_source(db, src)?; let krate = module.krate(); diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 45149bf0c..59eced9d7 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -38,7 +38,7 @@ fn get_inlay_hints( node: &SyntaxNode, max_inlay_hint_length: Option, ) -> Option> { - let analyzer = SourceAnalyzer::new(db, hir::Source::new(file_id.into(), node), None); + let analyzer = SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None); match_ast! { match node { ast::LetStmt(it) => { diff --git a/crates/ra_ide/src/parent_module.rs b/crates/ra_ide/src/parent_module.rs index 6027e7d54..616d69fce 100644 --- a/crates/ra_ide/src/parent_module.rs +++ b/crates/ra_ide/src/parent_module.rs @@ -10,7 +10,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec return Vec::new(), Some(it) => it, @@ -23,7 +23,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec Vec { let src = hir::ModuleSource::from_file_id(db, file_id); let module = - match hir::Module::from_definition(db, hir::Source { file_id: file_id.into(), value: src }) + match hir::Module::from_definition(db, hir::InFile { file_id: file_id.into(), value: src }) { Some(it) => it, None => return Vec::new(), diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 21a1ea69e..3e7bfd872 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -14,7 +14,7 @@ mod name_definition; mod rename; mod search_scope; -use hir::Source; +use hir::InFile; use once_cell::unsync::Lazy; use ra_db::{SourceDatabase, SourceDatabaseExt}; use ra_prof::profile; @@ -107,12 +107,12 @@ fn find_name<'a>( position: FilePosition, ) -> Option> { if let Some(name) = find_node_at_offset::(&syntax, position.offset) { - let def = classify_name(db, Source::new(position.file_id.into(), &name))?; + let def = classify_name(db, InFile::new(position.file_id.into(), &name))?; let range = name.syntax().text_range(); return Some(RangeInfo::new(range, (name.text().to_string(), def))); } let name_ref = find_node_at_offset::(&syntax, position.offset)?; - let def = classify_name_ref(db, Source::new(position.file_id.into(), &name_ref))?; + let def = classify_name_ref(db, InFile::new(position.file_id.into(), &name_ref))?; let range = name_ref.syntax().text_range(); Some(RangeInfo::new(range, (name_ref.text().to_string(), def))) } @@ -144,7 +144,7 @@ fn process_definition( continue; } } - if let Some(d) = classify_name_ref(db, Source::new(file_id.into(), &name_ref)) { + if let Some(d) = classify_name_ref(db, InFile::new(file_id.into(), &name_ref)) { if d == def { refs.push(FileRange { file_id, range }); } diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index 5cea805ec..b716d32e5 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs @@ -1,6 +1,6 @@ //! Functions that are used to classify an element from its definition or reference. -use hir::{FromSource, Module, ModuleSource, PathResolution, Source, SourceAnalyzer}; +use hir::{FromSource, InFile, Module, ModuleSource, PathResolution, SourceAnalyzer}; use ra_prof::profile; use ra_syntax::{ast, match_ast, AstNode}; use test_utils::tested_by; @@ -11,7 +11,7 @@ use super::{ }; use crate::db::RootDatabase; -pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Option { +pub(crate) fn classify_name(db: &RootDatabase, name: InFile<&ast::Name>) -> Option { let _p = profile("classify_name"); let parent = name.value.syntax().parent()?; @@ -117,7 +117,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti pub(crate) fn classify_name_ref( db: &RootDatabase, - name_ref: Source<&ast::NameRef>, + name_ref: InFile<&ast::NameRef>, ) -> Option { let _p = profile("classify_name_ref"); diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index d58496049..ea6b354c2 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -55,7 +55,7 @@ fn rename_mod( ) -> Option { let mut source_file_edits = Vec::new(); let mut file_system_edits = Vec::new(); - let module_src = hir::Source { file_id: position.file_id.into(), value: ast_module.clone() }; + let module_src = hir::InFile { file_id: position.file_id.into(), value: ast_module.clone() }; if let Some(module) = hir::Module::from_declaration(db, module_src) { let src = module.definition_source(db); let file_id = src.file_id.original_file(db); diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index 8039a5164..e213e1a06 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir::Source; +use hir::InFile; use itertools::Itertools; use ra_db::SourceDatabase; use ra_syntax::{ @@ -66,8 +66,8 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Opti return None; } let range = module.syntax().text_range(); - let src = hir::ModuleSource::from_child_node(db, Source::new(file_id.into(), &module.syntax())); - let module = hir::Module::from_definition(db, Source::new(file_id.into(), src))?; + let src = hir::ModuleSource::from_child_node(db, InFile::new(file_id.into(), &module.syntax())); + let module = hir::Module::from_definition(db, InFile::new(file_id.into(), src))?; let path = module.path_to_root(db).into_iter().rev().filter_map(|it| it.name(db)).join("::"); Some(Runnable { range, kind: RunnableKind::TestMod { path } }) diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 9a3e4c82f..e6a79541f 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -2,7 +2,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; -use hir::{Name, Source}; +use hir::{InFile, Name}; use ra_db::SourceDatabase; use ra_prof::profile; use ra_syntax::{ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::*, TextRange, T}; @@ -81,7 +81,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec Vec { let name = node.as_node().cloned().and_then(ast::Name::cast).unwrap(); let name_kind = - classify_name(db, Source::new(file_id.into(), &name)).map(|d| d.kind); + classify_name(db, InFile::new(file_id.into(), &name)).map(|d| d.kind); if let Some(Local(local)) = &name_kind { if let Some(name) = local.name(db) { -- cgit v1.2.3