From 9d130ffada20df648ef5dc73d76dc79aa8d3794a Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 22 Jan 2022 01:24:22 -0500 Subject: [PATCH] Updates line tracker naming for clarity --- src/annotations/lineAnnotationController.ts | 8 ++--- src/hovers/lineHoverController.ts | 6 ++-- src/statusbar/statusBarController.ts | 6 ++-- src/trackers/lineTracker.ts | 55 +++++++++++++++-------------- src/views/nodes/lineHistoryTrackerNode.ts | 4 +-- 5 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/annotations/lineAnnotationController.ts b/src/annotations/lineAnnotationController.ts index 9ec4597..1fc8dd3 100644 --- a/src/annotations/lineAnnotationController.ts +++ b/src/annotations/lineAnnotationController.ts @@ -48,7 +48,7 @@ export class LineAnnotationController implements Disposable { dispose() { this.clearAnnotations(this._editor); - this.container.lineTracker.stop(this); + this.container.lineTracker.unsubscribe(this); this._disposable.dispose(); } @@ -318,8 +318,8 @@ export class LineAnnotationController implements Disposable { private setLineTracker(enabled: boolean) { if (enabled) { - if (!this.container.lineTracker.isSubscribed(this)) { - this.container.lineTracker.start( + if (!this.container.lineTracker.subscribed(this)) { + this.container.lineTracker.subscribe( this, this.container.lineTracker.onDidChangeActiveLines(this.onActiveLinesChanged, this), ); @@ -328,7 +328,7 @@ export class LineAnnotationController implements Disposable { return; } - this.container.lineTracker.stop(this); + this.container.lineTracker.unsubscribe(this); } private async waitForAnyPendingPullRequests( diff --git a/src/hovers/lineHoverController.ts b/src/hovers/lineHoverController.ts index a25ecfb..18067fe 100644 --- a/src/hovers/lineHoverController.ts +++ b/src/hovers/lineHoverController.ts @@ -35,7 +35,7 @@ export class LineHoverController implements Disposable { dispose() { this.unregister(); - this.container.lineTracker.stop(this); + this.container.lineTracker.unsubscribe(this); this._disposable.dispose(); } @@ -49,14 +49,14 @@ export class LineHoverController implements Disposable { } if (this.container.config.hovers.enabled && this.container.config.hovers.currentLine.enabled) { - this.container.lineTracker.start( + this.container.lineTracker.subscribe( this, this.container.lineTracker.onDidChangeActiveLines(this.onActiveLinesChanged, this), ); this.register(window.activeTextEditor); } else { - this.container.lineTracker.stop(this); + this.container.lineTracker.unsubscribe(this); this.unregister(); } } diff --git a/src/statusbar/statusBarController.ts b/src/statusbar/statusBarController.ts index cee920c..1544720 100644 --- a/src/statusbar/statusBarController.ts +++ b/src/statusbar/statusBarController.ts @@ -44,7 +44,7 @@ export class StatusBarController implements Disposable { this._statusBarBlame?.dispose(); this._statusBarMode?.dispose(); - this.container.lineTracker.stop(this); + this.container.lineTracker.unsubscribe(this); this._disposable.dispose(); } @@ -118,13 +118,13 @@ export class StatusBarController implements Disposable { this._statusBarBlame.command = this.container.config.statusBar.command; if (configuration.changed(e, 'statusBar.enabled')) { - this.container.lineTracker.start( + this.container.lineTracker.subscribe( this, this.container.lineTracker.onDidChangeActiveLines(this.onActiveLinesChanged, this), ); } } else if (configuration.changed(e, 'statusBar.enabled')) { - this.container.lineTracker.stop(this); + this.container.lineTracker.unsubscribe(this); this._statusBarBlame?.dispose(); this._statusBarBlame = undefined; diff --git a/src/trackers/lineTracker.ts b/src/trackers/lineTracker.ts index 90cd121..db8ffaa 100644 --- a/src/trackers/lineTracker.ts +++ b/src/trackers/lineTracker.ts @@ -1,6 +1,7 @@ 'use strict'; import { Disposable, Event, EventEmitter, Selection, TextEditor, TextEditorSelectionChangeEvent, window } from 'vscode'; import { isTextEditor } from '../constants'; +import { Logger } from '../logger'; import { debug, Functions } from '../system'; export interface LinesChangeEvent { @@ -29,13 +30,13 @@ export class LineTracker implements Disposable { dispose() { for (const subscriber of this._subscriptions.keys()) { - this.stop(subscriber); + this.unsubscribe(subscriber); } } private onActiveTextEditorChanged(editor: TextEditor | undefined) { - if (this._editor === editor) return; - if (editor !== undefined && !isTextEditor(editor)) return; + if (editor === this._editor) return; + if (editor != null && !isTextEditor(editor)) return; this.reset(); this._editor = editor; @@ -74,7 +75,7 @@ export class LineTracker implements Disposable { includes(selections: LineSelection[]): boolean; includes(line: number, options?: { activeOnly: boolean }): boolean; includes(lineOrSelections: number | LineSelection[], options?: { activeOnly: boolean }): boolean { - if (Array.isArray(lineOrSelections)) { + if (typeof lineOrSelections !== 'number') { return LineTracker.includes(lineOrSelections, this._selections); } @@ -104,24 +105,26 @@ export class LineTracker implements Disposable { this._state.clear(); } - private _subscriptions = new Map(); + private _subscriptions = new Map(); - isSubscribed(subscriber: any) { + subscribed(subscriber: unknown) { return this._subscriptions.has(subscriber); } protected onStart?(): Disposable | undefined; @debug({ args: false }) - start(subscriber: any, subscription: Disposable): Disposable { + subscribe(subscriber: unknown, subscription: Disposable): Disposable { + const cc = Logger.getCorrelationContext(); + const disposable = { - dispose: () => this.stop(subscriber), + dispose: () => this.unsubscribe(subscriber), }; const first = this._subscriptions.size === 0; let subs = this._subscriptions.get(subscriber); - if (subs === undefined) { + if (subs == null) { subs = [subscription]; this._subscriptions.set(subscriber, subs); } else { @@ -129,6 +132,8 @@ export class LineTracker implements Disposable { } if (first) { + Logger.debug(cc, 'Starting line tracker...'); + this._disposable = Disposable.from( window.onDidChangeActiveTextEditor(Functions.debounce(this.onActiveTextEditorChanged, 0), this), window.onDidChangeTextEditorSelection(this.onTextEditorSelectionChanged, this), @@ -142,9 +147,9 @@ export class LineTracker implements Disposable { } @debug({ args: false }) - stop(subscriber: any) { + unsubscribe(subscriber: unknown) { const subs = this._subscriptions.get(subscriber); - if (subs === undefined) return; + if (subs == null) return; this._subscriptions.delete(subscriber); for (const sub of subs) { @@ -153,14 +158,12 @@ export class LineTracker implements Disposable { if (this._subscriptions.size !== 0) return; - if (this._linesChangedDebounced !== undefined) { + if (this._linesChangedDebounced != null) { this._linesChangedDebounced.cancel(); } - if (this._disposable !== undefined) { - this._disposable.dispose(); - this._disposable = undefined; - } + this._disposable?.dispose(); + this._disposable = undefined; } private _suspended = false; @@ -171,8 +174,8 @@ export class LineTracker implements Disposable { protected onResume?(): void; @debug() - resume(options: { force?: boolean } = {}) { - if (!options.force && !this._suspended) return; + resume(options?: { force?: boolean }) { + if (!options?.force && !this._suspended) return; this._suspended = false; void this.onResume?.(); @@ -182,8 +185,8 @@ export class LineTracker implements Disposable { protected onSuspend?(): void; @debug() - suspend(options: { force?: boolean } = {}) { - if (!options.force && this._suspended) return; + suspend(options?: { force?: boolean }) { + if (!options?.force && this._suspended) return; this._suspended = true; void this.onSuspend?.(); @@ -201,11 +204,11 @@ export class LineTracker implements Disposable { private _linesChangedDebounced: Functions.Deferrable<(e: LinesChangeEvent) => void> | undefined; private onLinesChanged(e: LinesChangeEvent) { - if (e.selections === undefined) { + if (e.selections == null) { queueMicrotask(() => { - if (window.activeTextEditor !== e.editor) return; + if (e.editor !== window.activeTextEditor) return; - if (this._linesChangedDebounced !== undefined) { + if (this._linesChangedDebounced != null) { this._linesChangedDebounced.cancel(); } @@ -215,10 +218,10 @@ export class LineTracker implements Disposable { return; } - if (this._linesChangedDebounced === undefined) { + if (this._linesChangedDebounced == null) { this._linesChangedDebounced = Functions.debounce( (e: LinesChangeEvent) => { - if (window.activeTextEditor !== e.editor) return; + if (e.editor !== window.activeTextEditor) return; // Make sure we are still on the same lines if (!LineTracker.includes(e.selections, LineTracker.toLineSelections(e.editor?.selections))) { return; @@ -232,7 +235,7 @@ export class LineTracker implements Disposable { } // If we have no pending moves, then fire an immediate pending event, and defer the real event - if (!this._linesChangedDebounced.pending!()) { + if (!this._linesChangedDebounced.pending?.()) { void this.fireLinesChanged({ ...e, pending: true }); } diff --git a/src/views/nodes/lineHistoryTrackerNode.ts b/src/views/nodes/lineHistoryTrackerNode.ts index e7647dc..743c138 100644 --- a/src/views/nodes/lineHistoryTrackerNode.ts +++ b/src/views/nodes/lineHistoryTrackerNode.ts @@ -218,11 +218,11 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode { if (e.pending) return;