Skip to content

Commit

Permalink
#53526 Migrate away from TPromise in views land
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Nov 9, 2018
1 parent 11194a1 commit fe5fbc2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
22 changes: 9 additions & 13 deletions src/vs/workbench/api/electron-browser/mainThreadTreeViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { TPromise } from 'vs/base/common/winjs.base';
import { Disposable } from 'vs/base/common/lifecycle';
import { ExtHostContext, MainThreadTreeViewsShape, ExtHostTreeViewsShape, MainContext, IExtHostContext } from '../node/extHost.protocol';
import { ITreeViewDataProvider, ITreeItem, IViewsService, ITreeViewer, ViewsRegistry, ICustomViewDescriptor, IRevealOptions } from 'vs/workbench/common/views';
Expand Down Expand Up @@ -59,7 +58,7 @@ export class MainThreadTreeViews extends Disposable implements MainThreadTreeVie
return null;
}

private async reveal(treeViewer: ITreeViewer, dataProvider: TreeViewDataProvider, item: ITreeItem, parentChain: ITreeItem[], options: IRevealOptions): TPromise<void> {
private async reveal(treeViewer: ITreeViewer, dataProvider: TreeViewDataProvider, item: ITreeItem, parentChain: ITreeItem[], options: IRevealOptions): Promise<void> {
options = options ? options : { select: false, focus: false };
const select = isUndefinedOrNull(options.select) ? false : options.select;
const focus = isUndefinedOrNull(options.focus) ? false : options.focus;
Expand Down Expand Up @@ -131,17 +130,14 @@ class TreeViewDataProvider implements ITreeViewDataProvider {
) {
}

getChildren(treeItem?: ITreeItem): TPromise<ITreeItem[]> {
if (treeItem && treeItem.children) {
return TPromise.as(treeItem.children);
}
return TPromise.wrap(this._proxy.$getChildren(this.treeViewId, treeItem ? treeItem.handle : void 0)
.then(children => {
return this.postGetChildren(children);
}, err => {
this.notificationService.error(err);
return [];
}));
getChildren(treeItem?: ITreeItem): Promise<ITreeItem[]> {
return Promise.resolve(this._proxy.$getChildren(this.treeViewId, treeItem ? treeItem.handle : void 0)
.then(
children => this.postGetChildren(children),
err => {
this.notificationService.error(err);
return [];
}));
}

getItemsToRefresh(itemsToRefreshByHandle: { [treeItemHandle: string]: ITreeItem }): ITreeItem[] {
Expand Down
17 changes: 8 additions & 9 deletions src/vs/workbench/browser/parts/views/customView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'vs/css!./media/views';
import { Event, Emitter } from 'vs/base/common/event';
import { IDisposable, dispose, Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { TPromise } from 'vs/base/common/winjs.base';
import { IAction, IActionItem, ActionRunner, Action } from 'vs/base/common/actions';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
Expand Down Expand Up @@ -238,7 +237,7 @@ export class CustomTreeViewer extends Disposable implements ITreeViewer {
set dataProvider(dataProvider: ITreeViewDataProvider) {
if (dataProvider) {
this._dataProvider = new class implements ITreeViewDataProvider {
getChildren(node?: ITreeItem): TPromise<ITreeItem[]> {
getChildren(node?: ITreeItem): Promise<ITreeItem[]> {
if (node && node.children) {
return Promise.resolve(node.children);
}
Expand Down Expand Up @@ -394,7 +393,7 @@ export class CustomTreeViewer extends Disposable implements ITreeViewer {
return 0;
}

refresh(elements?: ITreeItem[]): TPromise<void> {
refresh(elements?: ITreeItem[]): Promise<void> {
if (this.dataProvider && this.tree) {
elements = elements || [this.root];
for (const element of elements) {
Expand All @@ -409,7 +408,7 @@ export class CustomTreeViewer extends Disposable implements ITreeViewer {
return Promise.resolve(null);
}

expand(itemOrItems: ITreeItem | ITreeItem[]): TPromise<void> {
expand(itemOrItems: ITreeItem | ITreeItem[]): Thenable<void> {
itemOrItems = Array.isArray(itemOrItems) ? itemOrItems : [itemOrItems];
return this.tree.expandAll(itemOrItems);
}
Expand All @@ -423,7 +422,7 @@ export class CustomTreeViewer extends Disposable implements ITreeViewer {
this.tree.setFocus(item);
}

reveal(item: ITreeItem): TPromise<void> {
reveal(item: ITreeItem): Thenable<void> {
return this.tree.reveal(item);
}

Expand All @@ -441,7 +440,7 @@ export class CustomTreeViewer extends Disposable implements ITreeViewer {
}
}

private doRefresh(elements: ITreeItem[]): TPromise<void> {
private doRefresh(elements: ITreeItem[]): Promise<void> {
if (this.tree) {
return Promise.all(elements.map(e => this.tree.refresh(e))).then(() => null);
}
Expand Down Expand Up @@ -484,7 +483,7 @@ class TreeDataSource implements IDataSource {
return this.treeView.dataProvider && node.collapsibleState !== TreeItemCollapsibleState.None;
}

getChildren(tree: ITree, node: ITreeItem): TPromise<any[]> {
getChildren(tree: ITree, node: ITreeItem): Promise<any[]> {
if (this.treeView.dataProvider) {
return this.progressService.withProgress({ location: this.container.id }, () => this.treeView.dataProvider.getChildren(node));
}
Expand All @@ -495,7 +494,7 @@ class TreeDataSource implements IDataSource {
return node.collapsibleState === TreeItemCollapsibleState.Expanded;
}

getParent(tree: ITree, node: any): TPromise<any> {
getParent(tree: ITree, node: any): Promise<any> {
return Promise.resolve(null);
}
}
Expand Down Expand Up @@ -721,7 +720,7 @@ class MultipleSelectionActionRunner extends ActionRunner {
super();
}

runAction(action: IAction, context: any): TPromise<any> {
runAction(action: IAction, context: any): Thenable<any> {
if (action instanceof MenuItemAction) {
const selection = this.getSelectedResources();
const filteredSelection = selection.filter(s => s !== context);
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/browser/parts/views/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import 'vs/css!./media/views';
import { Disposable } from 'vs/base/common/lifecycle';
import { TPromise } from 'vs/base/common/winjs.base';
import { IViewsService, ViewsRegistry, IViewsViewlet, ViewContainer, IViewDescriptor, IViewContainersRegistry, Extensions as ViewContainerExtensions, TEST_VIEW_CONTAINER_ID, IView, IViewDescriptorCollection } from 'vs/workbench/common/views';
import { Registry } from 'vs/platform/registry/common/platform';
import { ViewletRegistry, Extensions as ViewletExtensions } from 'vs/workbench/browser/viewlet';
Expand Down Expand Up @@ -541,7 +540,7 @@ export class ViewsService extends Disposable implements IViewsService {
return this.viewDescriptorCollections.get(container);
}

openView(id: string, focus: boolean): TPromise<IView> {
openView(id: string, focus: boolean): Thenable<IView> {
const viewDescriptor = ViewsRegistry.getView(id);
if (viewDescriptor) {
const viewletDescriptor = this.viewletService.getViewlet(viewDescriptor.container.id);
Expand Down
11 changes: 5 additions & 6 deletions src/vs/workbench/common/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { TPromise } from 'vs/base/common/winjs.base';
import { Command } from 'vs/editor/common/modes';
import { UriComponents } from 'vs/base/common/uri';
import { Event, Emitter } from 'vs/base/common/event';
Expand Down Expand Up @@ -228,7 +227,7 @@ export const IViewsService = createDecorator<IViewsService>('viewsService');
export interface IViewsService {
_serviceBrand: any;

openView(id: string, focus?: boolean): TPromise<IView>;
openView(id: string, focus?: boolean): Thenable<IView>;

getViewDescriptors(container: ViewContainer): IViewDescriptorCollection;
}
Expand All @@ -253,7 +252,7 @@ export interface ITreeViewer extends IDisposable {

readonly onDidChangeActions: Event<void>;

refresh(treeItems?: ITreeItem[]): TPromise<void>;
refresh(treeItems?: ITreeItem[]): Promise<void>;

setVisibility(visible: boolean): void;

Expand All @@ -265,9 +264,9 @@ export interface ITreeViewer extends IDisposable {

getOptimalWidth(): number;

reveal(item: ITreeItem): TPromise<void>;
reveal(item: ITreeItem): Thenable<void>;

expand(itemOrItems: ITreeItem | ITreeItem[]): TPromise<void>;
expand(itemOrItems: ITreeItem | ITreeItem[]): Thenable<void>;

setSelection(items: ITreeItem[]): void;

Expand Down Expand Up @@ -342,6 +341,6 @@ export interface ITreeItem {

export interface ITreeViewDataProvider {

getChildren(element?: ITreeItem): TPromise<ITreeItem[]>;
getChildren(element?: ITreeItem): Promise<ITreeItem[]>;

}

0 comments on commit fe5fbc2

Please sign in to comment.