Skip to content

Change "extract variable" to allow extracting literals, not just expressions. #16305

Closed
@camercu

Description

@camercu

Suppose I had a statement like so:

let result = some_complicated_computation(arg1, arg2, arg3, "annoyingly long literal of text");

I'd like to be able to put my cursor inside the str literal (or a numeric literal) and have the option to run a refactoring code action to extract the literal into a variable. The result of running this on the previous example would be:

let var_name = "annoyingly long literal of text";
let result = some_complicated_computation(arg1, arg2, arg3, var_name);

The refactoring can improve readability or set the code up for further refactorings (like moving the variable to a parameter/field).

Currently when I try to do this (in VSCode), I get no such option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-featureCategory: feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions