rust-lang / rust-lang/rust-analyzer

Prompt for name when using extract refactoring assists

Open
#17,579 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists A-ide C-feature C-tracking-issue
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

In typescript, extracting a variable / function / etc. allows you to enter a name for the just created extraction. It would be nice to do the same in RA for functions, modules, variables, etc.

image image

Playing with the extract_variable:

if let Some(cap) = ctx.config.snippet_cap {
    if let Some(ast::Pat::IdentPat(ident_pat)) = let_stmt.pat() {
        if let Some(name) = ident_pat.name() {
-            edit.add_tabstop_before(cap, name);
+            edit.add_placeholder_snippet_group(
+                cap,
+                vec![name.syntax().clone(), name_expr.syntax().clone()],
            )
        }
    }
}

SourceChangeBuilder::add_placeholder_snippet_token doesn't seem quite right for this. Instead of a single edit location which applies to both places when the edit is confirmed, this method makes two edit locations that are edited simultaneously.

image

I'm not quite sure what the right terminology to use to find the functionality here, so seeking some guidance on what to do to make this work.

Edit: this UX is provided by the rename symbol function, but I'm not sure how that would fit in to the extract refactoring.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the extract_variable assist and SourceChangeBuilder's add_placeholder_snippet_token and add_placeholder_snippet_group APIs. Compare how rename symbol provides linked editing, then determine how that behavior should apply to extracted functions, modules, and variables. Done means extraction assists prompt for a name and update linked occurrences together.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.