Skip to content

Fix auto-import not offering unsaved exports after auto-imports were computed - #64960

Open
Harsh Vardhan Chauhan (1-DARK) wants to merge 1 commit into
microsoft:mainfrom
1-DARK:fix-autoimport-unsaved-export
Open

Harsh Vardhan Chauhan (1-DARK) wants to merge 1 commit into
microsoft:mainfrom
1-DARK:fix-autoimport-unsaved-export

Conversation

@1-DARK

Copy link
Copy Markdown

Fixes #64953

markBucketsDirty removed a bucket from the "clean" set after its first dirty file (when multipleFilesDirty was false), instead of once the
bucket was fully dirty. Any further changed files in the same batch were then skipped.

In the reported sequence, closing importer.ts and opening exporter.ts land in one batch. The Deleted importer was processed first, so the
Changed exporter.ts was never marked dirty. The bucket kept the stale (empty) exporter.ts, and unsavedFn was never offered as an auto-import,
via completion or getImportEditsForSymbols.

The condition was inverted in three places (the project bucket and both node_modules paths). Each now removes the bucket only when
multipleFilesDirty is true.

Tests

Adds TestUnsavedExportAfterAutoImportsComputed in tsc/internal/ls/autoimport/registry_test.go. It follows the reported sequence: open importer,
request auto-imports, close importer, open exporter with unsaved content, reopen importer, request auto-imports. It then asserts that the project
bucket indexed the export.

  • Without the fix: FAIL. The bucket is dirty only for importer.ts and has ExportCount:0.
  • With the fix: PASS.
$ go test ./internal/ls/autoimport -run TestUnsavedExport
ok     github.com/microsoft/TypeScript/tsc/internal/ls/autoimport

Other checks:

  • go test ./internal/project/... ./internal/ls/... ./internal/fourslash/... passes.
  • npx hereby lint: 0 issues.
  • npx hereby check:format: passes.
  • go test ./...: the only failure is astnav TestGetTouchingPropertyName. It also fails without this change.

Verification

Ran https://github.com/johnsoncodehk/tsgo-auto-import-unsaved-export-repro against a local build, using this repo's JS API client.

Before the fix:

FAIL 0/5  [API] getImportEditsForSymbols, unsaved export, auto-imports computed before
FAIL 0/5  [LSP] completion,               unsaved export, auto-imports computed before
PASS 5/5  [API] getImportEditsForSymbols, unsaved export, no auto-imports before
PASS 5/5  [LSP] completion,               unsaved export, no auto-imports before
PASS 5/5  [API] getImportEditsForSymbols, saved export,   auto-imports computed before
PASS 5/5  [LSP] completion,               saved export,   auto-imports computed before

After the fix:

PASS 5/5  [API] getImportEditsForSymbols, unsaved export, auto-imports computed before
PASS 5/5  [LSP] completion,               unsaved export, auto-imports computed before
PASS 5/5  [API] getImportEditsForSymbols, unsaved export, no auto-imports before
PASS 5/5  [LSP] completion,               unsaved export, no auto-imports before
PASS 5/5  [API] getImportEditsForSymbols, saved export,   auto-imports computed before
PASS 5/5  [LSP] completion,               saved export,   auto-imports computed before

…a batch

markBucketsDirty removed a bucket from the clean set after its first dirty
file (when multipleFilesDirty was false) instead of once it was fully dirty.
Subsequent changed files in the same batch were skipped, so an export that
only existed as unsaved content was never re-indexed.

Add a regression test.
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 25, 2026
Copilot AI balanced review requested due to automatic review settings October 25, 2026 18:06
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 25, 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.

🟢 Approval recommended

The focused condition fixes match the bucket-state semantics, and the regression test covers the reported failure sequence with no identified blocking issues.

No open issues 🎉

What changed in this PR

Fixes #64953 by correcting auto-import cache invalidation so unsaved exports are indexed when multiple file changes arrive in one batch.

Changes:

  • Keeps project and node_modules buckets eligible for further invalidation until they are fully dirty.
  • Adds a regression test covering the close/reopen sequence that previously left unsaved exports unindexed.
File Description
tsc/​internal/​ls/​autoimport/​registry.go Corrects three conditions that prematurely stopped processing bucket changes.
tsc/​internal/​ls/​autoimport/​registry_test.go Verifies unsaved exports are indexed after auto-imports were previously computed.

Review effort: Balanced

@1-DARK

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Oct 26, 2026
@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 Oct 26, 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: Needs merge

Development

Successfully merging this pull request may close these issues.

Unsaved export not offered for auto-import after reopening the importing file

3 participants