Skip to content

Commit f87c527

Browse files
Merge pull request #22043 from Shourya742/2026-04-14-migrate-make-with-syntax-editor-in-raw-string
Replace make with syntax factory in raw string handler
2 parents 9d84c4a + ba61809 commit f87c527

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

crates/ide-assists/src/handlers/raw_string.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ide_db::source_change::SourceChangeBuilder;
22
use syntax::{
3-
AstToken,
4-
ast::{self, IsString, make::tokens::literal},
3+
AstNode, AstToken,
4+
ast::{self, IsString},
55
};
66

77
use crate::{
@@ -162,23 +162,18 @@ fn replace_literal(
162162
builder: &mut SourceChangeBuilder,
163163
ctx: &AssistContext<'_>,
164164
) {
165-
let token = token.syntax();
166-
let node = token.parent().expect("no parent token");
167-
let edit = builder.make_editor(&node);
168-
let new_literal = literal(new);
169-
170-
edit.replace(token, mut_token(new_literal));
171-
172-
builder.add_file_edits(ctx.vfs_file_id(), edit);
173-
}
174-
175-
fn mut_token(token: syntax::SyntaxToken) -> syntax::SyntaxToken {
176-
let node = token.parent().expect("no parent token");
177-
node.clone_for_update()
178-
.children_with_tokens()
179-
.filter_map(|it| it.into_token())
180-
.find(|it| it.text_range() == token.text_range() && it.text() == token.text())
181-
.unwrap()
165+
let old_token = token.syntax();
166+
let parent = old_token.parent().expect("no parent token");
167+
let editor = builder.make_editor(&parent);
168+
let make = editor.make();
169+
let new_literal = make.expr_literal(new);
170+
let new_token = new_literal
171+
.syntax()
172+
.first_child_or_token()
173+
.and_then(|it| it.into_token())
174+
.expect("literal has no token child");
175+
editor.replace(old_token, new_token);
176+
builder.add_file_edits(ctx.vfs_file_id(), editor);
182177
}
183178

184179
#[cfg(test)]

0 commit comments

Comments
 (0)