remove make from add_turbo_fish

This commit is contained in:
bit-aloo
2026-03-02 21:06:29 +05:30
parent 2aeb269257
commit 6feab700fc
3 changed files with 16 additions and 10 deletions

View File

@@ -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)
}

View File

@@ -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();

View File

@@ -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,