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

Fix indefinite line tracker suspension after closing large dirty editor #3067

Merged
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 @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed

- Fixes [#2926](https://github.com/gitkraken/vscode-gitlens/issues/2926) in more cases - "Open File at Revision" has incorrect editor label if revision contains path separator — thanks to [PR #3060](https://github.com/gitkraken/vscode-gitlens/issues/3060) by Ian Chamberlain ([@ian-h-chamberlain](https://github.com/ian-h-chamberlain)
- Fixes [#3066](https://github.com/gitkraken/vscode-gitlens/issues/3066) - Editing a large file and switching away to another file without saving causes current line blame to disappear; thanks to [PR #3067](https://github.com/gitkraken/vscode-gitlens/pulls/3067) by Brandon Cheng ([@gluxon](https://github.com/gluxon)).

## [14.6.1] - 2023-12-14

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ A big thanks to the people that have contributed to this project 🙏❤️:
- WofWca ([@WofWca](https://github.com/WofWca)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=WofWca)
- 不见月 ([@nooooooom](https://github.com/nooooooom)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=nooooooom)
- Ian Chamberlain ([@ian-h-chamberlain](https://github.com/ian-h-chamberlain)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=ian-h-chamberlain)
- Brandon Cheng ([@gluxon](https://github.com/gluxon)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=gluxon)`

Also special thanks to the people that have provided support, testing, brainstorming, etc:

Expand Down
12 changes: 12 additions & 0 deletions src/trackers/gitLineTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ export class GitLineTracker extends LineTracker<GitLineState> {
this._subscriptionOnlyWhenActive = undefined;
}

protected override onActiveEditorChanged() {
// The GitLineTracker is suspended for performance while users have
// dirty changes in a large editor with lines exceeding the
// advanced.blame.sizeThresholdAfterEdit config.
//
// We'll need to resume if the active editor has changed (since the
// suspension was for the previous editor). Otherwise the line tracker
// would stay suspended after navigating away from the large dirty
// document.
this.resume();
}

@debug<GitLineTracker['onBlameStateChanged']>({
args: {
0: e => `editor/doc=${e.editor.document.uri.toString(true)}, blameable=${e.blameable}`,
Expand Down
7 changes: 7 additions & 0 deletions src/trackers/lineTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class LineTracker<T> implements Disposable {
this._selections = toLineSelections(editor?.selections);

this.notifyLinesChanged('editor');
this.onActiveEditorChanged?.();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was brainstorming a few alternatives to this approach.

  1. Instead of the indirection through GitLineTracker, we could also call this.resume() right here. That felt strange since nothing else in lineTracker.ts suspends or resumes the tracker. This feels like a gitLineTracker.ts responsibility based on what's written today.
  2. We could call this.fireDocumentDirtyStateChanged in the window.onDidChangeActiveTextEditor handler. This feels like a reasonable alternative approach to me. The main downside is that it's a bit of a slippery slope with regard to what document-specific change events are re-fired when the active editor changes. Ex: Would we also want to call onBlameStateChanged when the active editor changes?

I settled on the current approach, but happy to consider others in more depth if others have thoughts.

}

private onTextEditorSelectionChanged(e: TextEditorSelectionChangeEvent) {
Expand Down Expand Up @@ -197,6 +198,12 @@ export class LineTracker<T> implements Disposable {
this.notifyLinesChanged('editor');
}

/**
* Called after the active editor is changed and line tracker state has been
* updated for it.
*/
protected onActiveEditorChanged?(): void;

protected fireLinesChanged(e: LinesChangeEvent) {
this._onDidChangeActiveLines.fire(e);
}
Expand Down