Skip to content

Auto-update imports when files are renamed#1688

Merged
chrisdp merged 3 commits intomasterfrom
feature/update-imports-on-rename
Apr 29, 2026
Merged

Auto-update imports when files are renamed#1688
chrisdp merged 3 commits intomasterfrom
feature/update-imports-on-rename

Conversation

@chrisdp
Copy link
Copy Markdown
Contributor

@chrisdp chrisdp commented Apr 29, 2026

Summary

  • Adds LSP workspace/willRenameFiles support so renaming a .bs/.brs/.xml file in the editor auto-updates every import statement and <script uri> tag that points at it.
  • Each project independently produces edits; ProjectManager reconciles by (srcPath, range) and drops any edit where projects disagree on the replacement text, so we never corrupt source files in a multi-project workspace.
  • Original path style is preserved: pkg:/... stays pkg:/..., libpkg:/... stays libpkg:/..., and relative paths are recomputed from the containing file's pkg path.

Design notes

  • Capability: LanguageServer.ts advertises workspace.fileOperations.willRename with a **/*.{bs,brs,xml} file filter. The handler is registered manually under connection.workspace because the existing on* auto-bind loop only sees top-level connection methods.
  • Per-project edits: Project.getFileRenameEdits walks every BrsFile import statement and every XmlFile script-tag FileReference, comparing the resolved pkg path against the renamed file. Edits operate on the path-string range (which already excludes surrounding quotes), so quotes stay intact.
  • New-path resolution: tries rokuDeploy.getDestPath first so custom files mappings keep working, and falls back to a plain rootDir-relative path so renames into folders that aren't yet covered by the files glob still get their imports rewritten. Bails when the new path is outside the project's rootDir.
  • Worker delegation: WorkerThreadProject forwards via sendStandardRequest. The worker runner dispatches by name, so no other worker-side wiring is required.

Out of scope for v1

  • Folder renames are unrolled per-file by the LSP client; the server only registers matches: 'file'.
  • Files that move across project boundaries (different rootDir) are intentionally skipped — too easy to mangle in ambiguous cases.
  • Edits whose source import "..." is not a recognized style (e.g. variable expression, no scheme + no relative form) are skipped.

Test plan

  • 6 new util tests covering computeRenamedReferencePath path-style preservation
  • 9 new Project tests covering pkg:/, libpkg:/, relative, cross-folder, no-match, out-of-project, range-excludes-quotes, XML relative, XML pkg:/, both-references-at-once
  • 5 new ProjectManager consensus tests covering single-project pass-through, agreement, disagreement, unique-to-one-project, throw-isolation
  • 3 new LanguageServer tests covering capability advertisement, null-when-no-match, and a full WorkspaceEdit on a real rename
  • Existing 2700+ test suite passes
  • Manual end-to-end verification (paired with the extension PR) — see linked PR

Paired extension PR

Companion change in the extension that handles the silent-apply + save flow on the client side: linking shortly.

🤖 Generated with Claude Code

Advertise workspace.fileOperations.willRename for *.{bs,brs,xml} and
walk every project's program when a rename arrives. For each BrsFile
import statement and XmlFile <script uri> tag that resolves to the
old pkg path, produce a text edit that preserves the original style
(pkg:/, libpkg:/, or relative).

ProjectManager aggregates per-project edits and reconciles by
(srcPath, range) — when projects disagree on the replacement, the
edit is dropped to avoid corrupting source. Per-project failures are
isolated.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
TwitchBronBron and others added 2 commits April 29, 2026 14:21
…shape

Replaces the custom FileRenameEdit interface with FileRenameTextEdit,
a thin extension of LSP's TextEdit that adds a uri field. Each project
returns a flat array; ProjectManager reconciles by (uri, range);
LanguageServer groups by uri into the WorkspaceEdit response.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@TwitchBronBron TwitchBronBron enabled auto-merge (squash) April 29, 2026 19:02
@TwitchBronBron TwitchBronBron disabled auto-merge April 29, 2026 19:02
@chrisdp chrisdp merged commit 595e31f into master Apr 29, 2026
7 checks passed
@chrisdp chrisdp deleted the feature/update-imports-on-rename branch April 29, 2026 19:20
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.

2 participants