Skip to content

Prevent continuous "package resolve" cycles #1654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions src/PackageWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,6 +60,7 @@ export class PackageWatcher {
*/
dispose() {
this.packageFileWatcher?.dispose();
this.resolvedChangedDisposable?.dispose();
this.resolvedFileWatcher?.dispose();
this.workspaceStateFileWatcher?.dispose();
this.snippetWatcher?.dispose();
Expand All @@ -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;
}

Expand Down