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_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 +++--- 16 files changed, 41 insertions(+), 41 deletions(-) (limited to 'crates/ra_ide/src') 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