Skip to content

Rename a method, property or type across the workspace with Rename symbol (rs) #697

Closed

Description

@a-team-app

Context

Renaming a method, property or type today means Replace in files, which matches text and hits comments, strings and unrelated members. This adds Rename symbol: ask for the new name, then apply the language server's rename across the workspace, editing open tabs (undoable, unsaved) and confirming before writing any file that isn't open. The Usages tab then lists what changed. Full design, mockups and decisions: #683.

Acceptance criteria

  • With the cursor on a method name in a C# file and the language server ready, rs (and Edit ▸ Rename symbol, and the palette) opens a dialog titled Rename <name>, with a New name: text field holding the current name, all of it selected.
  • Typing a new name and pressing Ctrl+Enter (or the [ Rename ] button) renames the declaration and every reference to it; the same word in comments, strings and unrelated members is left alone.
  • Esc (or [ Cancel ]) closes the dialog and changes nothing.
  • When every changed file is open, there is no confirm: each tab shows the change, unsaved, and Ctrl+Z in a tab takes back that tab's whole part of the rename in one step.
  • When some changed files aren't open, a confirm first says Rename <old> to <new>? <n> changes in <m> files. <k> files aren't open and are saved straight away., with [ Rename ] and [ Cancel ], Cancel focused. Cancel changes nothing anywhere. Rename writes the closed files to disk, keeping their encoding and line endings, and edits the open tabs unsaved.
  • After a rename, the sidebar's Usages tab shows Renamed <old> → <new> · <n> in <m> files, grouped by file, one row per changed line, and Enter on a row opens it there.
  • An empty or unchanged name keeps the dialog open, marks the field and says why at the dialog's foot; so does a name the server rejects, in the server's words.
  • On something that can't be renamed (a keyword, a type from a library, or with a server that doesn't support rename) the dialog doesn't open, and the status bar says why, in the server's words where it gives them.
  • With no language server, or while it's loading, the command behaves as Go to definition does then, and the Edit menu item is dimmed.
  • F1 lists Rename symbol, and the mnemonics list shows rs.
  • The same works in a Go or TypeScript file with its server.

Tests

  • The textDocument/rename request and prepareRename (used only when the server advertises it), with the client capabilities declared; the response parsed from both changes and documentChanges (text edits only; ignore file create/rename/delete operations).
  • Applying a workspace edit: several edits in one file applied back to front so offsets stay right; edits to an open tab land as one undo step and leave it dirty; edits to closed files keep encoding, BOM and line endings; a file that changed on disk since the server answered is handled without corrupting it.
  • The counts in the confirm and Usages header, and when the confirm appears (only with at least one closed file).
  • Refusals: empty, unchanged, server error, prepareRename returning null.
  • Mnemonic table stays prefix-free with rs.

Out of scope

  • A default key (F2 or otherwise). The command ships with the mnemonic only.
  • A preview with a tick box per change.
  • Renaming the file along with a type, or advertising workspace file operations.
  • Undo across files that weren't open.
  • Renaming inside comments or strings, other refactorings, and handling server-pushed workspace/applyEdit.

Activity

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

    @a-team-app
    ContributorAuthor

    Draft PR #698 is up.

  2. added 2 commits that reference this issue on Nov 18, 2026
    3d1d4c5
    6c4b845
  3. jamescrosswell commented on Nov 19, 2026

    @jamescrosswell
    Contributor

    Is there any reason to limit this to method names? Could we not also use it to rename other symbols (like variables or classes)?

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

    @a-team-app
    ContributorAuthor

    No reason, and it isn't limited: rs asks the language server to rename whatever symbol is under the cursor, so variables, parameters, fields, classes and the rest work too. The task only said "method" in its wording, and the code doesn't filter by kind. I've reworded #698's description to say so. I only tried a method on screen, so a local variable or class with csharp-ls is untested so far.

  5. jamescrosswell commented on Nov 19, 2026

    @jamescrosswell
    Contributor

    OK in that case we maybe have a problem. I tried to rename the _bar symbol in the following code but I see a message saying it can't rename that symbol:

    public class Foo 
    {
        private int _bar;
    
        public int Bar15()
        {
            _bar = 15;
            return _bar;
        }
    
        public int Bar30()
        {
            _bar = 30;
            return _bar;
        }
    }

    Maybe there's a syntax error somewhere in that code? I'm not sure - the editor didn't have any red/highlighted text from the analyser though.

  6. added 2 commits that reference this issue on Nov 19, 2026
    662760d
    b1607f1
  7. a-team-app commented on Nov 19, 2026

    @a-team-app
    ContributorAuthor

    Not a syntax error, it was a bug. I reproduced it with your code and csharp-ls. It fails only when the cursor is just past the name, e.g. between _bar and ; (Ln 3, Col 21). csharp-ls won't rename from there, and rs passed it the cursor as it was. Now rs asks about the start of the name, so it opens Rename _bar from there too. Renaming it to _count changed all 5 uses.

    I also fixed something else this turned up: the dialog title showed Rename bar, because _ was read as a hotkey marker. There are tests for both.

    There's one more I haven't fixed: the status bar then says Renamed bar to _count. The library's status bar drops the first _ of any message, so this isn't only rename. The fix belongs in tui-style-guide. I've noted it on #698. Want me to open it as a follow-up?

  8. jamescrosswell commented on Nov 19, 2026

    @jamescrosswell
    Contributor

    There's one more I haven't fixed: the status bar then says Renamed bar to _count. The library's status bar drops the first _ of any message, so this isn't only rename. The fix belongs in tui-style-guide. I've noted it on #698. Want me to open it as a follow-up?

    Yes open an issue for that

  9. jamescrosswell commented on Nov 19, 2026

    @jamescrosswell
    Contributor

    I also can't currently try this out:

    a-team try: ~/code/TuiCode/.try/698 has 1 changed file at 6c4b845, behind b1607f1 (closes #697). Remove it with: a-team try tuicode 698 --clean

  10. a-team-app commented on Nov 19, 2026

    @a-team-app
    ContributorAuthor

    Opened #702 for the status bar hiding the first _, and put it on the board as an Idea.

    About try: the one changed file in ~/code/TuiCode/.try/698 is your test.cs (the Foo / _bar sample, untracked). It isn't part of the PR. That's what's stopping try from updating to b1607f1. Move it out and run a-team try tuicode 698 again. --clean would delete it, so copy it somewhere first if you want to keep it. I haven't touched it.

  11. jamescrosswell commented on Nov 20, 2026

    @jamescrosswell
    Contributor

    I still see, "Can't rename this" when I try to rename _bar in that code.

  12. added a commit that references this issue on Nov 20, 2026
    62f6b0f
  13. a-team-app commented on Nov 20, 2026

    @a-team-app
    ContributorAuthor

    Reproduced: it's where test.cs lives, not your code. csharp-ls only knows files inside a project it loaded. A loose test.cs at the repo root is in no .csproj, so it refuses every rename there. The same file inside a project opens Rename _bar fine.

    The bug was the message saying nothing useful. It now says Can't rename this: test.cs isn't in any C# project (pushed to #698, with a test). To try the rename itself, put the file in a folder with a .csproj, e.g. under src/TuiCode/.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions