瀏覽代碼

Updates line tracker naming for clarity

main
Eric Amodio 2 年之前
父節點
當前提交
9d130ffada
共有 5 個檔案被更改,包括 41 行新增38 行删除
  1. +4
    -4
      src/annotations/lineAnnotationController.ts
  2. +3
    -3
      src/hovers/lineHoverController.ts
  3. +3
    -3
      src/statusbar/statusBarController.ts
  4. +29
    -26
      src/trackers/lineTracker.ts
  5. +2
    -2
      src/views/nodes/lineHistoryTrackerNode.ts

+ 4
- 4
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(

+ 3
- 3
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();
}
}

+ 3
- 3
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;

+ 29
- 26
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<any, Disposable[]>();
private _subscriptions = new Map<unknown, Disposable[]>();
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 });
}

+ 2
- 2
src/views/nodes/lineHistoryTrackerNode.ts 查看文件

@ -218,11 +218,11 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
@debug()
protected subscribe() {
if (this.view.container.lineTracker.isSubscribed(this)) return undefined;
if (this.view.container.lineTracker.subscribed(this)) return undefined;
const onActiveLinesChanged = Functions.debounce(this.onActiveLinesChanged.bind(this), 250);
return this.view.container.lineTracker.start(
return this.view.container.lineTracker.subscribe(
this,
this.view.container.lineTracker.onDidChangeActiveLines((e: LinesChangeEvent) => {
if (e.pending) return;

Loading…
取消
儲存