mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2026-03-18 20:29:23 +00:00
remove make from add_turbo_fish
This commit is contained in:
@@ -2,7 +2,7 @@ use either::Either;
|
||||
use ide_db::defs::{Definition, NameRefClass};
|
||||
use syntax::{
|
||||
AstNode,
|
||||
ast::{self, HasArgList, HasGenericArgs, make, syntax_factory::SyntaxFactory},
|
||||
ast::{self, HasArgList, HasGenericArgs, syntax_factory::SyntaxFactory},
|
||||
syntax_editor::Position,
|
||||
};
|
||||
|
||||
@@ -94,20 +94,21 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
|
||||
ident.text_range(),
|
||||
|builder| {
|
||||
let mut editor = builder.make_editor(let_stmt.syntax());
|
||||
let make = SyntaxFactory::without_mappings();
|
||||
|
||||
if let_stmt.semicolon_token().is_none() {
|
||||
editor.insert(
|
||||
Position::last_child_of(let_stmt.syntax()),
|
||||
make::tokens::semicolon(),
|
||||
make.token(syntax::SyntaxKind::SEMICOLON),
|
||||
);
|
||||
}
|
||||
|
||||
let placeholder_ty = make::ty_placeholder().clone_for_update();
|
||||
let placeholder_ty = make.ty_placeholder();
|
||||
|
||||
if let Some(pat) = let_stmt.pat() {
|
||||
let elements = vec![
|
||||
make::token(syntax::SyntaxKind::COLON).into(),
|
||||
make::token(syntax::SyntaxKind::WHITESPACE).into(),
|
||||
make.token(syntax::SyntaxKind::COLON).into(),
|
||||
make.whitespace(" ").into(),
|
||||
placeholder_ty.syntax().clone().into(),
|
||||
];
|
||||
editor.insert_all(Position::after(pat.syntax()), elements);
|
||||
@@ -188,7 +189,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
|
||||
|
||||
/// This will create a turbofish generic arg list corresponding to the number of arguments
|
||||
fn get_fish_head(make: &SyntaxFactory, number_of_arguments: usize) -> ast::GenericArgList {
|
||||
let args = (0..number_of_arguments).map(|_| make::type_arg(make::ty_placeholder()).into());
|
||||
let args = (0..number_of_arguments).map(|_| make.type_arg(make.ty_placeholder()).into());
|
||||
make.generic_arg_list(args, true)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@ use either::Either;
|
||||
use hir::HirDisplay;
|
||||
use ide_db::syntax_helpers::node_ext::walk_ty;
|
||||
use syntax::{
|
||||
ast::{self, AstNode, HasGenericArgs, HasGenericParams, HasName, edit::IndentLevel, syntax_factory::SyntaxFactory},
|
||||
ast::{
|
||||
self, AstNode, HasGenericArgs, HasGenericParams, HasName, edit::IndentLevel,
|
||||
syntax_factory::SyntaxFactory,
|
||||
},
|
||||
syntax_editor,
|
||||
};
|
||||
|
||||
@@ -43,8 +46,7 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) ->
|
||||
let resolved_ty = ctx.sema.resolve_type(&ty)?;
|
||||
let resolved_ty = if !resolved_ty.contains_unknown() {
|
||||
let module = ctx.sema.scope(ty.syntax())?.module();
|
||||
let resolved_ty = resolved_ty.display_source_code(ctx.db(), module.into(), false).ok()?;
|
||||
resolved_ty
|
||||
resolved_ty.display_source_code(ctx.db(), module.into(), false).ok()?
|
||||
} else {
|
||||
ty.to_string()
|
||||
};
|
||||
@@ -54,7 +56,6 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) ->
|
||||
"Extract type as type alias",
|
||||
target,
|
||||
|builder| {
|
||||
|
||||
let mut edit = builder.make_editor(node);
|
||||
let make = SyntaxFactory::without_mappings();
|
||||
|
||||
|
||||
@@ -295,6 +295,10 @@ impl SyntaxFactory {
|
||||
make::generic_ty_path_segment(name_ref, generic_args).clone_for_update()
|
||||
}
|
||||
|
||||
pub fn ty_placeholder(&self) -> ast::Type {
|
||||
make::ty_placeholder().clone_for_update()
|
||||
}
|
||||
|
||||
pub fn path_segment_generics(
|
||||
&self,
|
||||
name_ref: ast::NameRef,
|
||||
|
||||
Reference in New Issue
Block a user