Stream: t-compiler/rust-analyzer

Topic: Rename refactor


Lukas Wirth (Jan 16 2021 at 19:04, on Zulip):

So I have been looking into rewriting the rename module to instead use the FindUsages functionality directly. As said in https://github.com/rust-analyzer/rust-analyzer/issues/4290 we ideally want to base renaming on the AST instead of strings so we can properly rename a reference by first figuring out how it is used, as in for example if its part of a destructure etc. For that I was wondering how we would do that ideally, given currently search gives us FileReferences:
https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_db/src/search.rs#L56-L72

#[derive(Debug, Clone)]
pub struct FileReference {
    pub range: TextRange,
    pub kind: ReferenceKind,
    pub access: Option<ReferenceAccess>,
}

#[derive(Debug, Clone, PartialEq)]
pub enum ReferenceKind {
    FieldShorthandForField,
    FieldShorthandForLocal,
    StructLiteral,
    RecordFieldExprOrPat,
    SelfParam,
    EnumLiteral,
    Lifetime,
    Other,
}

My initial thought was to get rid of the current ReferenceKind entirely and replace it with something like:

#[derive(Debug, Clone)]
pub enum ReferenceKind {
    NameRef(ast::NameRef),
    Name(ast::Name),
    Lifetime(ast::Lifetime),
}
matklad (Jan 16 2021 at 19:07, on Zulip):

makes sense as a long term plan!

but i'd start with just replacing ide/references with ide_db/search, to keep the diff smaller

Lukas Wirth (Jan 16 2021 at 19:08, on Zulip):

:thumbs_up:

Last update: Jul 28 2021 at 04:30UTC