Skip to content

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

Merged
jamescrosswell merged 8 commits into
mainfrom
feat/rename-symbol
Nov 22, 2026
Merged

jamescrosswell merged 8 commits into
mainfrom
feat/rename-symbol

Conversation

@a-team-app

@a-team-app a-team-app Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Rename symbol (rs, in Edit, and the palette) renames the symbol under the cursor (a variable, parameter, field, method, property, class or any other symbol the language server can rename) across the folder, through the language server. It asks for the new name, edits the open tabs (unsaved, one Ctrl+Z per tab), and confirms before writing files that aren't open, keeping their BOM and line endings. Afterwards the Usages tab lists every changed line under Renamed <old> → <new> · <n> in <m> files. Comments and strings are left alone, since only the server's edits are made.

Closes #697

Choices worth a look:

  • F1 doesn't list Rename symbol. F1 only lists commands that have a key, and this one ships with none, like gs. So criterion 10 is only half met: the mnemonics list shows rs. To list it, either give it a key or have F1 show key-less commands by their mnemonic. Tell me which you want.
  • A tab edited, or a closed file changed on disk, between the server's answer and the rename is left alone. The status bar names it, rather than risking a corrupted file.
  • After writing closed files, TuiCode sends the server workspace/didChangeWatchedFiles, so its next answer isn't based on the old text.
  • Closed files are rewritten only when they're UTF-8 (with or without a BOM), the same as Replace in files. Anything else is skipped and named.
  • Not checked: Go or TypeScript (criterion 11). gopls and typescript-language-server aren't installed on this machine. The screenshots use csharp-ls on a small sample project.
  • With the cursor just past a name (_bar|;), rs now renames that name. csharp-ls refuses to prepare a rename there, so TuiCode asks about the start of the name instead.
  • Not fixed here: the status bar drops the first _ of any message (Renamed _bar to _count shows as Renamed bar to _count). That's MentalDesk.Tui's AppStatusBar treating _ as a hotkey marker, so it affects every status message, not just rename. The fix is in tui-style-guide.

What it looks like

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.

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.

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.

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.

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.

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.

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.

Checked by the team

  • screen 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.
  • test 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.
  • test Esc (or [ Cancel ]) closes the dialog and changes nothing.
  • test 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.
  • screen 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.
  • screen 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.
  • screen 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.
  • screen 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.
  • test 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.

a-team try tuicode 698

…age server

Asks textDocument/prepareRename where the server advertises prepareProvider,
then opens a prompt on the name it gives. Ctrl+Enter sends textDocument/rename
and reads the WorkspaceEdit from documentChanges or changes, text edits only.
Open tabs take their part as one ReplaceLines each, so one undo step, left
unsaved; files that aren't open are written after a confirm, keeping their
BOM and line endings, and the server is told they changed. A tab edited or a
file changed on disk since the server was asked is skipped and named on the
status bar. The Usages tab lists one row per changed line afterwards.

Closes #697

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hang on Windows

new Uri("/work/New.cs") throws on Windows, so the fake never answered
textDocument/rename and Rename_reads_documentChanges_and_leaves_out_the_file_operations
waited until CI's 30-minute timeout.

Closes #697

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@a-team-app

a-team-app Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

CI on 3d1d4c5: build-test (ubuntu-latest) in the push run failed only EditorLargeFileTests.Typing_and_scrolling_cost_about_the_same… (34 ms/key vs 7.6 ms), a timing test on code this PR doesn't touch; the same job passed in the pull_request run of this commit. Transient, so it gets re-run (gh run rerun 44252789467 --failed) once the run settles, not fixed.

@a-team-app

a-team-app Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Needs changing

  • src/TuiCode.Workbench/WorkbenchHost.cs:654 The Usages rows for a rename come from LinesOf, which only looks at the active group's tabs (Editor.Group.Tabs), while the rename edits tabs in every group. If the editor is split and a changed file is open, unsaved, in the other group, its rows are read from disk and show the old name (Diff.Hunks(); under Renamed Hunks → Count). Find usages could live with this because nothing was unsaved. Rename makes it visible, so LinesOf should look in Editor.Groups.Tabs, as line 1994 does.
  • src/TuiCode.Workbench/WorkbenchHost.cs:660 Every skipped file is reported as one "which changed while renaming". WorkspaceRename.Apply also skips a closed file that isn't UTF-8, can't be written, or has an edit that falls outside it, plus a read-only tab. So for a Windows-1252 file with café in a comment, the status bar gives the wrong reason. The PR body says such files are "skipped and named", so the message should say why, or use a neutral wording ("left unchanged").
  • Criterion 10 isn't met: F1 doesn't list Rename symbol. The PR body asks the stakeholder to choose between giving it a key and having F1 list commands that have no key. That needs their answer before this goes in.
  • The picture captioned "With the cursor on a method name … all of it selected" doesn't show SaveAsync as selected. It's drawn like plain field text, with the caret after it. The test checks SelectedText, but on screen the selection can't be seen. Either the selection isn't drawn after FocusInput, or its colour can't be told apart from the field.

