This commit is contained in:
Lukas Wirth 2021-07-02 23:52:43 +02:00
parent 26dd0c4e5b
commit fbdcb49d48
3 changed files with 9 additions and 8 deletions

View file

@ -1,3 +1,5 @@
use ast::make;
use itertools::Itertools;
use syntax::{ use syntax::{
ast::{self, VisibilityOwner}, ast::{self, VisibilityOwner},
ted::{self, Position}, ted::{self, Position},
@ -42,9 +44,9 @@ pub(crate) fn unmerge_use(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
"Unmerge use", "Unmerge use",
target, target,
|builder| { |builder| {
let new_use = ast::make::use_( let new_use = make::use_(
use_.visibility(), use_.visibility(),
ast::make::use_tree( make::use_tree(
path, path,
tree.use_tree_list(), tree.use_tree_list(),
tree.rename(), tree.rename(),
@ -62,17 +64,14 @@ pub(crate) fn unmerge_use(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
} }
fn resolve_full_path(tree: &ast::UseTree) -> Option<ast::Path> { fn resolve_full_path(tree: &ast::UseTree) -> Option<ast::Path> {
let mut paths = tree let paths = tree
.syntax() .syntax()
.ancestors() .ancestors()
.take_while(|n| n.kind() != SyntaxKind::USE_KW) .take_while(|n| n.kind() != SyntaxKind::USE)
.filter_map(ast::UseTree::cast) .filter_map(ast::UseTree::cast)
.filter_map(|t| t.path()); .filter_map(|t| t.path());
let mut final_path = paths.next()?; let final_path = paths.fold1(|prev, next| make::path_concat(next, prev))?;
for path in paths {
final_path = ast::make::path_concat(path, final_path)
}
if final_path.segment().map_or(false, |it| it.self_token().is_some()) { if final_path.segment().map_or(false, |it| it.self_token().is_some()) {
final_path.qualifier() final_path.qualifier()
} else { } else {

View file

@ -13,6 +13,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// Wrap the function's return type into Result. // Wrap the function's return type into Result.
// //
// ``` // ```
// # //- minicore: result
// fn foo() -> i32$0 { 42i32 } // fn foo() -> i32$0 { 42i32 }
// ``` // ```
// -> // ->

View file

@ -1600,6 +1600,7 @@ fn doctest_wrap_return_type_in_result() {
check_doc_test( check_doc_test(
"wrap_return_type_in_result", "wrap_return_type_in_result",
r#####" r#####"
//- minicore: result
fn foo() -> i32$0 { 42i32 } fn foo() -> i32$0 { 42i32 }
"#####, "#####,
r#####" r#####"