Run cargo fmt

This commit is contained in:
Paweł Palenica 2021-10-20 23:35:14 -07:00
parent bb00b09d22
commit c8820d342f
2 changed files with 23 additions and 14 deletions

View file

@ -1,8 +1,14 @@
use hir::{ItemInNs, ModuleDef}; use hir::{ItemInNs, ModuleDef};
use ide_db::{assists::{AssistId, AssistKind}, helpers::import_assets::item_for_path_search}; use ide_db::{
use syntax::{AstNode, ast}; assists::{AssistId, AssistKind},
helpers::import_assets::item_for_path_search,
};
use syntax::{ast, AstNode};
use crate::{assist_context::{AssistContext, Assists}, handlers::qualify_path::QualifyCandidate}; use crate::{
assist_context::{AssistContext, Assists},
handlers::qualify_path::QualifyCandidate,
};
// Assist: qualify_method_call // Assist: qualify_method_call
// //
@ -11,7 +17,7 @@ use crate::{assist_context::{AssistContext, Assists}, handlers::qualify_path::Qu
// ``` // ```
// struct Foo; // struct Foo;
// impl Foo { // impl Foo {
// fn foo(&self) {} // fn foo(&self) {}
// } // }
// fn main() { // fn main() {
// let foo = Foo; // let foo = Foo;
@ -22,7 +28,7 @@ use crate::{assist_context::{AssistContext, Assists}, handlers::qualify_path::Qu
// ``` // ```
// struct Foo; // struct Foo;
// impl Foo { // impl Foo {
// fn foo(&self) {} // fn foo(&self) {}
// } // }
// fn main() { // fn main() {
// let foo = Foo; // let foo = Foo;
@ -32,7 +38,7 @@ use crate::{assist_context::{AssistContext, Assists}, handlers::qualify_path::Qu
pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let call: ast::MethodCallExpr = ctx.find_node_at_offset()?; let call: ast::MethodCallExpr = ctx.find_node_at_offset()?;
let fn_name = &call.name_ref()?; let fn_name = &call.name_ref()?;
// let callExpr = path_expr.syntax(); // let callExpr = path_expr.syntax();
let range = call.syntax().text_range(); let range = call.syntax().text_range();
let resolved_call = ctx.sema.resolve_method_call(&call)?; let resolved_call = ctx.sema.resolve_method_call(&call)?;
@ -40,10 +46,11 @@ pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext) -> Opt
let current_module = ctx.sema.scope(&call.syntax()).module()?; let current_module = ctx.sema.scope(&call.syntax()).module()?;
let target_module_def = ModuleDef::from(resolved_call); let target_module_def = ModuleDef::from(resolved_call);
let item_in_ns = ItemInNs::from(target_module_def); let item_in_ns = ItemInNs::from(target_module_def);
let receiver_path = current_module.find_use_path(ctx.sema.db, item_for_path_search(ctx.sema.db, item_in_ns)?)?; let receiver_path = current_module
.find_use_path(ctx.sema.db, item_for_path_search(ctx.sema.db, item_in_ns)?)?;
let qualify_candidate = QualifyCandidate::ImplMethod(ctx.sema.db, call, resolved_call); let qualify_candidate = QualifyCandidate::ImplMethod(ctx.sema.db, call, resolved_call);
acc.add( acc.add(
AssistId("qualify_method_call", AssistKind::RefactorInline), AssistId("qualify_method_call", AssistKind::RefactorInline),
format!("Qualify call `{}`", fn_name), format!("Qualify call `{}`", fn_name),
@ -52,17 +59,17 @@ pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext) -> Opt
qualify_candidate.qualify( qualify_candidate.qualify(
|replace_with: String| builder.replace(range, replace_with), |replace_with: String| builder.replace(range, replace_with),
&receiver_path, &receiver_path,
item_in_ns item_in_ns,
) )
} },
); );
Some(()) Some(())
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::tests::{check_assist};
use super::*; use super::*;
use crate::tests::check_assist;
#[test] #[test]
fn struct_method() { fn struct_method() {
@ -478,4 +485,3 @@ fn main() {
); );
} }
} }

View file

@ -1,7 +1,10 @@
use std::iter; use std::iter;
use hir::AsAssocItem; use hir::AsAssocItem;
use ide_db::helpers::{import_assets::{ImportCandidate, LocatedImport}, mod_path_to_ast}; use ide_db::helpers::{
import_assets::{ImportCandidate, LocatedImport},
mod_path_to_ast,
};
use ide_db::RootDatabase; use ide_db::RootDatabase;
use syntax::{ use syntax::{
ast, ast,
@ -136,7 +139,7 @@ impl QualifyCandidate<'_> {
) -> Option<()> { ) -> Option<()> {
let receiver = mcall_expr.receiver()?; let receiver = mcall_expr.receiver()?;
let method_name = mcall_expr.name_ref()?; let method_name = mcall_expr.name_ref()?;
let generics = let generics =
mcall_expr.generic_arg_list().as_ref().map_or_else(String::new, ToString::to_string); mcall_expr.generic_arg_list().as_ref().map_or_else(String::new, ToString::to_string);
let arg_list = mcall_expr.arg_list().map(|arg_list| arg_list.args()); let arg_list = mcall_expr.arg_list().map(|arg_list| arg_list.args());