Auto-update imports when files are renamed#1688
Merged
Conversation
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>
4 tasks
…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
approved these changes
Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
workspace/willRenameFilessupport so renaming a.bs/.brs/.xmlfile in the editor auto-updates everyimportstatement and<script uri>tag that points at it.ProjectManagerreconciles 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.pkg:/...stayspkg:/...,libpkg:/...stayslibpkg:/..., and relative paths are recomputed from the containing file's pkg path.Design notes
LanguageServer.tsadvertisesworkspace.fileOperations.willRenamewith a**/*.{bs,brs,xml}file filter. The handler is registered manually underconnection.workspacebecause the existingon*auto-bind loop only sees top-level connection methods.Project.getFileRenameEditswalks everyBrsFileimport statement and everyXmlFilescript-tagFileReference, 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.rokuDeploy.getDestPathfirst so customfilesmappings keep working, and falls back to a plain rootDir-relative path so renames into folders that aren't yet covered by thefilesglob still get their imports rewritten. Bails when the new path is outside the project's rootDir.WorkerThreadProjectforwards viasendStandardRequest. The worker runner dispatches by name, so no other worker-side wiring is required.Out of scope for v1
matches: 'file'.rootDir) are intentionally skipped — too easy to mangle in ambiguous cases.import "..."is not a recognized style (e.g. variable expression, no scheme + no relative form) are skipped.Test plan
computeRenamedReferencePathpath-style preservationProjecttests coveringpkg:/,libpkg:/, relative, cross-folder, no-match, out-of-project, range-excludes-quotes, XML relative, XMLpkg:/, both-references-at-onceProjectManagerconsensus tests covering single-project pass-through, agreement, disagreement, unique-to-one-project, throw-isolationLanguageServertests covering capability advertisement, null-when-no-match, and a full WorkspaceEdit on a real renamePaired extension PR
Companion change in the extension that handles the silent-apply + save flow on the client side: linking shortly.
🤖 Generated with Claude Code