From 51baaf298d4ac56036062786bf070aeab7ab8e79 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Nov 2019 13:09:21 +0300 Subject: Rename with_ast -> with_value --- crates/ra_hir/src/source_binder.rs | 12 ++++---- crates/ra_hir_expand/src/lib.rs | 8 +++--- crates/ra_ide_api/src/display/navigation_target.rs | 10 +++---- crates/ra_ide_api/src/expand.rs | 4 +-- crates/ra_ide_api/src/goto_definition.rs | 30 ++++++++++---------- crates/ra_ide_api/src/goto_type_definition.rs | 2 +- crates/ra_ide_api/src/hover.rs | 4 +-- crates/ra_ide_api/src/references/classify.rs | 32 +++++++++++----------- 8 files changed, 51 insertions(+), 51 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 471b0b089..a1c1daacd 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -33,19 +33,19 @@ fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) - match_ast! { match (node.value) { ast::Module(it) => { - let src = node.with_ast(it); + let src = node.with_value(it); Some(crate::Module::from_declaration(db, src)?.resolver(db)) }, ast::SourceFile(it) => { - let src = node.with_ast(crate::ModuleSource::SourceFile(it)); + let src = node.with_value(crate::ModuleSource::SourceFile(it)); Some(crate::Module::from_definition(db, src)?.resolver(db)) }, ast::StructDef(it) => { - let src = node.with_ast(it); + let src = node.with_value(it); Some(Struct::from_source(db, src)?.resolver(db)) }, ast::EnumDef(it) => { - let src = node.with_ast(it); + let src = node.with_value(it); Some(Enum::from_source(db, src)?.resolver(db)) }, _ => match node.value.kind() { @@ -157,7 +157,7 @@ impl SourceAnalyzer { let scopes = def.expr_scopes(db); let scope = match offset { None => scope_for(&scopes, &source_map, node), - Some(offset) => scope_for_offset(&scopes, &source_map, node.with_ast(offset)), + Some(offset) => scope_for_offset(&scopes, &source_map, node.with_value(offset)), }; let resolver = expr::resolver_for_scope(db, def, scope); SourceAnalyzer { @@ -173,7 +173,7 @@ impl SourceAnalyzer { resolver: node .value .ancestors() - .find_map(|it| try_get_resolver_for_node(db, node.with_ast(&it))) + .find_map(|it| try_get_resolver_for_node(db, node.with_value(&it))) .unwrap_or_default(), body_owner: None, body_source_map: None, diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 6ca4bc7a3..1389f64ce 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -174,7 +174,7 @@ impl ExpansionInfo { let token = algo::find_covering_element(&self.expanded.value, range).into_token()?; - Some(self.expanded.with_ast(token)) + Some(self.expanded.with_value(token)) } pub fn map_token_up(&self, token: Source<&SyntaxToken>) -> Option> { @@ -192,7 +192,7 @@ impl ExpansionInfo { range + tt.value.syntax().text_range().start(), ) .into_token()?; - Some(tt.with_ast(token)) + Some(tt.with_value(token)) } } @@ -259,7 +259,7 @@ impl Source { } // Similarly, naming here is stupid... - pub fn with_ast(&self, value: U) -> Source { + pub fn with_value(&self, value: U) -> Source { Source::new(self.file_id, value) } @@ -267,7 +267,7 @@ impl Source { Source::new(self.file_id, f(self.value)) } pub fn as_ref(&self) -> Source<&T> { - self.with_ast(&self.value) + self.with_value(&self.value) } pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode { db.parse_or_expand(self.file_id).expect("source created from invalid file") diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index 50accafd0..6ac60722b 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -148,7 +148,7 @@ impl NavigationTarget { //FIXME: use `_` instead of empty string let name = node.value.name().map(|it| it.text().clone()).unwrap_or_default(); let focus_range = - node.value.name().map(|it| original_range(db, node.with_ast(it.syntax())).range); + node.value.name().map(|it| original_range(db, node.with_value(it.syntax())).range); let frange = original_range(db, node.map(|it| it.syntax())); NavigationTarget::from_syntax( @@ -232,7 +232,7 @@ impl ToNav for hir::Module { let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default(); match &src.value { ModuleSource::SourceFile(node) => { - let frange = original_range(db, src.with_ast(node.syntax())); + let frange = original_range(db, src.with_value(node.syntax())); NavigationTarget::from_syntax( frange.file_id, @@ -245,7 +245,7 @@ impl ToNav for hir::Module { ) } ModuleSource::Module(node) => { - let frange = original_range(db, src.with_ast(node.syntax())); + let frange = original_range(db, src.with_value(node.syntax())); NavigationTarget::from_syntax( frange.file_id, @@ -285,12 +285,12 @@ impl ToNav for hir::StructField { match &src.value { FieldSource::Named(it) => NavigationTarget::from_named( db, - src.with_ast(it), + src.with_value(it), it.doc_comment_text(), it.short_label(), ), FieldSource::Pos(it) => { - let frange = original_range(db, src.with_ast(it.syntax())); + let frange = original_range(db, src.with_value(it.syntax())); NavigationTarget::from_syntax( frange.file_id, "".into(), diff --git a/crates/ra_ide_api/src/expand.rs b/crates/ra_ide_api/src/expand.rs index 0228bced9..0ad125a9e 100644 --- a/crates/ra_ide_api/src/expand.rs +++ b/crates/ra_ide_api/src/expand.rs @@ -28,7 +28,7 @@ pub(crate) fn original_range(db: &RootDatabase, node: Source<&SyntaxNode>) -> Fi .value .descendants_with_tokens() .filter_map(|it| it.into_token()) - .find_map(|it| expansion.map_token_up(node.with_ast(&it))); + .find_map(|it| expansion.map_token_up(node.with_value(&it))); match token { Some(it) => { @@ -54,7 +54,7 @@ pub(crate) fn descend_into_macros( return None; } let source_analyzer = - hir::SourceAnalyzer::new(db, token.with_ast(token.value.parent()).as_ref(), None); + hir::SourceAnalyzer::new(db, token.with_value(token.value.parent()).as_ref(), None); let exp = source_analyzer.expand(db, ¯o_call)?; exp.map_token_down(db, token.as_ref()) }) diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index ed9d99a7f..b6c72efdf 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -25,11 +25,11 @@ pub(crate) fn goto_definition( let res = match_ast! { match (token.value.parent()) { ast::NameRef(name_ref) => { - let navs = reference_definition(db, token.with_ast(&name_ref)).to_vec(); + let navs = reference_definition(db, token.with_value(&name_ref)).to_vec(); RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec()) }, ast::Name(name) => { - let navs = name_definition(db, token.with_ast(&name))?; + let navs = name_definition(db, token.with_value(&name))?; RangeInfo::new(name.syntax().text_range(), navs) }, @@ -99,7 +99,7 @@ pub(crate) fn name_definition( if let Some(module) = ast::Module::cast(parent.clone()) { if module.has_semi() { - let src = name.with_ast(module); + let src = name.with_value(module); if let Some(child_module) = hir::Module::from_declaration(db, src) { let nav = child_module.to_nav(db); return Some(vec![nav]); @@ -107,7 +107,7 @@ pub(crate) fn name_definition( } } - if let Some(nav) = named_target(db, name.with_ast(&parent)) { + if let Some(nav) = named_target(db, name.with_value(&parent)) { return Some(vec![nav]); } @@ -120,7 +120,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.with_ast(&it), + node.with_value(&it), it.doc_comment_text(), it.short_label(), )) @@ -128,7 +128,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.with_ast(&it), + node.with_value(&it), it.doc_comment_text(), it.short_label(), )) @@ -136,7 +136,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.with_ast(&it), + node.with_value(&it), it.doc_comment_text(), it.short_label(), )) @@ -144,7 +144,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.with_ast(&it), + node.with_value(&it), it.doc_comment_text(), it.short_label(), )) @@ -152,7 +152,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.with_ast(&it), + node.with_value(&it), it.doc_comment_text(), it.short_label(), )) @@ -160,7 +160,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.with_ast(&it), + node.with_value(&it), it.doc_comment_text(), it.short_label(), )) @@ -168,7 +168,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.with_ast(&it), + node.with_value(&it), it.doc_comment_text(), it.short_label(), )) @@ -176,7 +176,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.with_ast(&it), + node.with_value(&it), it.doc_comment_text(), it.short_label(), )) @@ -184,7 +184,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.with_ast(&it), + node.with_value(&it), it.doc_comment_text(), it.short_label(), )) @@ -192,7 +192,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.with_ast(&it), + node.with_value(&it), it.doc_comment_text(), it.short_label(), )) @@ -200,7 +200,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.with_ast(&it), + node.with_value(&it), it.doc_comment_text(), None, )) diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs index 6aeeefa1f..28a83a3e2 100644 --- a/crates/ra_ide_api/src/goto_type_definition.rs +++ b/crates/ra_ide_api/src/goto_type_definition.rs @@ -22,7 +22,7 @@ pub(crate) fn goto_type_definition( .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some()) })?; - let analyzer = hir::SourceAnalyzer::new(db, token.with_ast(&node), None); + let analyzer = hir::SourceAnalyzer::new(db, token.with_value(&node), None); let ty: hir::Ty = if let Some(ty) = ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e)) diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index e8a340ba4..ae87ab9f9 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -174,7 +174,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { let mut no_fallback = false; if let Some(name_kind) = - classify_name_ref(db, token.with_ast(&name_ref)).map(|d| d.kind) + classify_name_ref(db, token.with_value(&name_ref)).map(|d| d.kind) { res.extend(hover_text_from_name_kind(db, name_kind, &mut no_fallback)) } @@ -196,7 +196,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - if let Some(name_kind) = classify_name(db, token.with_ast(&name)).map(|d| d.kind) { + if let Some(name_kind) = classify_name(db, token.with_value(&name)).map(|d| d.kind) { res.extend(hover_text_from_name_kind(db, name_kind, &mut true)); } diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs index 333264540..4a4b030f8 100644 --- a/crates/ra_ide_api/src/references/classify.rs +++ b/crates/ra_ide_api/src/references/classify.rs @@ -18,7 +18,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti match_ast! { match parent { ast::BindPat(it) => { - let src = name.with_ast(it); + let src = name.with_value(it); let local = hir::Local::from_source(db, src)?; Some(NameDefinition { visibility: None, @@ -28,7 +28,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti }, ast::RecordFieldDef(it) => { let ast = hir::FieldSource::Named(it); - let src = name.with_ast(ast); + let src = name.with_value(ast); let field = hir::StructField::from_source(db, src)?; Some(from_struct_field(db, field)) }, @@ -36,42 +36,42 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti let def = { if !it.has_semi() { let ast = hir::ModuleSource::Module(it); - let src = name.with_ast(ast); + let src = name.with_value(ast); hir::Module::from_definition(db, src) } else { - let src = name.with_ast(it); + let src = name.with_value(it); hir::Module::from_declaration(db, src) } }?; Some(from_module_def(db, def.into(), None)) }, ast::StructDef(it) => { - let src = name.with_ast(it); + let src = name.with_value(it); let def = hir::Struct::from_source(db, src)?; Some(from_module_def(db, def.into(), None)) }, ast::EnumDef(it) => { - let src = name.with_ast(it); + let src = name.with_value(it); let def = hir::Enum::from_source(db, src)?; Some(from_module_def(db, def.into(), None)) }, ast::TraitDef(it) => { - let src = name.with_ast(it); + let src = name.with_value(it); let def = hir::Trait::from_source(db, src)?; Some(from_module_def(db, def.into(), None)) }, ast::StaticDef(it) => { - let src = name.with_ast(it); + let src = name.with_value(it); let def = hir::Static::from_source(db, src)?; Some(from_module_def(db, def.into(), None)) }, ast::EnumVariant(it) => { - let src = name.with_ast(it); + let src = name.with_value(it); let def = hir::EnumVariant::from_source(db, src)?; Some(from_module_def(db, def.into(), None)) }, ast::FnDef(it) => { - let src = name.with_ast(it); + let src = name.with_value(it); let def = hir::Function::from_source(db, src)?; if parent.parent().and_then(ast::ItemList::cast).is_some() { Some(from_assoc_item(db, def.into())) @@ -80,7 +80,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti } }, ast::ConstDef(it) => { - let src = name.with_ast(it); + let src = name.with_value(it); let def = hir::Const::from_source(db, src)?; if parent.parent().and_then(ast::ItemList::cast).is_some() { Some(from_assoc_item(db, def.into())) @@ -89,7 +89,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti } }, ast::TypeAliasDef(it) => { - let src = name.with_ast(it); + let src = name.with_value(it); let def = hir::TypeAlias::from_source(db, src)?; if parent.parent().and_then(ast::ItemList::cast).is_some() { Some(from_assoc_item(db, def.into())) @@ -98,11 +98,11 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti } }, ast::MacroCall(it) => { - let src = name.with_ast(it); + let src = name.with_value(it); let def = hir::MacroDef::from_source(db, src.clone())?; let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); - let module = Module::from_definition(db, src.with_ast(module_src))?; + let module = Module::from_definition(db, src.with_value(module_src))?; Some(NameDefinition { visibility: None, @@ -149,9 +149,9 @@ pub(crate) fn classify_name_ref( } } - let ast = ModuleSource::from_child_node(db, name_ref.with_ast(&parent)); + let ast = ModuleSource::from_child_node(db, name_ref.with_value(&parent)); // FIXME: find correct container and visibility for each case - let container = Module::from_definition(db, name_ref.with_ast(ast))?; + let container = Module::from_definition(db, name_ref.with_value(ast))?; let visibility = None; if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { -- cgit v1.2.3