Skip to content

fix: deduplicate rename edits for dynamic imports with .ts specifiers - #65512

Open
刘亦达 (zhengdaodeguL) wants to merge 1 commit into
microsoft:mainfrom
zhengdaodeguL:fix/willrenamefiles-duplicate-edit-65505
Open

刘亦达 (zhengdaodeguL) wants to merge 1 commit into
microsoft:mainfrom
zhengdaodeguL:fix/willrenamefiles-duplicate-edit-65505

Conversation

@zhengdaodeguL

Copy link
Copy Markdown

Fixes #65505

Background

Renaming a file loaded by a dynamic import("./file.ts") (with
allowImportingTsExtensions) makes the language server panic and exit
(status 2): panic: changes overlap: {{0 34} {0 47}} and {{0 34} {0 47}}.
updateImportsForFileRename queues one edit per sourceFile.Imports()
entry, and the dynamic import produces the same specifier-range edit twice;
change.Tracker.GetChanges panics on the duplicate before the LSP layer's
later deduplication can run. Static imports and .js specifiers only produce
one edit and do not panic.

Change

Deduplicate identical import edits per source file in
updateImportsForFileRename, keyed by text range + replacement text. A
conflicting replacement at the same range still passes through to the
existing overlap check. Adds a fourslash regression test covering the
dynamic .ts import case, asserting exactly one edit with new text
./sub/moved.ts.

Verification

  • go test ./internal/fourslash/tests -run '^TestGetEditsForFileRename' —
    pass (includes the new regression test; the new test fails on base code
    with the panic).
  • LSP repro against the built server: before the fix the server exits
    status 2 with the changes overlap panic; after the fix the
    workspace/willRenameFiles response contains exactly one edit
    (./sub/moved.ts) and the server keeps running. The .js specifier
    control case still returns one edit.
  • gofmt -l clean on both changed files; git diff --check clean.

Not run: full npx hereby test (too large for this environment; only the
targeted Go tests were run), npx hereby lint, npx hereby check:format.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 13:52
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 15, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

workspace/willRenameFiles panics with "changes overlap" when the renamed file is loaded by import() with a .ts specifier

2 participants