|
|
@ -4,6 +4,7 @@ import { Container } from '../container'; |
|
|
|
import { GitBlameCommit, GitLogCommit } from '../git/gitService'; |
|
|
|
import { |
|
|
|
DocumentBlameStateChangeEvent, |
|
|
|
DocumentContentChangeEvent, |
|
|
|
DocumentDirtyIdleTriggerEvent, |
|
|
|
DocumentDirtyStateChangeEvent, |
|
|
|
GitDocumentState |
|
|
@ -22,21 +23,39 @@ export class GitLineTracker extends LineTracker { |
|
|
|
this.reset(); |
|
|
|
|
|
|
|
let updated = false; |
|
|
|
if (!this._suspended && !e.pending && e.lines !== undefined && e.editor !== undefined) { |
|
|
|
if (!this.suspended && !e.pending && e.lines !== undefined && e.editor !== undefined) { |
|
|
|
updated = await this.updateState(e.lines, e.editor); |
|
|
|
} |
|
|
|
|
|
|
|
return super.fireLinesChanged(updated ? e : { ...e, lines: undefined }); |
|
|
|
} |
|
|
|
|
|
|
|
private _subscriptionOnlyWhenActive: Disposable | undefined; |
|
|
|
|
|
|
|
protected onStart(): Disposable | undefined { |
|
|
|
this.onResume(); |
|
|
|
|
|
|
|
return Disposable.from( |
|
|
|
{ dispose: () => this.onSuspend() }, |
|
|
|
Container.tracker.onDidChangeBlameState(this.onBlameStateChanged, this), |
|
|
|
Container.tracker.onDidChangeDirtyState(this.onDirtyStateChanged, this), |
|
|
|
Container.tracker.onDidTriggerDirtyIdle(this.onDirtyIdleTriggered, this) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
protected onResume(): void { |
|
|
|
if (this._subscriptionOnlyWhenActive === undefined) { |
|
|
|
this._subscriptionOnlyWhenActive = Container.tracker.onDidChangeContent(this.onContentChanged, this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected onSuspend(): void { |
|
|
|
if (this._subscriptionOnlyWhenActive === undefined) return; |
|
|
|
|
|
|
|
this._subscriptionOnlyWhenActive.dispose(); |
|
|
|
this._subscriptionOnlyWhenActive = undefined; |
|
|
|
} |
|
|
|
|
|
|
|
@debug({ |
|
|
|
args: { |
|
|
|
0: (e: DocumentBlameStateChangeEvent<GitDocumentState>) => |
|
|
@ -51,6 +70,18 @@ export class GitLineTracker extends LineTracker { |
|
|
|
|
|
|
|
@debug({ |
|
|
|
args: { |
|
|
|
0: (e: DocumentContentChangeEvent<GitDocumentState>) => |
|
|
|
`editor=${e.editor.document.uri.toString(true)}, doc=${e.document.uri.toString(true)}` |
|
|
|
} |
|
|
|
}) |
|
|
|
private onContentChanged(e: DocumentContentChangeEvent<GitDocumentState>) { |
|
|
|
if (e.contentChanges.some(cc => this.lines?.some(l => cc.range.start.line <= l && cc.range.end.line >= l))) { |
|
|
|
this.trigger('editor'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@debug({ |
|
|
|
args: { |
|
|
|
0: (e: DocumentDirtyIdleTriggerEvent<GitDocumentState>) => |
|
|
|
`editor=${e.editor.document.uri.toString(true)}, doc=${e.document.uri.toString(true)}` |
|
|
|
} |
|
|
@ -76,24 +107,6 @@ export class GitLineTracker extends LineTracker { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private _suspended = false; |
|
|
|
|
|
|
|
@debug() |
|
|
|
private resume(options: { force?: boolean } = {}) { |
|
|
|
if (!options.force && !this._suspended) return; |
|
|
|
|
|
|
|
this._suspended = false; |
|
|
|
this.trigger('editor'); |
|
|
|
} |
|
|
|
|
|
|
|
@debug() |
|
|
|
private suspend(options: { force?: boolean } = {}) { |
|
|
|
if (!options.force && this._suspended) return; |
|
|
|
|
|
|
|
this._suspended = true; |
|
|
|
this.trigger('editor'); |
|
|
|
} |
|
|
|
|
|
|
|
private async updateState(lines: number[], editor: TextEditor): Promise<boolean> { |
|
|
|
const trackedDocument = await Container.tracker.getOrAdd(editor.document); |
|
|
|
if (!trackedDocument.isBlameable || !this.includesAll(lines)) return false; |
|
|
|