提交 a6885b48 编写于 作者: M Matt Bierner

Use toDisposable in more places in workbench and platform

上级 ad7cbfda
......@@ -5,7 +5,7 @@
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { TypeConstraint, validateConstraints } from 'vs/base/common/types';
import { ServicesAccessor, createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { Event } from 'vs/base/common/event';
......@@ -91,14 +91,12 @@ export const CommandsRegistry: ICommandRegistry = new class implements ICommandR
let removeFn = commands.unshift(idOrCommand);
return {
dispose: () => {
removeFn();
if (this._commands.get(id).isEmpty()) {
this._commands.delete(id);
}
return toDisposable(() => {
removeFn();
if (this._commands.get(id).isEmpty()) {
this._commands.delete(id);
}
};
});
}
getCommand(id: string): ICommand {
......
......@@ -6,7 +6,7 @@
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { Color } from 'vs/base/common/color';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import * as platform from 'vs/platform/registry/common/platform';
import { ColorIdentifier } from 'vs/platform/theme/common/colorRegistry';
import { Event, Emitter } from 'vs/base/common/event';
......@@ -111,12 +111,10 @@ class ThemingRegistry implements IThemingRegistry {
public onThemeChange(participant: IThemingParticipant): IDisposable {
this.themingParticipants.push(participant);
this.onThemingParticipantAddedEmitter.fire(participant);
return {
dispose: () => {
const idx = this.themingParticipants.indexOf(participant);
this.themingParticipants.splice(idx, 1);
}
};
return toDisposable(() => {
const idx = this.themingParticipants.indexOf(participant);
this.themingParticipants.splice(idx, 1);
});
}
public get onThemingParticipantAdded(): Event<IThemingParticipant> {
......
......@@ -5,7 +5,7 @@
'use strict';
import { Emitter, Event } from 'vs/base/common/event';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { FileWriteOptions, FileSystemProviderCapabilities, IFileChange, IFileService, IFileSystemProvider, IStat, IWatchOptions, FileType, FileOverwriteOptions, FileDeleteOptions } from 'vs/platform/files/common/files';
......@@ -71,11 +71,9 @@ class RemoteFileSystemProvider implements IFileSystemProvider {
watch(resource: URI, opts: IWatchOptions) {
const session = Math.random();
this._proxy.$watch(this._handle, session, resource, opts);
return {
dispose: () => {
this._proxy.$unwatch(this._handle, session);
}
};
return toDisposable(() => {
this._proxy.$unwatch(this._handle, session);
});
}
$onFileSystemChange(changes: IFileChangeDto[]): void {
......
......@@ -9,7 +9,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { MainContext, IMainContext, ExtHostFileSystemShape, MainThreadFileSystemShape, IFileChangeDto } from './extHost.protocol';
import * as vscode from 'vscode';
import * as files from 'vs/platform/files/common/files';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { asWinJsPromise } from 'vs/base/common/async';
import { values } from 'vs/base/common/map';
import { Range, FileChangeType } from 'vs/workbench/api/node/extHostTypes';
......@@ -132,15 +132,13 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
this._proxy.$onFileSystemChange(handle, mapped);
});
return {
dispose: () => {
subscription.dispose();
this._linkProvider.delete(scheme);
this._usedSchemes.delete(scheme);
this._fsProvider.delete(handle);
this._proxy.$unregisterProvider(handle);
}
};
return toDisposable(() => {
subscription.dispose();
this._linkProvider.delete(scheme);
this._usedSchemes.delete(scheme);
this._fsProvider.delete(handle);
this._proxy.$unregisterProvider(handle);
});
}
private static _asIStat(stat: vscode.FileStat): files.IStat {
......
......@@ -15,6 +15,7 @@ import * as extfs from 'vs/base/node/extfs';
import { IFileMatch, IFolderQuery, IPatternInfo, IRawSearchQuery, ISearchCompleteStats, ISearchQuery } from 'vs/platform/search/common/search';
import * as vscode from 'vscode';
import { ExtHostSearchShape, IMainContext, MainContext, MainThreadSearchShape } from './extHost.protocol';
import { toDisposable } from 'vs/base/common/lifecycle';
export interface ISchemeTransformer {
transformOutgoing(scheme: string): string;
......@@ -44,12 +45,10 @@ export class ExtHostSearch implements ExtHostSearchShape {
const handle = this._handlePool++;
this._searchProvider.set(handle, provider);
this._proxy.$registerSearchProvider(handle, this._transformScheme(scheme));
return {
dispose: () => {
this._searchProvider.delete(handle);
this._proxy.$unregisterProvider(handle);
}
};
return toDisposable(() => {
this._searchProvider.delete(handle);
this._proxy.$unregisterProvider(handle);
});
}
$provideFileSearchResults(handle: number, session: number, rawQuery: IRawSearchQuery): TPromise<ISearchCompleteStats> {
......
......@@ -18,7 +18,7 @@ import { onUnexpectedError, isPromiseCanceledError } from 'vs/base/common/errors
import { Emitter } from 'vs/base/common/event';
import { defaultGenerator } from 'vs/base/common/idGenerator';
import { KeyCode } from 'vs/base/common/keyCodes';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { LRUCache } from 'vs/base/common/map';
import { escape } from 'vs/base/common/strings';
import URI from 'vs/base/common/uri';
......@@ -567,9 +567,7 @@ export class OutlinePanel extends ViewletPanel {
}
this._editorDisposables.push(this._input.onDidChange(onInputValueChanged));
this._editorDisposables.push({
dispose: () => this._contextKeyFiltered.reset()
});
this._editorDisposables.push(toDisposable(() => this._contextKeyFiltered.reset()));
// feature: reveal outline selection in editor
// on change -> reveal/select defining range
......
......@@ -7,7 +7,7 @@
import { basename, extname, join } from 'path';
import { MarkdownString } from 'vs/base/common/htmlContent';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { values } from 'vs/base/common/map';
import * as resources from 'vs/base/common/resources';
import { compare, endsWith, isFalsyOrWhitespace } from 'vs/base/common/strings';
......@@ -253,14 +253,12 @@ class SnippetsService implements ISnippetsService {
}
});
}, (error: string) => this._logService.error(error));
this._disposables.push({
dispose: () => {
if (watcher) {
watcher.removeAllListeners();
watcher.close();
}
this._disposables.push(toDisposable(() => {
if (watcher) {
watcher.removeAllListeners();
watcher.close();
}
});
}));
}).then(undefined, err => {
this._logService.error('Failed to load user snippets', err);
......
......@@ -17,7 +17,7 @@ import URI from 'vs/base/common/uri';
import { IStringDictionary } from 'vs/base/common/collections';
import { Action } from 'vs/base/common/actions';
import * as Dom from 'vs/base/browser/dom';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event';
import * as Types from 'vs/base/common/types';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
......@@ -253,11 +253,9 @@ class BuildStatusBarItem extends Themable implements IStatusbarItem {
this.updateStyles();
return {
dispose: () => {
callOnDispose = dispose(callOnDispose);
}
};
return toDisposable(() => {
callOnDispose = dispose(callOnDispose);
});
}
private ignoreEvent(event: TaskEvent): boolean {
......
......@@ -10,7 +10,7 @@ import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableEle
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
import * as strings from 'vs/base/common/strings';
import URI from 'vs/base/common/uri';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
import { EditorOptions, IEditorMemento } from 'vs/workbench/common/editor';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
......@@ -117,7 +117,7 @@ export class WalkThroughPart extends BaseEditor {
private addEventListener<E extends HTMLElement>(element: E, type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): IDisposable;
private addEventListener<E extends HTMLElement>(element: E, type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): IDisposable {
element.addEventListener(type, listener, useCapture);
return { dispose: () => { element.removeEventListener(type, listener, useCapture); } };
return toDisposable(() => { element.removeEventListener(type, listener, useCapture); });
}
private registerFocusHandlers() {
......
......@@ -14,6 +14,7 @@ import { ConfigurationResolverService } from 'vs/workbench/services/configuratio
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { TestEnvironmentService, TestEditorService, TestContextService } from 'vs/workbench/test/workbenchTestServices';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { Disposable } from 'vs/base/common/lifecycle';
suite('Configuration Resolver Service', () => {
let configurationResolverService: IConfigurationResolverService;
......@@ -391,7 +392,7 @@ class MockCommandService implements ICommandService {
public _serviceBrand: any;
public callCount = 0;
onWillExecuteCommand = () => ({ dispose: () => { } });
onWillExecuteCommand = () => Disposable.None;
public executeCommand(commandId: string, ...args: any[]): TPromise<any> {
this.callCount++;
......
......@@ -19,7 +19,7 @@ import { IRawSearch, ISerializedSearchComplete, ISerializedSearchProgressItem, I
import { ISearchChannel, SearchChannelClient } from './searchIpc';
import { IEnvironmentService, IDebugParams } from 'vs/platform/environment/common/environment';
import { ResourceMap } from 'vs/base/common/map';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { onUnexpectedError } from 'vs/base/common/errors';
import { Schemas } from 'vs/base/common/network';
......@@ -55,18 +55,16 @@ export class SearchService implements ISearchService {
this.searchProviders.push(provider);
}
return {
dispose: () => {
if (scheme === 'file') {
this.fileSearchProvider = null;
} else {
const idx = this.searchProviders.indexOf(provider);
if (idx >= 0) {
this.searchProviders.splice(idx, 1);
}
return toDisposable(() => {
if (scheme === 'file') {
this.fileSearchProvider = null;
} else {
const idx = this.searchProviders.indexOf(provider);
if (idx >= 0) {
this.searchProviders.splice(idx, 1);
}
}
};
});
}
public extendQuery(query: ISearchQuery): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册