Skip to content

Clear auto-import specifier cache when user preferences change - #64821

Open
lsh4711 wants to merge 1 commit into
microsoft:mainfrom
lsh4711:fix-specifier-cache-on-preference-change
Open

lsh4711 wants to merge 1 commit into
microsoft:mainfrom
lsh4711:fix-specifier-cache-on-preference-change

Conversation

@lsh4711

@lsh4711 lsh4711 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #64820

Registry.specifierCache was only cleared when autoImportSpecifierExcludeRegexes changed, so a change to importModuleSpecifierPreference or importModuleSpecifierEnding kept returning specifiers computed with the old preferences for files that were already open.

This clears the cache on every user preference change instead of comparing the specific preferences that affect specifiers:

  • Preference changes only happen when the user edits their settings, so they are rare.
  • Clearing is cheap: specifiers are recomputed lazily, only for the imports that are requested afterwards.
  • Comparing individual fields is what caused this bug, since importModuleSpecifierPreference and importModuleSpecifierEnding were never added to the check. Clearing unconditionally keeps the cache correct when new preferences that affect specifiers are added later.

Added TestAutoImportModuleSpecifierAfterUserPreferenceChange, which changes autoImportSpecifierExcludeRegexes, importModuleSpecifierEnding and importModuleSpecifierPreference one at a time on an open file and checks the auto-import specifier after each change. The first step covers the existing behavior; the other two fail without this change.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 22:17
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 14, 2026
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 14, 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 reached their quota limit.

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 Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Changing importModuleSpecifier or importModuleSpecifierEnding does not update auto-import specifiers in open files

2 participants