Skip to content

Ability to rename generated context selectors via IDE tools like rust-analyzer #485

@clouds56

Description

@clouds56

I always feel frustrated when I'd like to refactor Error enum, since I could not use "Rename Symbol" feature provided by vscode and rust-analyzer.

When I add PackageBConfigError, I'd like to rename ConfigError to PackageAConfigError, but it would cause compilation failing since vscode would not rename ConfigSnafu to PackageAConfigSnafu for me.

#[derive(Debug, snafu::Snafu)]
pub enum Error {
  #[snafu(rename = "ConfigSnafu"] // <-- suggest adding optional rename field helps IDE to do refactor
  ConfigError { .. },
  PackageBConfigError { .. }
}

Is there any workaround?

My sugguestion

Shall we allow an attr that be the span of generated Snafu struct? We could do refactor maybe in this way.

  1. add corresponding attr #[snafu(rename = "ConfigSnafu"] to ConfigError { .. },
  2. press F2 on ConfigError to rename to PackageAConfigError, but it would still use ConfigSnafu for context
  3. press F2 on ConfigSnafu to rename to PackageAConfigSnafu
  4. delete temp attr #[snafu(rename = "PackageAConfigSnafu"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions