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 constant #4246

Open
3 of 6 tasks
alexander-irbis opened this issue Aug 12, 2019 · 1 comment
Open
3 of 6 tasks

Extract constant #4246

alexander-irbis opened this issue Aug 12, 2019 · 1 comment
Labels
feature subsystem::code insight General label for issues related to code understanding: highlighting, completion, annotation, etc. subsystem::refactoring Issues related to refactorings

Comments

@alexander-irbis
Copy link

alexander-irbis commented Aug 12, 2019

This is a request for the "extract constant" refactoring feature.
The feature may include:

  • "Extract literal as a local constant" action, similar to "extract variable" action.
  • "Extract literal as a global constant" action.
  • (?)"Replace all entries of the literal in the scope" option during extracting.
  • Suggest to extract constant on literals.
  • Suggest (with warning underline of the literal) to replace a literal with the corresponding constant if it is in the scope.
  • (?)Suggest (with warning underline of the literal) to replace a literal with the corresponding constant, and to autoimport last if it may be imported
@Undin Undin added subsystem::code insight General label for issues related to code understanding: highlighting, completion, annotation, etc. feature labels Aug 13, 2019
@artemmukhin artemmukhin added the subsystem::refactoring Issues related to refactorings label Feb 6, 2020
bors bot added a commit that referenced this issue May 11, 2020
4985: REF: introduce constant refactoring r=vlad20012 a=Kobzol

In this PR I'd like to tackle the Introduce constant refactoring. The current state is just a sketch, because I have a few questions:

- Should this work on arbitrary expressions (and types) or just literals?
- Where should the corresponding constant be generated? Maybe we should show the user a short dialog (similar to the Introduce parameter refactoring) to let him select? For example here:

```rust
//x
mod x {
    //x
    fn foo() {
        //x
        fn bar() {
            //x
            let x = 5;
        }   
    }
}
```
We could offer these 4 locations (inner function, outer function, inside module, outside module).
- Should literals with the same type and value in the given context (function/block) be extracted to use the newly created constant (same as with the Introduce Variable refactoring)?

Related issue: #4246

Co-authored-by: Jakub Beránek <jakub.beranek@vsb.cz>
@Kobzol
Copy link
Member

Kobzol commented May 11, 2020

#4985 has now been merged. @alexander-irbis can you check it out if it fulfills your needs? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature subsystem::code insight General label for issues related to code understanding: highlighting, completion, annotation, etc. subsystem::refactoring Issues related to refactorings
Projects
None yet
Development

No branches or pull requests

4 participants