mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 04:09:28 +00:00
Extend disposable in more places
This commit is contained in:
@@ -9,6 +9,7 @@ import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import API from '../utils/api';
|
||||
import { isTypeScriptDocument } from '../utils/languageModeIds';
|
||||
import { ResourceMap } from '../utils/resourceMap';
|
||||
import { Disposable } from '../utils/dispose';
|
||||
|
||||
|
||||
function objsAreEqual<T>(a: T, b: T): boolean {
|
||||
@@ -33,27 +34,20 @@ function areFileConfigurationsEqual(a: FileConfiguration, b: FileConfiguration):
|
||||
);
|
||||
}
|
||||
|
||||
export default class FileConfigurationManager {
|
||||
private onDidCloseTextDocumentSub: vscode.Disposable | undefined;
|
||||
export default class FileConfigurationManager extends Disposable {
|
||||
private readonly formatOptions = new ResourceMap<Promise<FileConfiguration | undefined>>();
|
||||
|
||||
public constructor(
|
||||
private readonly client: ITypeScriptServiceClient
|
||||
) {
|
||||
this.onDidCloseTextDocumentSub = vscode.workspace.onDidCloseTextDocument(textDocument => {
|
||||
super();
|
||||
vscode.workspace.onDidCloseTextDocument(textDocument => {
|
||||
// When a document gets closed delete the cached formatting options.
|
||||
// This is necessary since the tsserver now closed a project when its
|
||||
// last file in it closes which drops the stored formatting options
|
||||
// as well.
|
||||
this.formatOptions.delete(textDocument.uri);
|
||||
});
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
if (this.onDidCloseTextDocumentSub) {
|
||||
this.onDidCloseTextDocumentSub.dispose();
|
||||
this.onDidCloseTextDocumentSub = undefined;
|
||||
}
|
||||
}, undefined, this._disposables);
|
||||
}
|
||||
|
||||
public async ensureConfigurationForDocument(
|
||||
|
||||
@@ -11,6 +11,7 @@ import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import { Lazy } from '../utils/lazy';
|
||||
import { isImplicitProjectConfigFile } from '../utils/tsconfig';
|
||||
import TsConfigProvider, { TSConfig } from '../utils/tsconfigProvider';
|
||||
import { Disposable } from '../utils/dispose';
|
||||
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
@@ -244,23 +245,24 @@ class TscTaskProvider implements vscode.TaskProvider {
|
||||
/**
|
||||
* Manages registrations of TypeScript task providers with VS Code.
|
||||
*/
|
||||
export default class TypeScriptTaskProviderManager {
|
||||
export default class TypeScriptTaskProviderManager extends Disposable {
|
||||
private taskProviderSub: vscode.Disposable | undefined = undefined;
|
||||
private readonly disposables: vscode.Disposable[] = [];
|
||||
|
||||
constructor(
|
||||
private readonly client: Lazy<ITypeScriptServiceClient>
|
||||
) {
|
||||
vscode.workspace.onDidChangeConfiguration(this.onConfigurationChanged, this, this.disposables);
|
||||
super();
|
||||
vscode.workspace.onDidChangeConfiguration(this.onConfigurationChanged, this, this._disposables);
|
||||
this.onConfigurationChanged();
|
||||
}
|
||||
|
||||
dispose() {
|
||||
super.dispose();
|
||||
|
||||
if (this.taskProviderSub) {
|
||||
this.taskProviderSub.dispose();
|
||||
this.taskProviderSub = undefined;
|
||||
}
|
||||
this.disposables.forEach(x => x.dispose());
|
||||
}
|
||||
|
||||
private onConfigurationChanged() {
|
||||
|
||||
@@ -5,29 +5,25 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { isSupportedLanguageMode } from './languageModeIds';
|
||||
import { Disposable } from './dispose';
|
||||
|
||||
/**
|
||||
* When clause context set when the current file is managed by vscode's built-in typescript extension.
|
||||
*/
|
||||
export default class ManagedFileContextManager {
|
||||
export default class ManagedFileContextManager extends Disposable {
|
||||
private static readonly contextName = 'typescript.isManagedFile';
|
||||
|
||||
private isInManagedFileContext: boolean = false;
|
||||
|
||||
private readonly onDidChangeActiveTextEditorSub: vscode.Disposable;
|
||||
|
||||
public constructor(
|
||||
private readonly normalizePath: (resource: vscode.Uri) => string | undefined
|
||||
) {
|
||||
this.onDidChangeActiveTextEditorSub = vscode.window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this);
|
||||
super();
|
||||
vscode.window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this, this._disposables);
|
||||
|
||||
this.onDidChangeActiveTextEditor(vscode.window.activeTextEditor);
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
this.onDidChangeActiveTextEditorSub.dispose();
|
||||
}
|
||||
|
||||
private onDidChangeActiveTextEditor(editor?: vscode.TextEditor): any {
|
||||
if (editor) {
|
||||
const isManagedFile = isSupportedLanguageMode(editor.document) && this.normalizePath(editor.document.uri) !== null;
|
||||
|
||||
@@ -6,18 +6,19 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { loadMessageBundle } from 'vscode-nls';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import { Disposable } from './dispose';
|
||||
|
||||
const localize = loadMessageBundle();
|
||||
|
||||
const typingsInstallTimeout = 30 * 1000;
|
||||
|
||||
export default class TypingsStatus extends vscode.Disposable {
|
||||
export default class TypingsStatus extends Disposable {
|
||||
private _acquiringTypings: { [eventId: string]: NodeJS.Timer } = Object.create({});
|
||||
private _client: ITypeScriptServiceClient;
|
||||
private _subscriptions: vscode.Disposable[] = [];
|
||||
|
||||
constructor(client: ITypeScriptServiceClient) {
|
||||
super(() => this.dispose());
|
||||
super();
|
||||
this._client = client;
|
||||
|
||||
this._subscriptions.push(
|
||||
@@ -28,6 +29,7 @@ export default class TypingsStatus extends vscode.Disposable {
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
super.dispose();
|
||||
this._subscriptions.forEach(x => x.dispose());
|
||||
|
||||
for (const eventId of Object.keys(this._acquiringTypings)) {
|
||||
|
||||
@@ -6,21 +6,17 @@
|
||||
import * as vscode from 'vscode';
|
||||
import * as languageModeIds from './languageModeIds';
|
||||
import { TypeScriptVersion } from './versionProvider';
|
||||
import { Disposable } from './dispose';
|
||||
|
||||
export default class VersionStatus {
|
||||
private readonly _onChangeEditorSub: vscode.Disposable;
|
||||
export default class VersionStatus extends Disposable {
|
||||
private readonly _versionBarEntry: vscode.StatusBarItem;
|
||||
|
||||
constructor(
|
||||
private readonly _normalizePath: (resource: vscode.Uri) => string | undefined
|
||||
) {
|
||||
this._versionBarEntry = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 99 /* to the right of editor status (100) */);
|
||||
this._onChangeEditorSub = vscode.window.onDidChangeActiveTextEditor(this.showHideStatus, this);
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
this._versionBarEntry.dispose();
|
||||
this._onChangeEditorSub.dispose();
|
||||
super();
|
||||
this._versionBarEntry = this._register(vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 99 /* to the right of editor status (100) */));
|
||||
vscode.window.onDidChangeActiveTextEditor(this.showHideStatus, this, this._disposables);
|
||||
}
|
||||
|
||||
public onDidChangeTypeScriptVersion(version: TypeScriptVersion) {
|
||||
|
||||
Reference in New Issue
Block a user