Skip to content

Renaming a method or type means fixing every reference by hand, because Replace in files only matches text #683

Closed
1 of 1 issue completed

Description

@a-team-app

Opportunity

When I rename a method, property or type, I have to find and fix every reference to it myself. Replace in files matches text, so it also changes the same word in comments, strings, other classes' members and unrelated files. It's only right if I check every hit. In practice I either leave TuiCode to rename in Rider or VS Code, or I don't rename and live with the worse name.

Renaming is the refactoring people do most while working through code they're learning: once you understand what a thing does, you give it the name that says so. The vision's user spends most of their time doing exactly that.

  • VS Code's Rename Symbol (F2) and Rider's Rename (Shift+F6) are core commands. Every LSP-speaking terminal editor (Helix, Zed, Fresh) has it.
  • Every server TuiCode offers (csharp-ls, the Roslyn server, gopls, rust-analyzer, typescript-language-server, pyright) answers LSP textDocument/rename with the edit across the workspace. TuiCode never sends it today.
  • Replace in files writes files that aren't open straight to disk, with a two-press Ctrl+Enter confirm and no undo, so TuiCode already has a precedent for editing files you can't see.
  • Find usages (#455) already lists, in the sidebar's Usages tab, the places a rename touches.

Options considered

  1. Do nothing. Keep using Replace in files with Word on, and check each hit. Free, but it's slow and error-prone, and it's the reason people leave for another editor to rename.
  2. Make Replace in files smarter. Pre-fill it from the symbol under the cursor and tick only the hits Find usages reports. That reuses a screen people know, but it bolts language knowledge onto a text tool. It can't handle what text can't see, like an overload with the same name, and Replace in files has no per-hit ticks to build on.
  3. Rename with a full preview first (VS Code's Refactor Preview): a tree of every change, each with a tick box, then Apply. It's the safest, but it's a new view to build and a second screen for every rename, when most renames touch a handful of lines that the server got right.
  4. Rename symbol: ask for the new name, then apply the server's edit (chosen). Edits in open tabs are undoable. Before anything is written to a file that isn't open, a confirm says how many changes land where. The Usages tab then lists what changed, so you can walk it. One prompt covers the common case, and you're asked before anything you can't undo.

Proposal

A new command, Rename symbol (mnemonic rs, in the Edit menu, Editor-scoped). It works on the name under the cursor:

  • The prompt. A dialog titled Rename SaveAsync, with a New name: field holding the current name, all of it selected, so typing replaces it. Ctrl+Enter renames and Esc cancels, like every TuiCode prompt.
  • Where it can't rename (a keyword, a library type, or a server that doesn't rename at all), the dialog doesn't open. The status bar says why, with the server's own words where it gives them: Can't rename this: it's defined in a library.
  • A refused name (empty, unchanged, or one the server rejects) keeps the dialog open, marks the field and says why at its foot, as every TuiCode dialog does.
  • Only open tabs change: the edit lands in each tab as one undo step, left unsaved. Ctrl+Z in a tab takes that tab's part back. No confirm, since nothing is written.
  • Files that aren't open change too: first a confirm, Rename SaveAsync to PersistAsync? 14 changes in 6 files. 4 files aren't open and are saved straight away., with [ Rename ] and [ Cancel ]. Cancel starts focused, as in every TuiCode confirm. Files that aren't open are written the way Replace in files writes them, keeping their encoding and line endings.
  • Afterwards the sidebar's Usages tab shows Renamed SaveAsync → PersistAsync · 14 in 6 files, one row per changed line, so you can walk the result. The changed files also show in Source Control as usual.
  • With no server, or while it loads, the command says what Go to definition says, and the menu dims it.

Mockup

On _store.SaveAsync(order), rs:

┌ Rename SaveAsync ─────────────────────────────────────────┐
│ New name:                                                 │
│ [PersistAsync                                           ] │
│                                                           │
│                              [ Rename ]  [ Cancel ]       │
└───────────────────────────────────────────────────────────┘

Ctrl+Enter, where some files aren't open:

┌ Rename symbol ───────────────────────────────────────────┐
│ Rename SaveAsync to PersistAsync?                        │
│ 14 changes in 6 files. 4 files aren't open and are       │
│ saved straight away.                                     │
│                                                          │
│                          [ Rename ]  [ Cancel ]          │
└──────────────────────────────────────────────────────────┘

Then the Usages tab:

 Renamed SaveAsync → PersistAsync      14 in 6 files
 ▾ IStore.cs                                       1
     12  Task PersistAsync(Order o);
 ▾ SqlStore.cs                                     2
     48  public async Task PersistAsync(Order o)
     61  await PersistAsync(copy);
 ▸ OrderService.cs                                 5

Scope

In: the textDocument/rename request (and prepareRename where the server offers it), with the client capabilities declared. The command, mnemonic, menu item and F1 row. Applying text edits to open tabs and to files on disk, the confirm, and the result in the Usages tab.

Out:

  • Renaming files with the symbol (a class's .cs file). TuiCode won't advertise file operations, so servers send text edits only. Move or rename file covers the rest.
  • A preview with a tick box per change (option 3).
  • Undo across files that weren't open. Git and Source Control's Revert cover that.
  • Rename in comments and strings, and other refactorings (extract method, change signature).
  • Edits a server pushes unasked (workspace/applyEdit).

Delivery

One PR. It's one request, a prompt, and applying an edit with the pieces Replace in files and Find usages already have.

Decided

All of these were the Lead's, and you approved them with the pitch.

  • No default key; the mnemonic is rs. From the register: you, on Compare to command #61, new commands ship with no key. The Ctrl+G exception (you, on I know the type I want but not its file, and nothing finds it by name #649) is for go-to commands, and this isn't one. F2 stays free in the editor if you want it later.
  • Open tabs are edited, not saved. That keeps them undoable, as Revert all changes and Replace in files leave them. The confirm only appears when a file that isn't open will be written.
  • The confirm appears even for one closed file. Writing a file you can't undo from TuiCode is the case that deserves a pause, however small.
  • The server works from the open tabs' unsaved text. TuiCode already sends every edit to the server as you type, so the rename matches what's on screen.
  • It's in the Edit menu, beside Replace in files, rather than the Go menu: it changes code, it doesn't move you.

Original idea

Opportunity

When I rename a method, property or type, I have to find and fix every reference to it myself. Replace in files matches text, so it also changes the same word in comments, strings, other classes' members and unrelated files, and misses nothing only if I review every hit. In practice I either leave TuiCode to rename in Rider or VS Code, or I don't rename at all and live with the worse name.

Renaming is the refactoring people do most while working through code they're learning: once you understand what a thing does, you give it the name that says so.

Evidence

  • VS Code's Rename Symbol (F2) and Rider's Rename (Shift+F6) are among their most-used commands, and every terminal editor that speaks LSP (Helix, Zed, Fresh) offers it.
  • The servers TuiCode already offers (csharp-ls, roslyn-language-server, gopls, rust-analyzer, typescript-language-server, pyright) all answer LSP textDocument/rename with the edit across every file. TuiCode doesn't send it today (src/TuiCode.Workbench/Languages/LanguageServer.cs).
  • Find usages (#455) already lists exactly the places a rename would touch, so a preview could reuse that tab.

Why it fits

Theme 3, Code intelligence: help "that understands the code, not just the text". It removes one of the reasons to reach for another editor, which is the vision's one-line promise. It needs care where the change lands in files that aren't open, and in tabs with unsaved edits, which is why it's an Idea for the stakeholder to weigh rather than a given.

Activity

  1. a-team-app commented on Nov 15, 2026

    @a-team-app
    ContributorAuthor

    Recommended: Medium · theme 3, medium · removes a reason to leave for Rider or VS Code, but edits files that aren't open and needs a preview, so it's bigger than #682

  2. added
    pitchAn a-team pitch: Lead shapes it, reviewer approves it
    on Nov 17, 2026
  3. a-team-app commented on Nov 17, 2026

    @a-team-app
    ContributorAuthor

    Up for your decision now that there's room in Pitched. I checked it against main as of today: rename still isn't sent to the server, and the pitch is unchanged since I drafted it last night.

    There are no open questions. The one thing worth a look under Assumed is the key. As drafted, it ships with no default key and the mnemonic rs. Comment if you'd rather it took F2, as in VS Code.

  4. a-team-app commented on Nov 18, 2026

    @a-team-app
    ContributorAuthor

    Broken down into one task: #697, Rename symbol (rs), covering the dialog, open-tab and closed-file edits, the confirm, and the Usages tab result.

    Everything under Assumed was mine and is now under Decided, unchanged: no default key, open tabs left unsaved, a confirm for any closed file, the server reading unsaved text, and the Edit menu.

  5. a-team-app commented on Nov 22, 2026

    @a-team-app
    ContributorAuthor

    Tried on origin/main (8023bed, CI green) with csharp-ls on a small sample project. rs on store.SaveAsync(1) opened Rename SaveAsync. PersistAsync then brought up the confirm (2 changes in 2 files. 1 file isn't open…, Cancel focused), and Rename applied it. The open tab changed but stayed unsaved, Store.cs was written to disk, the comment mentioning SaveAsync was left alone, and Usages showed Renamed SaveAsync → PersistAsync · 2 in 2 files.

    Left open when #698 merged: F1 doesn't list rs, since F1 only shows commands with a key and new commands ship without one. rs is in the mnemonics list. Go and TypeScript are still untried. The status-bar _ bug is #702.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pitchAn a-team pitch: Lead shapes it, reviewer approves it

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions