Skip to content

Commit 942cf09

Browse files
authored
Prevent continuous "package resolve" cycles (#1654)
* Prevent continuous "package resolve" cycles We can ignore the create and delete events as these were likely caused by the LSP or SwiftPM anywatch. Watch for change still in case the user switches branches Issue: #1571 * Add CHANGELOG entry
1 parent 3a615aa commit 942cf09

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Cleanup Swift diagnostics when the source file is moved or deleted ([#1653](https://github.com/swiftlang/vscode-swift/pull/1653))
88
- Make sure newline starts with /// when splitting doc comment ([#1651](https://github.com/swiftlang/vscode-swift/pull/1651))
9+
- Prevent continuous "package resolve" cycles ([#1654](https://github.com/swiftlang/vscode-swift/pull/1654))
910
- Fix error when running `Reset Package Dependencies` command from the Project view ([#1661](https://github.com/swiftlang/vscode-swift/pull/1661))
1011

1112
## 2.6.0 - 2025-06-26

src/PackageWatcher.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { showReloadExtensionNotification } from "./ui/ReloadExtension";
3030
*/
3131
export class PackageWatcher {
3232
private packageFileWatcher?: vscode.FileSystemWatcher;
33+
private resolvedChangedDisposable?: vscode.Disposable;
3334
private resolvedFileWatcher?: vscode.FileSystemWatcher;
3435
private workspaceStateFileWatcher?: vscode.FileSystemWatcher;
3536
private snippetWatcher?: vscode.FileSystemWatcher;
@@ -59,6 +60,7 @@ export class PackageWatcher {
5960
*/
6061
dispose() {
6162
this.packageFileWatcher?.dispose();
63+
this.resolvedChangedDisposable?.dispose();
6264
this.resolvedFileWatcher?.dispose();
6365
this.workspaceStateFileWatcher?.dispose();
6466
this.snippetWatcher?.dispose();
@@ -77,11 +79,18 @@ export class PackageWatcher {
7779

7880
private createResolvedFileWatcher(): vscode.FileSystemWatcher {
7981
const watcher = vscode.workspace.createFileSystemWatcher(
80-
new vscode.RelativePattern(this.folderContext.folder, "Package.resolved")
82+
new vscode.RelativePattern(this.folderContext.folder, "Package.resolved"),
83+
// https://github.com/swiftlang/vscode-swift/issues/1571
84+
// We can ignore create because that would be seemingly from a Package.resolved
85+
// and will ignore delete as we don't know the reason behind. By still listening
86+
// for change
87+
true,
88+
false,
89+
true
90+
);
91+
this.resolvedChangedDisposable = watcher.onDidChange(
92+
async () => await this.handlePackageResolvedChange()
8193
);
82-
watcher.onDidCreate(async () => await this.handlePackageResolvedChange());
83-
watcher.onDidChange(async () => await this.handlePackageResolvedChange());
84-
watcher.onDidDelete(async () => await this.handlePackageResolvedChange());
8594
return watcher;
8695
}
8796

0 commit comments

Comments
 (0)