Skip to content

Raw identifier fields do not get inserted with the raw identifier prefix when completed #9120

@repnop

Description

@repnop

e.g.

struct Foo { r#type: u32 }

fn bar(f: Foo) -> u32 { f.ty<enter> }

becomes

struct Foo { r#type: u32 }

fn bar(f: Foo) -> u32 { f.type }

which is a syntax error, instead of

struct Foo { r#type: u32 }

fn bar(f: Foo) -> u32 { f.r#type }

I was going to just PR this by having it check if the field name is a keyword but I'm not quite sure how to insert that here:
https://github.com/rust-analyzer/rust-analyzer/blob/9271941a950026836511bd1c85e15e26a480b824/crates/ide_completion/src/completions/dot.rs#L43-L46 because .add_field takes a hir_expand::Name which doesn't allow arbitrary name construction, and the r# prefix is stripped here: https://github.com/rust-analyzer/rust-analyzer/blob/9271941a950026836511bd1c85e15e26a480b824/crates/hir_expand/src/name.rs#L51

So if there's a relatively easy way to do that, I'm more than happy to adjust it and PR it :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-assistsS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions