-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a disposable base class Fixes #6285 * PR feedback
- Loading branch information
Showing
72 changed files
with
1,078 additions
and
1,160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
|
||
export function toDisposable(d: () => void): vscode.Disposable { | ||
return { dispose: d }; | ||
} | ||
|
||
export function combinedDisposable(disposables: vscode.Disposable[]): vscode.Disposable { | ||
return toDisposable(() => disposeAll(disposables)); | ||
} | ||
|
||
export function disposeAll(disposables: vscode.Disposable[]) { | ||
while (disposables.length) { | ||
const item = disposables.pop(); | ||
item?.dispose(); | ||
} | ||
} | ||
|
||
export abstract class Disposable { | ||
protected _isDisposed = false; | ||
|
||
private _disposables: vscode.Disposable[] = []; | ||
|
||
public dispose(): any { | ||
if (this._isDisposed) { | ||
return; | ||
} | ||
this._isDisposed = true; | ||
disposeAll(this._disposables); | ||
this._disposables = []; | ||
} | ||
|
||
protected _register<T extends vscode.Disposable>(value: T): T { | ||
if (this._isDisposed) { | ||
value.dispose(); | ||
} else { | ||
this._disposables.push(value); | ||
} | ||
return value; | ||
} | ||
|
||
protected get isDisposed() { | ||
return this._isDisposed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.