Skip to content

Commit c58c958

Browse files
ntottenclaude
andauthored
Watch .prettierignore for cache invalidation (#3943)
When users modify .prettierignore, the extension may use stale ignore data because Prettier caches file info. This adds a file system watcher for .prettierignore that clears the cache on change, create, or delete events, similar to how other config files are already watched. Fixes #3942 Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 61b4780 commit c58c958

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ All notable changes to the "prettier-vscode" extension will be documented in thi
66

77
## [Unreleased]
88

9+
- Watch `.prettierignore` for changes to invalidate cache (#3942)
10+
911
## [12.2.0]
1012

1113
- Fixed `source.fixAll.prettier` code action running even when `editor.defaultFormatter` was set to a different extension (#3908). The code action now respects the user's formatter choice and only runs when Prettier is the default formatter or when `source.fixAll.prettier` is explicitly enabled.

src/PrettierEditService.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ export default class PrettierEditService implements Disposable {
159159
watcher.onDidDelete(this.prettierConfigChanged);
160160
}
161161

162+
// Watch .prettierignore for changes to invalidate ignore cache
163+
const prettierIgnoreWatcher =
164+
workspace.createFileSystemWatcher("**/.prettierignore");
165+
prettierIgnoreWatcher.onDidChange(this.prettierConfigChanged);
166+
prettierIgnoreWatcher.onDidCreate(this.prettierConfigChanged);
167+
prettierIgnoreWatcher.onDidDelete(this.prettierConfigChanged);
168+
162169
const textEditorChange = window.onDidChangeActiveTextEditor(
163170
this.handleActiveTextEditorChangedSync,
164171
);
@@ -169,6 +176,7 @@ export default class PrettierEditService implements Disposable {
169176
packageWatcher,
170177
configurationWatcher,
171178
...prettierConfigWatchers,
179+
prettierIgnoreWatcher,
172180
textEditorChange,
173181
];
174182
}

0 commit comments

Comments
 (0)