Ver código fonte

Avoids any usage for setTimeout/setInterval

main
Eric Amodio 2 anos atrás
pai
commit
df7dd9f4ab
6 arquivos alterados com 28 adições e 19 exclusões
  1. +1
    -1
      src/commands/closeUnchangedFiles.ts
  2. +9
    -3
      src/partners.ts
  3. +5
    -2
      src/statusbar/statusBarController.ts
  4. +8
    -8
      src/system/function.ts
  5. +4
    -4
      src/system/promise.ts
  6. +1
    -1
      src/trackers/documentTracker.ts

+ 1
- 1
src/commands/closeUnchangedFiles.ts Ver arquivo

@ -130,7 +130,7 @@ export class CloseUnchangedFilesCommand extends Command {
private waitForEditorChange(timeout: number = 500): Promise<TextEditor | undefined> {
return new Promise<TextEditor | undefined>(resolve => {
let timer: any | undefined;
let timer: ReturnTypean><typeof setTimeout> | undefined;
this._onEditorChangedFn = (editor: TextEditor | undefined) => {
if (timer != null) {

+ 9
- 3
src/partners.ts Ver arquivo

@ -12,12 +12,15 @@ export async function installExtension(
vsix?: Uri,
): Promise<Extension<T> | undefined> {
try {
let timer: any = 0;
let timer: ReturnType<typeof setTimeout> | undefined = undefined;
const extension = new Promise<Extension<any> | undefined>(resolve => {
const disposable = extensions.onDidChange(() => {
const extension = extensions.getExtension(extensionId);
if (extension != null) {
clearTimeout(timer);
if (timer != null) {
clearTimeout(timer);
timer = undefined;
}
disposable.dispose();
resolve(extension);
@ -33,7 +36,10 @@ export async function installExtension(
await commands.executeCommand(BuiltInCommands.InstallExtension, vsix ?? extensionId);
// Wait for extension activation until timeout expires
timer = setTimeout(() => tokenSource.cancel(), timeout);
timer = setTimeout(() => {
timer = undefined;
tokenSource.cancel();
}, timeout);
return extension;
} catch {

+ 5
- 2
src/statusbar/statusBarController.ts Ver arquivo

@ -25,7 +25,7 @@ import { LinesChangeEvent } from '../trackers/gitLineTracker';
export class StatusBarController implements Disposable {
private _pullRequestCancellation: CancellationTokenSource | undefined;
private _tooltipCancellation: CancellationTokenSource | undefined;
private _tooltipDelayTimer: any | undefined;
private _tooltipDelayTimer: ReturnTypean><typeof setTimeout> | undefined;
private readonly _disposable: Disposable;
private _statusBarBlame: StatusBarItem | undefined;
@ -305,10 +305,13 @@ export class StatusBarController implements Disposable {
this._statusBarBlame.tooltip = tooltip;
clearTimeout(this._tooltipDelayTimer);
if (this._tooltipDelayTimer != null) {
clearTimeout(this._tooltipDelayTimer);
}
this._tooltipCancellation?.cancel();
this._tooltipDelayTimer = setTimeout(() => {
this._tooltipDelayTimer = undefined;
this._tooltipCancellation = new CancellationTokenSource();
void this.updateCommitTooltip(

+ 8
- 8
src/system/function.ts Ver arquivo

@ -152,26 +152,26 @@ export function propOf>(o: T, key: K) {
}
export function interval(fn: (...args: any[]) => void, ms: number): Disposable {
let timer: any | undefined;
let timer: ReturnTypean><typeof setInterval> | undefined;
const disposable = {
dispose: () => {
if (timer !== undefined) {
if (timer != null) {
clearInterval(timer);
timer = undefined;
}
},
};
timer = globalThis.setInterval(fn, ms);
timer = setInterval(fn, ms);
return disposable;
}
export function progress<T>(promise: Promise<T>, intervalMs: number, onProgress: () => boolean): Promise<T> {
return new Promise((resolve, reject) => {
let timer: any | undefined;
timer = globalThis.setInterval(() => {
let timer: ReturnTypean><typeof setInterval> | undefined;
timer = setInterval(() => {
if (onProgress()) {
if (timer !== undefined) {
if (timer != null) {
clearInterval(timer);
timer = undefined;
}
@ -180,7 +180,7 @@ export function progress(promise: Promise, intervalMs: number, onProgress:
promise.then(
() => {
if (timer !== undefined) {
if (timer != null) {
clearInterval(timer);
timer = undefined;
}
@ -188,7 +188,7 @@ export function progress(promise: Promise, intervalMs: number, onProgress:
resolve(promise);
},
ex => {
if (timer !== undefined) {
if (timer != null) {
clearInterval(timer);
timer = undefined;
}

+ 4
- 4
src/system/promise.ts Ver arquivo

@ -28,9 +28,9 @@ export function cancellable(
return new Promise((resolve, reject) => {
let fulfilled = false;
let timer: any | undefined;
let timer: ReturnTypean><typeof setTimeout> | undefined;
if (typeof timeoutOrToken === 'number') {
timer = globalThis.setTimeout(() => {
timer = setTimeout(() => {
if (typeof options.onDidCancel === 'function') {
options.onDidCancel(resolve, reject);
} else {
@ -52,14 +52,14 @@ export function cancellable(
promise.then(
() => {
fulfilled = true;
if (timer !== undefined) {
if (timer != null) {
clearTimeout(timer);
}
resolve(promise);
},
ex => {
fulfilled = true;
if (timer !== undefined) {
if (timer != null) {
clearTimeout(timer);
}
reject(ex);

+ 1
- 1
src/trackers/documentTracker.ts Ver arquivo

@ -96,7 +96,7 @@ export class DocumentTracker implements Disposable {
this.onActiveTextEditorChanged(window.activeTextEditor);
}
private _timer: any | undefined;
private _timer: ReturnTypean><typeof setTimeout> | undefined;
private onActiveTextEditorChanged(editor: TextEditor | undefined) {
if (editor != null && !isTextEditor(editor)) return;

Carregando…
Cancelar
Salvar