Merge pull request #5404 from Tyriar/tyriar/1de3_timeout_cleanup

Replace timeout handling with disposableTimeout
This commit is contained in:
Daniel Imms
2025-09-17 15:12:00 -07:00
committed by GitHub
7 changed files with 13 additions and 36 deletions
+1 -2
View File
@@ -12,8 +12,7 @@
"removeComments": true,
"strict": true,
"types": [
"../../../node_modules/@types/mocha",
"../../../src/vs/typings/thenable"
"../../../node_modules/@types/mocha"
],
"paths": {
"browser/*": [
+5 -10
View File
@@ -7,6 +7,7 @@ import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/
import type { SearchAddon as ISearchApi, ISearchOptions, ISearchDecorationOptions } from '@xterm/addon-search';
import { Emitter, Event } from 'vs/base/common/event';
import { Disposable, dispose, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { disposableTimeout } from 'vs/base/common/async';
import { SearchLineCache } from './SearchLineCache';
interface IInternalSearchOptions {
@@ -34,8 +35,6 @@ export interface ISearchResult {
size: number;
}
interface IHighlight extends IDisposable {
decoration: IDecoration;
match: ISearchResult;
@@ -57,8 +56,6 @@ const enum Constants {
*/
NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\\;:"\',./<>?',
/**
* Default maximum number of search results to highlight simultaneously. This limit prevents
* performance degradation when searching for very common terms that would result in excessive
@@ -73,10 +70,10 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp
private _highlightedLines: Set<number> = new Set();
private _highlightDecorations: IHighlight[] = [];
private _searchResultsWithHighlight: ISearchResult[] = [];
private _selectedDecoration: MutableDisposable<IMultiHighlight> = this._register(new MutableDisposable());
private _selectedDecoration = this._register(new MutableDisposable<IMultiHighlight>());
private _highlightLimit: number;
private _lastSearchOptions: ISearchOptions | undefined;
private _highlightTimeout: number | undefined;
private _highlightTimeout = this._register(new MutableDisposable<IDisposable>());
private _lineCache = this._register(new MutableDisposable<SearchLineCache>());
private readonly _onDidChangeResults = this._register(new Emitter<ISearchResultChangeEvent>());
@@ -97,11 +94,9 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp
}
private _updateMatches(): void {
if (this._highlightTimeout) {
window.clearTimeout(this._highlightTimeout);
}
this._highlightTimeout.clear();
if (this._cachedSearchTerm && this._lastSearchOptions?.decorations) {
this._highlightTimeout = setTimeout(() => {
this._highlightTimeout.value = disposableTimeout(() => {
const term = this._cachedSearchTerm;
this._cachedSearchTerm = undefined;
this.findPrevious(term!, { ...this._lastSearchOptions, incremental: true }, { noScroll: true });
+4 -7
View File
@@ -5,6 +5,7 @@
import type { Terminal } from '@xterm/xterm';
import { combinedDisposable, Disposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { disposableTimeout } from 'vs/base/common/async';
export type LineCacheEntry = [
/**
@@ -35,7 +36,7 @@ export class SearchLineCache extends Disposable {
* _linesCache is also invalidated when the terminal cursor moves.
*/
private _linesCache: LineCacheEntry[] | undefined;
private _linesCacheTimeoutId = 0;
private _linesCacheTimeout = this._register(new MutableDisposable());
private _linesCacheDisposables = this._register(new MutableDisposable());
constructor(private _terminal: Terminal) {
@@ -56,17 +57,13 @@ export class SearchLineCache extends Disposable {
);
}
window.clearTimeout(this._linesCacheTimeoutId);
this._linesCacheTimeoutId = window.setTimeout(() => this._destroyLinesCache(), Constants.LINES_CACHE_TIME_TO_LIVE);
this._linesCacheTimeout.value = disposableTimeout(() => this._destroyLinesCache(), Constants.LINES_CACHE_TIME_TO_LIVE);
}
private _destroyLinesCache(): void {
this._linesCache = undefined;
this._linesCacheDisposables.clear();
if (this._linesCacheTimeoutId) {
window.clearTimeout(this._linesCacheTimeoutId);
this._linesCacheTimeoutId = 0;
}
this._linesCacheTimeout.clear();
}
public getLineFromCache(row: number): LineCacheEntry | undefined {
+1 -2
View File
@@ -29,8 +29,7 @@
"downlevelIteration": true,
"experimentalDecorators": true,
"types": [
"../../../node_modules/@types/mocha",
"../../../src/vs/typings/thenable"
"../../../node_modules/@types/mocha"
]
},
"include": [
+1 -2
View File
@@ -7,8 +7,7 @@
],
"outDir": "../../out",
"types": [
"../../node_modules/@types/mocha",
"../vs/typings/thenable.d.ts"
"../../node_modules/@types/mocha"
],
"baseUrl": "..",
"paths": {
+1 -1
View File
@@ -124,7 +124,7 @@ export function raceTimeout<T>(promise: Promise<T>, timeout: number, onTimeout?:
]);
}
export function asPromise<T>(callback: () => T | Thenable<T>): Promise<T> {
export function asPromise<T>(callback: () => T | PromiseLike<T>): Promise<T> {
return new Promise<T>((resolve, reject) => {
const item = callback();
if (isThenable<T>(item)) {
-12
View File
@@ -1,12 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
* Thenable is a common denominator between ES6 promises, Q, jquery.Deferred, WinJS.Promise,
* and others. This API makes no assumption about what promise library is being used which
* enables reusing existing code without migrating to a specific promise implementation. Still,
* we recommend the use of native promises which are available in VS Code.
*/
interface Thenable<T> extends PromiseLike<T> { }