Adopt prefix private with _ in markdown extension (#165088)

This commit is contained in:
Matt Bierner
2022-10-31 14:22:39 -07:00
committed by GitHub
parent b97827dacf
commit 33867c55f3
29 changed files with 374 additions and 355 deletions

View File

@@ -10,55 +10,55 @@ export interface ITask<T> {
export class Delayer<T> {
public defaultDelay: number;
private timeout: any; // Timer
private completionPromise: Promise<T | null> | null;
private onSuccess: ((value: T | PromiseLike<T> | undefined) => void) | null;
private task: ITask<T> | null;
private _timeout: any; // Timer
private _cancelTimeout: Promise<T | null> | null;
private _onSuccess: ((value: T | PromiseLike<T> | undefined) => void) | null;
private _task: ITask<T> | null;
constructor(defaultDelay: number) {
this.defaultDelay = defaultDelay;
this.timeout = null;
this.completionPromise = null;
this.onSuccess = null;
this.task = null;
this._timeout = null;
this._cancelTimeout = null;
this._onSuccess = null;
this._task = null;
}
dispose() {
this.cancelTimeout();
this._doCancelTimeout();
}
public trigger(task: ITask<T>, delay: number = this.defaultDelay): Promise<T | null> {
this.task = task;
this._task = task;
if (delay >= 0) {
this.cancelTimeout();
this._doCancelTimeout();
}
if (!this.completionPromise) {
this.completionPromise = new Promise<T | undefined>((resolve) => {
this.onSuccess = resolve;
if (!this._cancelTimeout) {
this._cancelTimeout = new Promise<T | undefined>((resolve) => {
this._onSuccess = resolve;
}).then(() => {
this.completionPromise = null;
this.onSuccess = null;
const result = this.task && this.task();
this.task = null;
this._cancelTimeout = null;
this._onSuccess = null;
const result = this._task && this._task?.();
this._task = null;
return result;
});
}
if (delay >= 0 || this.timeout === null) {
this.timeout = setTimeout(() => {
this.timeout = null;
this.onSuccess?.(undefined);
if (delay >= 0 || this._timeout === null) {
this._timeout = setTimeout(() => {
this._timeout = null;
this._onSuccess?.(undefined);
}, delay >= 0 ? delay : this.defaultDelay);
}
return this.completionPromise;
return this._cancelTimeout;
}
private cancelTimeout(): void {
if (this.timeout !== null) {
clearTimeout(this.timeout);
this.timeout = null;
private _doCancelTimeout(): void {
if (this._timeout !== null) {
clearTimeout(this._timeout);
this._timeout = null;
}
}
}

View File

@@ -5,8 +5,8 @@
import * as vscode from 'vscode';
export const noopToken = new class implements vscode.CancellationToken {
_onCancellationRequestedEmitter = new vscode.EventEmitter<void>();
export const noopToken: vscode.CancellationToken = new class implements vscode.CancellationToken {
private readonly _onCancellationRequestedEmitter = new vscode.EventEmitter<void>();
onCancellationRequested = this._onCancellationRequestedEmitter.event;
get isCancellationRequested() { return false; }

View File

@@ -15,15 +15,15 @@ enum OpenMarkdownLinks {
export class MdLinkOpener {
constructor(
private readonly client: MdLanguageClient,
private readonly _client: MdLanguageClient,
) { }
public async resolveDocumentLink(linkText: string, fromResource: vscode.Uri): Promise<proto.ResolvedDocumentLinkTarget> {
return this.client.resolveLinkTarget(linkText, fromResource);
return this._client.resolveLinkTarget(linkText, fromResource);
}
public async openDocumentLink(linkText: string, fromResource: vscode.Uri, viewColumn?: vscode.ViewColumn): Promise<void> {
const resolved = await this.client.resolveLinkTarget(linkText, fromResource);
const resolved = await this._client.resolveLinkTarget(linkText, fromResource);
if (!resolved) {
return;
}

View File

@@ -11,53 +11,53 @@ const defaultResourceToKey = (resource: vscode.Uri): string => resource.toString
export class ResourceMap<T> {
private readonly map = new Map<string, { readonly uri: vscode.Uri; readonly value: T }>();
private readonly _map = new Map<string, { readonly uri: vscode.Uri; readonly value: T }>();
private readonly toKey: ResourceToKey;
private readonly _toKey: ResourceToKey;
constructor(toKey: ResourceToKey = defaultResourceToKey) {
this.toKey = toKey;
this._toKey = toKey;
}
public set(uri: vscode.Uri, value: T): this {
this.map.set(this.toKey(uri), { uri, value });
this._map.set(this._toKey(uri), { uri, value });
return this;
}
public get(resource: vscode.Uri): T | undefined {
return this.map.get(this.toKey(resource))?.value;
return this._map.get(this._toKey(resource))?.value;
}
public has(resource: vscode.Uri): boolean {
return this.map.has(this.toKey(resource));
return this._map.has(this._toKey(resource));
}
public get size(): number {
return this.map.size;
return this._map.size;
}
public clear(): void {
this.map.clear();
this._map.clear();
}
public delete(resource: vscode.Uri): boolean {
return this.map.delete(this.toKey(resource));
return this._map.delete(this._toKey(resource));
}
public *values(): IterableIterator<T> {
for (const entry of this.map.values()) {
for (const entry of this._map.values()) {
yield entry.value;
}
}
public *keys(): IterableIterator<vscode.Uri> {
for (const entry of this.map.values()) {
for (const entry of this._map.values()) {
yield entry.uri;
}
}
public *entries(): IterableIterator<[vscode.Uri, T]> {
for (const entry of this.map.values()) {
for (const entry of this._map.values()) {
yield [entry.uri, entry.value];
}
}