Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract_format_args assist escapes \ character in \n etc. #16745

Closed
kartva opened this issue Mar 4, 2024 · 3 comments · Fixed by #16781
Closed

extract_format_args assist escapes \ character in \n etc. #16745

kartva opened this issue Mar 4, 2024 · 3 comments · Fixed by #16781
Assignees
Labels
A-assists C-bug Category: bug

Comments

@kartva
Copy link
Contributor

kartva commented Mar 4, 2024

rust-analyzer version: rust-analyzer version: 0.3.1860-standalone

rustc version: rustc 1.76.0 (07dca489a 2024-02-04)

code snippet to reproduce:
Add the following test in rust-analyzer/crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs

    #[test]
    fn escaped_literals() {
        check_assist(
            extract_expressions_from_format_string,
            &add_macro_decl(
                r#"
fn main() {
    print!("\n {x + 1}$0");
}
            "#,
            ),
            &add_macro_decl(
                r#"
fn main() {
    print!("\n {}"$0, x + 1);
}
            "#,
            ),
        );
    }

fails and instead produces

fn main() {
    print!("\\n {}"$0, x + 1);
}
@kartva kartva added the C-bug Category: bug label Mar 4, 2024
@Veykril
Copy link
Member

Veykril commented Mar 4, 2024

not sure if this is related to your changes or not but it might so pinging @DropDemBits

@DropDemBits
Copy link
Contributor

Looks like extract_expressions_from_format_string is using snippet stuff but not insert_snippet or replace_snippet, so I didn't catch it as part of the assists to migrate to the structured snippet API.

It also looks like parse_format_exprs is the one escaping the \:

if matches!(chr, '\\' | '$') {
output.push('\\');
}

@DropDemBits
Copy link
Contributor

I have some time today, so I'll take this up.
@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants