diff --git a/src/vs/platform/extensionManagement/node/extensionGalleryService.ts b/src/vs/platform/extensionManagement/node/extensionGalleryService.ts index 6b5d9a67ca1b6..4933f341b2e1b 100644 --- a/src/vs/platform/extensionManagement/node/extensionGalleryService.ts +++ b/src/vs/platform/extensionManagement/node/extensionGalleryService.ts @@ -355,34 +355,36 @@ export class ExtensionGalleryService implements IExtensionGalleryService { }); } - private async queryGallery(query: Query): TPromise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> { - const commonHeaders = await this.commonHTTPHeaders; - const data = JSON.stringify(query.raw); - const headers = assign({}, commonHeaders, { - 'Content-Type': 'application/json', - 'Accept': 'application/json;api-version=3.0-preview.1', - 'Accept-Encoding': 'gzip', - 'Content-Length': data.length - }); - - const context = await this.requestService.request({ - type: 'POST', - url: this.api('/extensionquery'), - data, - headers - }); + private queryGallery(query: Query): TPromise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> { + return this.commonHTTPHeaders.then(commonHeaders => { + const data = JSON.stringify(query.raw); + const headers = assign({}, commonHeaders, { + 'Content-Type': 'application/json', + 'Accept': 'application/json;api-version=3.0-preview.1', + 'Accept-Encoding': 'gzip', + 'Content-Length': data.length + }); - if (context.res.statusCode >= 400 && context.res.statusCode < 500) { - return { galleryExtensions: [], total: 0 }; - } + return this.requestService.request({ + type: 'POST', + url: this.api('/extensionquery'), + data, + headers + }); + }).then((context) => { + if (context.res.statusCode >= 400 && context.res.statusCode < 500) { + return TPromise.as({ galleryExtensions: [], total: 0 }); + } - const result = await asJson(context); - const r = result.results[0]; - const galleryExtensions = r.extensions; - const resultCount = r.resultMetadata && r.resultMetadata.filter(m => m.metadataType === 'ResultCount')[0]; - const total = resultCount && resultCount.metadataItems.filter(i => i.name === 'TotalCount')[0].count || 0; + return asJson(context).then(result => { + const r = result.results[0]; + const galleryExtensions = r.extensions; + const resultCount = r.resultMetadata && r.resultMetadata.filter(m => m.metadataType === 'ResultCount')[0]; + const total = resultCount && resultCount.metadataItems.filter(i => i.name === 'TotalCount')[0].count || 0; - return { galleryExtensions, total }; + return { galleryExtensions, total }; + }); + }); } download(extension: IGalleryExtension): TPromise { diff --git a/src/vs/workbench/electron-browser/extensionHost.ts b/src/vs/workbench/electron-browser/extensionHost.ts index ed393c61a2d3c..c5e0f44169342 100644 --- a/src/vs/workbench/electron-browser/extensionHost.ts +++ b/src/vs/workbench/electron-browser/extensionHost.ts @@ -352,9 +352,8 @@ export class ExtensionHostProcessWorker { // Unexpected termination if (!this.isExtensionDevelopmentHost) { - const openDevTools = new Action('openDevTools', nls.localize('devTools', "Developer Tools"), '', true, async (): TPromise => { - await this.windowService.openDevTools(); - return false; + const openDevTools = new Action('openDevTools', nls.localize('devTools', "Developer Tools"), '', true, (): TPromise => { + return this.windowService.openDevTools().then(() => false); }); this.messageService.show(Severity.Error, { diff --git a/src/vs/workbench/parts/extensions/electron-browser/extensionsViewlet.ts b/src/vs/workbench/parts/extensions/electron-browser/extensionsViewlet.ts index 4f8e99d0488b7..4f7245c3af989 100644 --- a/src/vs/workbench/parts/extensions/electron-browser/extensionsViewlet.ts +++ b/src/vs/workbench/parts/extensions/electron-browser/extensionsViewlet.ts @@ -301,22 +301,23 @@ export class ExtensionsViewlet extends ComposedViewsViewlet implements IExtensio .done(null, err => this.onError(err)); } - private async doSearch(): TPromise { + private doSearch(): TPromise { const value = this.searchBox.value || ''; this.searchExtensionsContextKey.set(!!value); this.searchInstalledExtensionsContextKey.set(InstalledExtensionsView.isInsalledExtensionsQuery(value)); this.searchRecommendedExtensionsContextKey.set(RecommendedExtensionsView.isRecommendedExtensionsQuery(value)); - await this.updateViews(!!value); + return this.updateViews(!!value); } - protected async updateViews(showAll?: boolean): TPromise { - const created = await super.updateViews(); - const toShow = showAll ? this.views : created; - if (toShow.length) { - await this.progress(TPromise.join(toShow.map(view => (view).show(this.searchBox.value)))); - } - return created; + protected updateViews(showAll?: boolean): TPromise { + return super.updateViews().then(created => { + const toShow = showAll ? this.views : created; + if (toShow.length) { + return this.progress(TPromise.join(toShow.map(view => (view).show(this.searchBox.value)))).then(() => created); + } + return created; + }); } private count(): number { diff --git a/src/vs/workbench/parts/extensions/electron-browser/extensionsViews.ts b/src/vs/workbench/parts/extensions/electron-browser/extensionsViews.ts index 0d0e0315e0659..8655e765b84fe 100644 --- a/src/vs/workbench/parts/extensions/electron-browser/extensionsViews.ts +++ b/src/vs/workbench/parts/extensions/electron-browser/extensionsViews.ts @@ -116,10 +116,11 @@ export class ExtensionsListView extends CollapsibleView { this.list.layout(size); } - async show(query: string): TPromise> { - const model = await this.query(query); - this.setModel(model); - return model; + show(query: string): TPromise> { + return this.query(query).then(model => { + this.setModel(model); + return model; + }); } select(): void { @@ -150,7 +151,7 @@ export class ExtensionsListView extends CollapsibleView { return this.list.length; } - private async query(value: string): TPromise> { + private query(value: string): TPromise> { const query = Query.parse(value); let options: IQueryOptions = { @@ -167,52 +168,55 @@ export class ExtensionsListView extends CollapsibleView { // Show installed extensions value = value ? value.replace(/@installed/g, '').replace(/@sort:(\w+)(-\w*)?/g, '').trim().toLowerCase() : ''; - let result = await this.extensionsWorkbenchService.queryLocal(); - - switch (options.sortBy) { - case SortBy.InstallCount: - result = result.sort((e1, e2) => e2.installCount - e1.installCount); - break; - case SortBy.AverageRating: - result = result.sort((e1, e2) => e2.rating - e1.rating); - break; - default: - result = result.sort((e1, e2) => e1.displayName.localeCompare(e2.displayName)); - break; - } + return this.extensionsWorkbenchService.queryLocal().then(result => { + + switch (options.sortBy) { + case SortBy.InstallCount: + result = result.sort((e1, e2) => e2.installCount - e1.installCount); + break; + case SortBy.AverageRating: + result = result.sort((e1, e2) => e2.rating - e1.rating); + break; + default: + result = result.sort((e1, e2) => e1.displayName.localeCompare(e2.displayName)); + break; + } - if (options.sortOrder === SortOrder.Descending) { - result = result.reverse(); - } + if (options.sortOrder === SortOrder.Descending) { + result = result.reverse(); + } - result = result - .filter(e => e.type === LocalExtensionType.User && e.name.toLowerCase().indexOf(value) > -1); + result = result + .filter(e => e.type === LocalExtensionType.User && e.name.toLowerCase().indexOf(value) > -1); - return new PagedModel(result); + return new PagedModel(result); + }); } if (/@outdated/i.test(value)) { value = value.replace(/@outdated/g, '').trim().toLowerCase(); - const local = await this.extensionsWorkbenchService.queryLocal(); - const result = local - .sort((e1, e2) => e1.displayName.localeCompare(e2.displayName)) - .filter(extension => extension.outdated && extension.name.toLowerCase().indexOf(value) > -1); + return this.extensionsWorkbenchService.queryLocal().then(local => { + const result = local + .sort((e1, e2) => e1.displayName.localeCompare(e2.displayName)) + .filter(extension => extension.outdated && extension.name.toLowerCase().indexOf(value) > -1); - return new PagedModel(result); + return new PagedModel(result); + }); } if (/@disabled/i.test(value)) { value = value.replace(/@disabled/g, '').trim().toLowerCase(); - const local = await this.extensionsWorkbenchService.queryLocal(); - const runningExtensions = await this.extensionService.getExtensions(); - - const result = local - .sort((e1, e2) => e1.displayName.localeCompare(e2.displayName)) - .filter(e => runningExtensions.every(r => !areSameExtensions(r, e)) && e.name.toLowerCase().indexOf(value) > -1); + return this.extensionsWorkbenchService.queryLocal().then(local => { + return this.extensionService.getExtensions().then(runningExtensions => { + const result = local + .sort((e1, e2) => e1.displayName.localeCompare(e2.displayName)) + .filter(e => runningExtensions.every(r => !areSameExtensions(r, e)) && e.name.toLowerCase().indexOf(value) > -1); - return new PagedModel(result); + return new PagedModel(result); + }); + }); } if (ExtensionsListView.isWorkspaceRecommendedExtensionsQuery(query.value)) { @@ -259,10 +263,12 @@ export class ExtensionsListView extends CollapsibleView { pagerPromises.push(this.extensionsWorkbenchService.queryGallery(options)); - const pagers = await TPromise.join(pagerPromises); - const pager = pagers.length === 2 ? mergePagers(pagers[0], pagers[1]) : pagers[0]; - return new PagedModel(pager); + return TPromise.join(pagerPromises).then(pagers => { + const pager = pagers.length === 2 ? mergePagers(pagers[0], pagers[1]) : pagers[0]; + + return new PagedModel(pager); + }); } private getAllRecommendationsModel(query: Query, options: IQueryOptions): TPromise> { @@ -426,7 +432,7 @@ export class InstalledExtensionsView extends ExtensionsListView { || ExtensionsListView.isDisabledExtensionsQuery(query); } - async show(query: string): TPromise> { + show(query: string): TPromise> { if (InstalledExtensionsView.isInsalledExtensionsQuery(query)) { return super.show(query); } @@ -444,7 +450,7 @@ export class RecommendedExtensionsView extends ExtensionsListView { || ExtensionsListView.isWorkspaceRecommendedExtensionsQuery(query); } - async show(query: string): TPromise> { + show(query: string): TPromise> { if (RecommendedExtensionsView.isRecommendedExtensionsQuery(query)) { return super.show(query); } diff --git a/src/vs/workbench/services/textmodelResolver/test/textModelResolverService.test.ts b/src/vs/workbench/services/textmodelResolver/test/textModelResolverService.test.ts index 9ae8a6fd4ba2d..3c4e88f6e2e3d 100644 --- a/src/vs/workbench/services/textmodelResolver/test/textModelResolverService.test.ts +++ b/src/vs/workbench/services/textmodelResolver/test/textModelResolverService.test.ts @@ -133,12 +133,12 @@ suite('Workbench - TextModelResolverService', () => { let waitForIt = new TPromise(c => resolveModel = c); const disposable = accessor.textModelResolverService.registerTextModelContentProvider('test', { - provideTextContent: async (resource: URI): TPromise => { - await waitForIt; - - let modelContent = 'Hello Test'; - let mode = accessor.modeService.getOrCreateMode('json'); - return accessor.modelService.createModel(modelContent, mode, resource); + provideTextContent: (resource: URI): TPromise => { + return waitForIt.then(() => { + let modelContent = 'Hello Test'; + let mode = accessor.modeService.getOrCreateMode('json'); + return accessor.modelService.createModel(modelContent, mode, resource); + }); } });