diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bc6a9ecb..4741a24a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Cleanup Swift diagnostics when the source file is moved or deleted ([#1653](https://github.com/swiftlang/vscode-swift/pull/1653)) - Make sure newline starts with /// when splitting doc comment ([#1651](https://github.com/swiftlang/vscode-swift/pull/1651)) +- Prevent continuous "package resolve" cycles ([#1654](https://github.com/swiftlang/vscode-swift/pull/1654)) - Fix error when running `Reset Package Dependencies` command from the Project view ([#1661](https://github.com/swiftlang/vscode-swift/pull/1661)) ## 2.6.0 - 2025-06-26 diff --git a/src/PackageWatcher.ts b/src/PackageWatcher.ts index ab900f1de..712f8c0a9 100644 --- a/src/PackageWatcher.ts +++ b/src/PackageWatcher.ts @@ -30,6 +30,7 @@ import { showReloadExtensionNotification } from "./ui/ReloadExtension"; */ export class PackageWatcher { private packageFileWatcher?: vscode.FileSystemWatcher; + private resolvedChangedDisposable?: vscode.Disposable; private resolvedFileWatcher?: vscode.FileSystemWatcher; private workspaceStateFileWatcher?: vscode.FileSystemWatcher; private snippetWatcher?: vscode.FileSystemWatcher; @@ -59,6 +60,7 @@ export class PackageWatcher { */ dispose() { this.packageFileWatcher?.dispose(); + this.resolvedChangedDisposable?.dispose(); this.resolvedFileWatcher?.dispose(); this.workspaceStateFileWatcher?.dispose(); this.snippetWatcher?.dispose(); @@ -77,11 +79,18 @@ export class PackageWatcher { private createResolvedFileWatcher(): vscode.FileSystemWatcher { const watcher = vscode.workspace.createFileSystemWatcher( - new vscode.RelativePattern(this.folderContext.folder, "Package.resolved") + new vscode.RelativePattern(this.folderContext.folder, "Package.resolved"), + // https://github.com/swiftlang/vscode-swift/issues/1571 + // We can ignore create because that would be seemingly from a Package.resolved + // and will ignore delete as we don't know the reason behind. By still listening + // for change + true, + false, + true + ); + this.resolvedChangedDisposable = watcher.onDidChange( + async () => await this.handlePackageResolvedChange() ); - watcher.onDidCreate(async () => await this.handlePackageResolvedChange()); - watcher.onDidChange(async () => await this.handlePackageResolvedChange()); - watcher.onDidDelete(async () => await this.handlePackageResolvedChange()); return watcher; }