Worth considering

  • Criterion 11 (Go and TypeScript) hasn't been checked. LspRename reads both changes (typescript-language-server) and documentChanges (gopls), and nothing on the path is specific to C#, so the risk is low. Still, someone with gopls installed could run rs once.
  • WorkspaceRename.Plan takes its snapshot of each closed file's bytes after the server answers, not when it's asked. A file changed on disk while the server was working gets the server's edits applied at offsets that are no longer right. TextEdits.Apply only refuses edits that are out of range or overlap. A cheap guard would be to read the bytes before sending textDocument/rename.
  • Tests: no host test covers a rename where a file is skipped (the status-bar message), or one where the editor is split.

…s left unchanged

After a rename, a changed file open in the other editor group had its
Usages rows read from disk, showing the old name. Rows now come from
whichever group holds the tab.

The status bar said every skipped file "changed while renaming", but a
file is also skipped when it isn't UTF-8, can't be written, or is
read-only. It now says the file was left unchanged.

Closes #697

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@a-team-app

a-team-app Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Pushed 6c4b845.

  1. Fixed. LinesOf now looks in Editor.Groups.Tabs, so a changed file open in the other group shows its renamed lines. New test: With_the_editor_split_Usages_shows_the_renamed_lines_of_a_tab_in_the_other_group (fails without the fix).
  2. Fixed, with neutral wording: Renamed Hunks to Count, but left Report.cs unchanged. New test with a Latin-1 closed file: A_file_the_rename_cant_write_is_named_in_the_status_bar_as_left_unchanged.
  3. Left for @jamescrosswell. This needs your call, as the PR body asks: give Rename symbol a key, or have F1 list commands that have no key by their mnemonic?
  4. Not changed. The name is selected and drawn: the cast shows SaveAsync on #3A4150, the field's selection colour, against the field's #1B1E24. F2's Move or Rename prompt draws its selected stem the same way. It's just faint in this theme, for every text box. Fixing that means changing the theme's selection colour in the style guide, which this PR doesn't otherwise touch. I can open a follow-up if you want one.

I've left Worth considering for you.

@a-team-app
a-team-app Bot marked this pull request as ready for review November 18, 2026 08:13
a-team-app Bot and others added 4 commits November 19, 2026 21:22
…ialog's title

csharp-ls answers prepareRename with null when the cursor is just past a
name (before a `;` say), so `rs` there said "Can't rename this". Ask about
the start of the identifier at or just before the cursor instead, as the
word fallback already did. And `_` in the dialog's title was taken as a
hotkey marker, so "Rename _bar" showed as "Rename bar".

Closes #697

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Closes #697

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	src/TuiCode.Workbench/Languages/LanguageServer.cs
#	src/TuiCode.Workbench/WorkbenchHost.cs
#	tests/TuiCode.Tests/FakeLanguageServer.cs
#	tests/TuiCode.Tests/MenuBarHostTests.cs
csharp-ls only knows files inside a project it loaded, and answers
prepareRename with null for any other, so a loose test.cs at a repo
root got a bare "Can't rename this". When no folder from the file's up
to the server's root holds a .csproj, the status bar now says so.

Closes #697

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@a-team-app

a-team-app Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

CI on 62f6b0f failed on ubuntu only, in one test: EditorLargeFileTests timing (33.6 ms a key at 50,000 lines against 5.6 ms at 500, over its 3× + 10 ms limit). That test drives EditorTab alone, which this PR doesn't touch, and the full suite passes locally, that test included. So I've re-run the failed jobs rather than changing code.

@jamescrosswell
jamescrosswell merged commit 8023bed into main Nov 22, 2026
30 checks passed
@jamescrosswell
jamescrosswell deleted the feat/rename-symbol branch November 22, 2026 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant