Skip to content
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

Edit: Fix flickering code lens for users with autoSave enabled #1767

Merged
merged 3 commits into from
Nov 16, 2023
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 vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Starting from `0.2.0`, Cody is using `major.EVEN_NUMBER.patch` for release versi
- Autocomplete: Fix an issue where typing as suggested causes the completion to behave unexpectedly. [pull/1701](https://github.com/sourcegraph/cody/pull/1701)
- Chat: Forbid style tags in DOMPurify config to prevent code block rendering issues. [pull/1747](https://github.com/sourcegraph/cody/pull/1747)
- Edit: Fix `selectedCode` and `problemCode` sometimes being added to the document after an edit. [pull/1765](https://github.com/sourcegraph/cody/pull/1765)
- Edit: Fix the code lens containing options to diff, undo and retry being automatically dismissed for users who have `autoSave` enabled. [pull/1767](https://github.com/sourcegraph/cody/pull/1767)

### Changed

Expand Down
28 changes: 18 additions & 10 deletions vscode/src/non-stop/FixupController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,25 @@ export class FixupController
// Observe file edits
this.editObserver = new FixupDocumentEditObserver(this)
this._disposables.push(
vscode.workspace.onDidChangeTextDocument(this.editObserver.textDocumentChanged.bind(this.editObserver)),
vscode.workspace.onDidSaveTextDocument(({ uri }) => {
// If we save the document, we consider the user to have accepted any applied tasks.
// This helps ensure that the codelens doesn't stay around unnecessarily and become an annoyance.
for (const task of this.tasks.values()) {
if (task.fixupFile.uri.fsPath.endsWith(uri.fsPath)) {
this.accept(task.id)
}
}
})
vscode.workspace.onDidChangeTextDocument(this.editObserver.textDocumentChanged.bind(this.editObserver))
)

// Only auto-accept tasks on save if the user doesn't have a conflicting autoSave setting.
// Otherwise the code lens will just flicker for the user, as it will be accepted almost immediately
const autoSaveSetting = vscode.workspace.getConfiguration('files').get<string>('autoSave')
if (autoSaveSetting === 'off' || autoSaveSetting === 'onWindowChange') {
this._disposables.push(
vscode.workspace.onDidSaveTextDocument(({ uri }) => {
// If we save the document, we consider the user to have accepted any applied tasks.
// This helps ensure that the codelens doesn't stay around unnecessarily and become an annoyance.
for (const task of this.tasks.values()) {
if (task.fixupFile.uri.fsPath.endsWith(uri.fsPath)) {
this.accept(task.id)
}
}
})
)
}
}

/**
Expand Down