Repository navigation
Closed
Description
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 titledRename <name>, with aNew 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+Zin 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, andEnteron 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/renamerequest andprepareRename(used only when the server advertises it), with the client capabilities declared; the response parsed from bothchangesanddocumentChanges(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,
prepareRenamereturning 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.
Metadata
Metadata
Assignees
Labels
No labels
Activity
a-team-app commentedon Nov 18, 2026
Draft PR #698 is up.
Give the fake server's created file a full path, so the test doesn't …
Read Usages rows from tabs in either group, and say a skipped file wa…
jamescrosswell commentedon Nov 19, 2026
Is there any reason to limit this to method names? Could we not also use it to rename other symbols (like variables or classes)?
a-team-app commentedon Nov 19, 2026
No reason, and it isn't limited:
rsasks 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.jamescrosswell commentedon Nov 19, 2026
OK in that case we maybe have a problem. I tried to rename the
_barsymbol in the following code but I see a message saying it can't rename that symbol: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.
Rename the name just before the cursor, and keep a leading _ in the d…
Keep IdentifierAt's summary on it
a-team-app commentedon Nov 19, 2026
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
_barand;(Ln 3, Col 21). csharp-ls won't rename from there, andrspassed it the cursor as it was. Nowrsasks about the start of the name, so it opensRename _barfrom there too. Renaming it to_countchanged 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?jamescrosswell commentedon Nov 19, 2026
Yes open an issue for that
jamescrosswell commentedon Nov 19, 2026
I also can't currently try this out:
a-team-app commentedon Nov 19, 2026
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/698is yourtest.cs(theFoo/_barsample, untracked). It isn't part of the PR. That's what's stopping try from updating to b1607f1. Move it out and runa-team try tuicode 698again.--cleanwould delete it, so copy it somewhere first if you want to keep it. I haven't touched it.jamescrosswell commentedon Nov 20, 2026
I still see, "Can't rename this" when I try to rename
_barin that code.Say when Rename symbol can't rename because the file is in no C# project
a-team-app commentedon Nov 20, 2026
Reproduced: it's where
test.cslives, not your code. csharp-ls only knows files inside a project it loaded. A loosetest.csat the repo root is in no.csproj, so it refuses every rename there. The same file inside a project opensRename _barfine.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. undersrc/TuiCode/.