Skip to content

New Assist: From/To cfg_attr #13965

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

Closed
ModProg opened this issue Jan 16, 2023 · 3 comments · Fixed by #16813
Closed

New Assist: From/To cfg_attr #13965

ModProg opened this issue Jan 16, 2023 · 3 comments · Fixed by #16813
Assignees
Labels
A-assists C-feature Category: feature request S-actionable Someone could pick this issue up and work on it right now

Comments

@ModProg
Copy link
Contributor

ModProg commented Jan 16, 2023

Wrapping an attribute into #[cfg_attr isn't a lot of work, but can be tedious nonetheless.

I propose an assist that will convert

#[some_attr(...)]    ->  #[cfg_attr(todo, some_attr(...))]
#[some_attr = ...]   ->  #[cfg_attr(todo, some_attr = ...)]
#[some_attr]         ->  #[cfg_attr(todo, some_attr)]

and back

#[cfg_attr(not(all(...)), some_attr(...))]   ->  #[some_attr(...)] 
#[cfg_attr(not(all(...)), some_attr = ...)]  ->  #[some_attr = ...]
#[cfg_attr(not(all(...)), some_attr)]        ->  #[some_attr]

Obviously, the back direction is lossy.

This would play quite well with e.g. #13935 allowing to convert a doc comment in two steps to a conditional doc attribute.

As I'm quite new to rust-analyzer I'm not sure if this would need to somehow understand weather cfg_attr is actually cfg_attr or some custom attribute macro, which could complicate things. But other than that, this should be pretty simple to implement.

@lnicola lnicola added S-actionable Someone could pick this issue up and work on it right now A-assists C-feature Category: feature request labels Jan 16, 2023
@ModProg
Copy link
Contributor Author

ModProg commented Jan 20, 2023

Is a simple comparison i.e. does the path match cfg_attr enough?
Or do I need to do a path resolve and if so, how would I check if it is the actual cfg_attr?

@ModProg
Copy link
Contributor Author

ModProg commented Jan 20, 2023

Oh nevermind cfg_attr is a builtin one

@wyatt-herkamp
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-feature Category: feature request S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants