Skip to content

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

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

lsh4711 wants to merge 2 commits 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 compares all preferences returned by ModuleSpecifierPreferences() (the ones passed to GetModuleSpecifier) through a new modulespecifiers.UserPreferences.Equal, and clears the cache only when they differ.

Added TestUserPreferencesEqual, and TestAutoImportModuleSpecifierAfterUserPreferenceChange, which changes autoImportSpecifierExcludeRegexes, importModuleSpecifierEnding and importModuleSpecifierPreference one at a time on an open file and checks the auto-import specifier after each 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.

@RyanCavanaugh

Copy link
Copy Markdown
Member

This clears the cache on every user preference change

This is a strong claim that isn't well-supported by the code. It's allowed for the editor to re-send config even in the absence of a change, and it's easy to set up your editor to allow toggling preferences a lot for whatever reason (e.g. inlay hints). Without stronger justification than "it's rare so it's OK" I'd really prefer this just be done correctly (check the preferences values that matter).

@lsh4711 lsh4711 changed the title Clear auto-import specifier cache when user preferences change Clear auto-import specifier cache when module specifier preferences change Oct 15, 2026
@lsh4711

lsh4711 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, that's fair. I changed it to clear the cache only when the preferences returned by ModuleSpecifierPreferences() change, which are the ones passed to GetModuleSpecifier. I added an Equal method next to modulespecifiers.UserPreferences (following bucketBuildPreferences.Equal), so a field added to that struct is next to its comparison, and a unit test for it.

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

3 participants