Skip to content

Commit b12a939

Browse files
authored
Merge pull request #5404 from Tyriar/tyriar/1de3_timeout_cleanup
Replace timeout handling with disposableTimeout
2 parents 15d9082 + c27af4f commit b12a939

File tree

7 files changed

+13
-36
lines changed

7 files changed

+13
-36
lines changed

addons/addon-progress/src/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"removeComments": true,
1313
"strict": true,
1414
"types": [
15-
"../../../node_modules/@types/mocha",
16-
"../../../src/vs/typings/thenable"
15+
"../../../node_modules/@types/mocha"
1716
],
1817
"paths": {
1918
"browser/*": [

addons/addon-search/src/SearchAddon.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/
77
import type { SearchAddon as ISearchApi, ISearchOptions, ISearchDecorationOptions } from '@xterm/addon-search';
88
import { Emitter, Event } from 'vs/base/common/event';
99
import { Disposable, dispose, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
10+
import { disposableTimeout } from 'vs/base/common/async';
1011
import { SearchLineCache } from './SearchLineCache';
1112

1213
interface IInternalSearchOptions {
@@ -34,8 +35,6 @@ export interface ISearchResult {
3435
size: number;
3536
}
3637

37-
38-
3938
interface IHighlight extends IDisposable {
4039
decoration: IDecoration;
4140
match: ISearchResult;
@@ -57,8 +56,6 @@ const enum Constants {
5756
*/
5857
NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\\;:"\',./<>?',
5958

60-
61-
6259
/**
6360
* Default maximum number of search results to highlight simultaneously. This limit prevents
6461
* 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
7370
private _highlightedLines: Set<number> = new Set();
7471
private _highlightDecorations: IHighlight[] = [];
7572
private _searchResultsWithHighlight: ISearchResult[] = [];
76-
private _selectedDecoration: MutableDisposable<IMultiHighlight> = this._register(new MutableDisposable());
73+
private _selectedDecoration = this._register(new MutableDisposable<IMultiHighlight>());
7774
private _highlightLimit: number;
7875
private _lastSearchOptions: ISearchOptions | undefined;
79-
private _highlightTimeout: number | undefined;
76+
private _highlightTimeout = this._register(new MutableDisposable<IDisposable>());
8077
private _lineCache = this._register(new MutableDisposable<SearchLineCache>());
8178

8279
private readonly _onDidChangeResults = this._register(new Emitter<ISearchResultChangeEvent>());
@@ -97,11 +94,9 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp
9794
}
9895

9996
private _updateMatches(): void {
100-
if (this._highlightTimeout) {
101-
window.clearTimeout(this._highlightTimeout);
102-
}
97+
this._highlightTimeout.clear();
10398
if (this._cachedSearchTerm && this._lastSearchOptions?.decorations) {
104-
this._highlightTimeout = setTimeout(() => {
99+
this._highlightTimeout.value = disposableTimeout(() => {
105100
const term = this._cachedSearchTerm;
106101
this._cachedSearchTerm = undefined;
107102
this.findPrevious(term!, { ...this._lastSearchOptions, incremental: true }, { noScroll: true });

addons/addon-search/src/SearchLineCache.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import type { Terminal } from '@xterm/xterm';
77
import { combinedDisposable, Disposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
8+
import { disposableTimeout } from 'vs/base/common/async';
89

910
export type LineCacheEntry = [
1011
/**
@@ -35,7 +36,7 @@ export class SearchLineCache extends Disposable {
3536
* _linesCache is also invalidated when the terminal cursor moves.
3637
*/
3738
private _linesCache: LineCacheEntry[] | undefined;
38-
private _linesCacheTimeoutId = 0;
39+
private _linesCacheTimeout = this._register(new MutableDisposable());
3940
private _linesCacheDisposables = this._register(new MutableDisposable());
4041

4142
constructor(private _terminal: Terminal) {
@@ -56,17 +57,13 @@ export class SearchLineCache extends Disposable {
5657
);
5758
}
5859

59-
window.clearTimeout(this._linesCacheTimeoutId);
60-
this._linesCacheTimeoutId = window.setTimeout(() => this._destroyLinesCache(), Constants.LINES_CACHE_TIME_TO_LIVE);
60+
this._linesCacheTimeout.value = disposableTimeout(() => this._destroyLinesCache(), Constants.LINES_CACHE_TIME_TO_LIVE);
6161
}
6262

6363
private _destroyLinesCache(): void {
6464
this._linesCache = undefined;
6565
this._linesCacheDisposables.clear();
66-
if (this._linesCacheTimeoutId) {
67-
window.clearTimeout(this._linesCacheTimeoutId);
68-
this._linesCacheTimeoutId = 0;
69-
}
66+
this._linesCacheTimeout.clear();
7067
}
7168

7269
public getLineFromCache(row: number): LineCacheEntry | undefined {

addons/addon-webgl/src/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"downlevelIteration": true,
3030
"experimentalDecorators": true,
3131
"types": [
32-
"../../../node_modules/@types/mocha",
33-
"../../../src/vs/typings/thenable"
32+
"../../../node_modules/@types/mocha"
3433
]
3534
},
3635
"include": [

src/browser/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
],
88
"outDir": "../../out",
99
"types": [
10-
"../../node_modules/@types/mocha",
11-
"../vs/typings/thenable.d.ts"
10+
"../../node_modules/@types/mocha"
1211
],
1312
"baseUrl": "..",
1413
"paths": {

src/vs/base/common/async.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function raceTimeout<T>(promise: Promise<T>, timeout: number, onTimeout?:
124124
]);
125125
}
126126

127-
export function asPromise<T>(callback: () => T | Thenable<T>): Promise<T> {
127+
export function asPromise<T>(callback: () => T | PromiseLike<T>): Promise<T> {
128128
return new Promise<T>((resolve, reject) => {
129129
const item = callback();
130130
if (isThenable<T>(item)) {

src/vs/typings/thenable.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)