Refresh master with initial release/0.24 snapshot (#332)

* Initial port of release/0.24 source code

* Fix additional headers

* Fix a typo in launch.json
This commit is contained in:
Karl Burtram
2017-12-15 15:38:57 -08:00
committed by GitHub
parent 271b3a0b82
commit 6ad0df0e3e
7118 changed files with 107999 additions and 56466 deletions

View File

@@ -5,16 +5,16 @@
import { localize } from 'vs/nls';
import { TPromise } from 'vs/base/common/winjs.base';
import { distinct } from 'vs/base/common/arrays';
import { distinct, coalesce } from 'vs/base/common/arrays';
import Event, { Emitter } from 'vs/base/common/event';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IExtensionManagementService, DidUninstallExtensionEvent, IExtensionEnablementService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { adoptToGalleryExtensionId, getIdAndVersionFromLocalExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IExtensionManagementService, DidUninstallExtensionEvent, IExtensionEnablementService, IExtensionIdentifier } from 'vs/platform/extensionManagement/common/extensionManagement';
import { adoptToGalleryExtensionId, getIdAndVersionFromLocalExtensionId, areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
const DISABLED_EXTENSIONS_STORAGE_PATH = 'extensions/disabled';
const DISABLED_EXTENSIONS_STORAGE_PATH = 'extensionsIdentifiers/disabled';
export class ExtensionEnablementService implements IExtensionEnablementService {
@@ -22,8 +22,8 @@ export class ExtensionEnablementService implements IExtensionEnablementService {
private disposables: IDisposable[] = [];
private _onEnablementChanged = new Emitter<string>();
public onEnablementChanged: Event<string> = this._onEnablementChanged.event;
private _onEnablementChanged = new Emitter<IExtensionIdentifier>();
public onEnablementChanged: Event<IExtensionIdentifier> = this._onEnablementChanged.event;
constructor(
@IStorageService private storageService: IStorageService,
@@ -35,31 +35,31 @@ export class ExtensionEnablementService implements IExtensionEnablementService {
}
private get hasWorkspace(): boolean {
return this.contextService.hasWorkspace();
return this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY;
}
public getGloballyDisabledExtensions(): string[] {
getGloballyDisabledExtensions(): IExtensionIdentifier[] {
return this.getDisabledExtensions(StorageScope.GLOBAL);
}
public getWorkspaceDisabledExtensions(): string[] {
getWorkspaceDisabledExtensions(): IExtensionIdentifier[] {
return this.getDisabledExtensions(StorageScope.WORKSPACE);
}
public canEnable(identifier: string): boolean {
canEnable(identifier: IExtensionIdentifier): boolean {
if (this.environmentService.disableExtensions) {
return false;
}
if (this.getGloballyDisabledExtensions().indexOf(identifier) !== -1) {
if (this.getGloballyDisabledExtensions().some(d => areSameExtensions(d, identifier))) {
return true;
}
if (this.getWorkspaceDisabledExtensions().indexOf(identifier) !== -1) {
if (this.getWorkspaceDisabledExtensions().some(d => areSameExtensions(d, identifier))) {
return true;
}
return false;
}
public setEnablement(identifier: string, enable: boolean, workspace: boolean = false): TPromise<boolean> {
setEnablement(identifier: IExtensionIdentifier, enable: boolean, workspace: boolean = false): TPromise<boolean> {
if (workspace && !this.hasWorkspace) {
return TPromise.wrapError<boolean>(new Error(localize('noWorkspace', "No workspace.")));
}
@@ -83,10 +83,16 @@ export class ExtensionEnablementService implements IExtensionEnablementService {
}
}
private disableExtension(identifier: string, scope: StorageScope): TPromise<boolean> {
migrateToIdentifiers(installed: IExtensionIdentifier[]): void {
this.migrateDisabledExtensions(installed, StorageScope.GLOBAL);
if (this.hasWorkspace) {
this.migrateDisabledExtensions(installed, StorageScope.WORKSPACE);
}
}
private disableExtension(identifier: IExtensionIdentifier, scope: StorageScope): TPromise<boolean> {
let disabledExtensions = this.getDisabledExtensions(scope);
const index = disabledExtensions.indexOf(identifier);
if (index === -1) {
if (disabledExtensions.every(e => !areSameExtensions(e, identifier))) {
disabledExtensions.push(identifier);
this.setDisabledExtensions(disabledExtensions, scope, identifier);
return TPromise.wrap(true);
@@ -94,28 +100,30 @@ export class ExtensionEnablementService implements IExtensionEnablementService {
return TPromise.wrap(false);
}
private enableExtension(identifier: string, scope: StorageScope, fireEvent = true): TPromise<boolean> {
private enableExtension(identifier: IExtensionIdentifier, scope: StorageScope, fireEvent = true): TPromise<boolean> {
let disabledExtensions = this.getDisabledExtensions(scope);
const index = disabledExtensions.indexOf(identifier);
if (index !== -1) {
disabledExtensions.splice(index, 1);
this.setDisabledExtensions(disabledExtensions, scope, identifier, fireEvent);
return TPromise.wrap(true);
for (let index = 0; index < disabledExtensions.length; index++) {
const disabledExtension = disabledExtensions[index];
if (areSameExtensions(disabledExtension, identifier)) {
disabledExtensions.splice(index, 1);
this.setDisabledExtensions(disabledExtensions, scope, identifier, fireEvent);
return TPromise.wrap(true);
}
}
return TPromise.wrap(false);
}
private getDisabledExtensions(scope: StorageScope): string[] {
private getDisabledExtensions(scope: StorageScope): IExtensionIdentifier[] {
if (scope === StorageScope.WORKSPACE && !this.hasWorkspace) {
return [];
}
const value = this.storageService.get(DISABLED_EXTENSIONS_STORAGE_PATH, scope, '');
return value ? distinct(value.split(',')).map(id => adoptToGalleryExtensionId(id)) : [];
return value ? JSON.parse(value) : [];
}
private setDisabledExtensions(disabledExtensions: string[], scope: StorageScope, extension: string, fireEvent = true): void {
private setDisabledExtensions(disabledExtensions: IExtensionIdentifier[], scope: StorageScope, extension: IExtensionIdentifier, fireEvent = true): void {
if (disabledExtensions.length) {
this.storageService.store(DISABLED_EXTENSIONS_STORAGE_PATH, disabledExtensions.join(','), scope);
this.storageService.store(DISABLED_EXTENSIONS_STORAGE_PATH, JSON.stringify(disabledExtensions.map(({ id, uuid }) => (<IExtensionIdentifier>{ id, uuid }))), scope);
} else {
this.storageService.remove(DISABLED_EXTENSIONS_STORAGE_PATH, scope);
}
@@ -124,12 +132,28 @@ export class ExtensionEnablementService implements IExtensionEnablementService {
}
}
private onDidUninstallExtension({ id, error }: DidUninstallExtensionEvent): void {
private migrateDisabledExtensions(installedExtensions: IExtensionIdentifier[], scope: StorageScope): void {
const oldValue = this.storageService.get('extensions/disabled', scope, '');
if (oldValue) {
const extensionIdentifiers = coalesce(distinct(oldValue.split(',')).map(id => {
id = adoptToGalleryExtensionId(id);
const matched = installedExtensions.filter(installed => areSameExtensions({ id }, { id: installed.id }))[0];
return matched ? { id: matched.id, uuid: matched.uuid } : null;
}));
if (extensionIdentifiers.length) {
this.storageService.store(DISABLED_EXTENSIONS_STORAGE_PATH, JSON.stringify(extensionIdentifiers), scope);
}
}
this.storageService.remove('extensions/disabled', scope);
}
private onDidUninstallExtension({ identifier, error }: DidUninstallExtensionEvent): void {
if (!error) {
id = getIdAndVersionFromLocalExtensionId(id).id;
const id = getIdAndVersionFromLocalExtensionId(identifier.id).id;
if (id) {
this.enableExtension(id, StorageScope.WORKSPACE, false);
this.enableExtension(id, StorageScope.GLOBAL, false);
const extension = { id, uuid: identifier.uuid };
this.enableExtension(extension, StorageScope.WORKSPACE, false);
this.enableExtension(extension, StorageScope.GLOBAL, false);
}
}
}

View File

@@ -79,6 +79,12 @@ export interface IView {
name: string;
}
export interface IColor {
id: string;
description: string;
defaults: { light: string, dark: string, highContrast: string };
}
export interface IExtensionContributions {
commands?: ICommand[];
configuration?: IConfiguration;
@@ -90,7 +96,9 @@ export interface IExtensionContributions {
menus?: { [context: string]: IMenu[] };
snippets?: ISnippet[];
themes?: ITheme[];
iconThemes?: ITheme[];
views?: { [location: string]: IView[] };
colors: IColor[];
}
export interface IExtensionManifest {
@@ -127,10 +135,14 @@ export interface IGalleryExtensionAssets {
license: IGalleryExtensionAsset;
}
export interface IGalleryExtension {
uuid: string;
export interface IExtensionIdentifier {
id: string;
uuid?: string;
}
export interface IGalleryExtension {
name: string;
identifier: IExtensionIdentifier;
version: string;
date: string;
displayName: string;
@@ -159,7 +171,7 @@ export enum LocalExtensionType {
export interface ILocalExtension {
type: LocalExtensionType;
id: string;
identifier: IExtensionIdentifier;
manifest: IExtensionManifest;
metadata: IGalleryMetadata;
path: string;
@@ -209,28 +221,28 @@ export interface IExtensionGalleryService {
reportStatistic(publisher: string, name: string, version: string, type: StatisticType): TPromise<void>;
getReadme(extension: IGalleryExtension): TPromise<string>;
getManifest(extension: IGalleryExtension): TPromise<IExtensionManifest>;
getChangelog(extension: IGalleryMetadata): TPromise<string>;
getChangelog(extension: IGalleryExtension): TPromise<string>;
loadCompatibleVersion(extension: IGalleryExtension): TPromise<IGalleryExtension>;
getAllDependencies(extension: IGalleryExtension): TPromise<IGalleryExtension[]>;
}
export interface InstallExtensionEvent {
id: string;
identifier: IExtensionIdentifier;
zipPath?: string;
gallery?: IGalleryExtension;
}
export interface DidInstallExtensionEvent {
id: string;
identifier: IExtensionIdentifier;
zipPath?: string;
gallery?: IGalleryExtension;
local?: ILocalExtension;
error?: Error;
error?: string;
}
export interface DidUninstallExtensionEvent {
id: string;
error?: Error;
identifier: IExtensionIdentifier;
error?: string;
}
export interface IExtensionManagementService {
@@ -238,13 +250,15 @@ export interface IExtensionManagementService {
onInstallExtension: Event<InstallExtensionEvent>;
onDidInstallExtension: Event<DidInstallExtensionEvent>;
onUninstallExtension: Event<string>;
onUninstallExtension: Event<IExtensionIdentifier>;
onDidUninstallExtension: Event<DidUninstallExtensionEvent>;
install(zipPath: string): TPromise<void>;
installFromGallery(extension: IGalleryExtension, promptToInstallDependencies?: boolean): TPromise<void>;
installFromGallery(extension: IGalleryExtension): TPromise<void>;
uninstall(extension: ILocalExtension, force?: boolean): TPromise<void>;
getInstalled(type?: LocalExtensionType): TPromise<ILocalExtension[]>;
updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise<ILocalExtension>;
}
export const IExtensionEnablementService = createDecorator<IExtensionEnablementService>('extensionEnablementService');
@@ -256,24 +270,24 @@ export interface IExtensionEnablementService {
/**
* Event to listen on for extension enablement changes
*/
onEnablementChanged: Event<string>;
onEnablementChanged: Event<IExtensionIdentifier>;
/**
* Returns all globally disabled extension identifiers.
* Returns an empty array if none exist.
*/
getGloballyDisabledExtensions(): string[];
getGloballyDisabledExtensions(): IExtensionIdentifier[];
/**
* Returns all workspace disabled extension identifiers.
* Returns an empty array if none exist or workspace does not exist.
*/
getWorkspaceDisabledExtensions(): string[];
getWorkspaceDisabledExtensions(): IExtensionIdentifier[];
/**
* Returns `true` if given extension can be enabled by calling `setEnablement`, otherwise false`.
*/
canEnable(identifier: string): boolean;
canEnable(identifier: IExtensionIdentifier): boolean;
/**
* Enable or disable the given extension.
@@ -284,14 +298,18 @@ export interface IExtensionEnablementService {
*
* Throws error if enablement is requested for workspace and there is no workspace
*/
setEnablement(identifier: string, enable: boolean, workspace?: boolean): TPromise<boolean>;
setEnablement(identifier: IExtensionIdentifier, enable: boolean, workspace?: boolean): TPromise<boolean>;
migrateToIdentifiers(installed: IExtensionIdentifier[]): void;
}
export const IExtensionTipsService = createDecorator<IExtensionTipsService>('extensionTipsService');
export interface IExtensionTipsService {
_serviceBrand: any;
getRecommendations(): string[];
getAllRecommendationsWithReason(): { [id: string]: string; };
getFileBasedRecommendations(): string[];
getOtherRecommendations(): string[];
getWorkspaceRecommendations(): TPromise<string[]>;
getKeymapRecommendations(): string[];
getKeywordsForExtension(extension: string): string[];

View File

@@ -7,7 +7,7 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc';
import { IExtensionManagementService, ILocalExtension, InstallExtensionEvent, DidInstallExtensionEvent, IGalleryExtension, LocalExtensionType, DidUninstallExtensionEvent } from './extensionManagement';
import { IExtensionManagementService, ILocalExtension, InstallExtensionEvent, DidInstallExtensionEvent, IGalleryExtension, LocalExtensionType, DidUninstallExtensionEvent, IExtensionIdentifier, IGalleryMetadata } from './extensionManagement';
import Event, { buffer } from 'vs/base/common/event';
export interface IExtensionManagementChannel extends IChannel {
@@ -26,7 +26,7 @@ export class ExtensionManagementChannel implements IExtensionManagementChannel {
onInstallExtension: Event<InstallExtensionEvent>;
onDidInstallExtension: Event<DidInstallExtensionEvent>;
onUninstallExtension: Event<string>;
onUninstallExtension: Event<IExtensionIdentifier>;
onDidUninstallExtension: Event<DidUninstallExtensionEvent>;
constructor(private service: IExtensionManagementService) {
@@ -43,9 +43,10 @@ export class ExtensionManagementChannel implements IExtensionManagementChannel {
case 'event:onUninstallExtension': return eventToCall(this.onUninstallExtension);
case 'event:onDidUninstallExtension': return eventToCall(this.onDidUninstallExtension);
case 'install': return this.service.install(arg);
case 'installFromGallery': return this.service.installFromGallery(arg[0], arg[1]);
case 'installFromGallery': return this.service.installFromGallery(arg[0]);
case 'uninstall': return this.service.uninstall(arg[0], arg[1]);
case 'getInstalled': return this.service.getInstalled(arg);
case 'updateMetadata': return this.service.updateMetadata(arg[0], arg[1]);
}
return undefined;
}
@@ -63,8 +64,8 @@ export class ExtensionManagementChannelClient implements IExtensionManagementSer
private _onDidInstallExtension = eventFromCall<DidInstallExtensionEvent>(this.channel, 'event:onDidInstallExtension');
get onDidInstallExtension(): Event<DidInstallExtensionEvent> { return this._onDidInstallExtension; }
private _onUninstallExtension = eventFromCall<string>(this.channel, 'event:onUninstallExtension');
get onUninstallExtension(): Event<string> { return this._onUninstallExtension; }
private _onUninstallExtension = eventFromCall<IExtensionIdentifier>(this.channel, 'event:onUninstallExtension');
get onUninstallExtension(): Event<IExtensionIdentifier> { return this._onUninstallExtension; }
private _onDidUninstallExtension = eventFromCall<DidUninstallExtensionEvent>(this.channel, 'event:onDidUninstallExtension');
get onDidUninstallExtension(): Event<DidUninstallExtensionEvent> { return this._onDidUninstallExtension; }
@@ -73,8 +74,8 @@ export class ExtensionManagementChannelClient implements IExtensionManagementSer
return this.channel.call('install', zipPath);
}
installFromGallery(extension: IGalleryExtension, promptToInstallDependencies: boolean = true): TPromise<void> {
return this.channel.call('installFromGallery', [extension, promptToInstallDependencies]);
installFromGallery(extension: IGalleryExtension): TPromise<void> {
return this.channel.call('installFromGallery', [extension]);
}
uninstall(extension: ILocalExtension, force = false): TPromise<void> {
@@ -84,4 +85,8 @@ export class ExtensionManagementChannelClient implements IExtensionManagementSer
getInstalled(type: LocalExtensionType = null): TPromise<ILocalExtension[]> {
return this.channel.call('getInstalled', type);
}
updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise<ILocalExtension> {
return this.channel.call('updateMetadata', [local, metadata]);
}
}

View File

@@ -5,10 +5,13 @@
'use strict';
import { ILocalExtension, IGalleryExtension, IExtensionManifest, EXTENSION_IDENTIFIER_REGEX, IExtensionEnablementService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { ILocalExtension, IGalleryExtension, EXTENSION_IDENTIFIER_REGEX, IExtensionEnablementService, IExtensionIdentifier } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
export function areSameExtensions(a: { id: string }, b: { id: string }): boolean {
export function areSameExtensions(a: IExtensionIdentifier, b: IExtensionIdentifier): boolean {
if (a.uuid && b.uuid) {
return a.uuid === b.uuid;
}
if (a.id === b.id) {
return true;
}
@@ -19,14 +22,6 @@ export function getGalleryExtensionId(publisher: string, name: string): string {
return `${publisher}.${name.toLocaleLowerCase()}`;
}
export function getLocalExtensionIdFromGallery(extension: IGalleryExtension, version: string): string {
return getLocalExtensionId(extension.id, version);
}
export function getLocalExtensionIdFromManifest(manifest: IExtensionManifest): string {
return getLocalExtensionId(getGalleryExtensionId(manifest.publisher, manifest.name), manifest.version);
}
export function getGalleryExtensionIdFromLocal(local: ILocalExtension): string {
return getGalleryExtensionId(local.manifest.publisher, local.manifest.name);
}
@@ -46,10 +41,6 @@ export function adoptToGalleryExtensionId(id: string): string {
return id.replace(EXTENSION_IDENTIFIER_REGEX, (match, publisher: string, name: string) => getGalleryExtensionId(publisher, name));
}
function getLocalExtensionId(id: string, version: string): string {
return `${id}-${version}`;
}
export function getLocalExtensionTelemetryData(extension: ILocalExtension): any {
return {
id: getGalleryExtensionIdFromLocal(extension),
@@ -62,11 +53,26 @@ export function getLocalExtensionTelemetryData(extension: ILocalExtension): any
};
}
/* __GDPR__FRAGMENT__
"GalleryExtensionTelemetryData" : {
"id" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"name": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"galleryId": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"publisherId": { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight" },
"publisherName": { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight" },
"publisherDisplayName": { "classification": "PublicPersonalData", "purpose": "FeatureInsight" },
"dependencies": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"${include}": [
"${GalleryExtensionTelemetryData2}"
]
}
*/
export function getGalleryExtensionTelemetryData(extension: IGalleryExtension): any {
return {
id: extension.id,
id: extension.identifier.id,
name: extension.name,
galleryId: extension.uuid,
galleryId: extension.identifier.uuid,
publisherId: extension.publisherId,
publisherName: extension.publisher,
publisherDisplayName: extension.publisherDisplayName,
@@ -87,9 +93,9 @@ export function getGloballyDisabledExtensions(extensionEnablementService: IExten
const globallyDisabled = extensionEnablementService.getGloballyDisabledExtensions();
if (!storageService.getBoolean(BetterMergeCheckKey, StorageScope.GLOBAL, false)) {
storageService.store(BetterMergeCheckKey, true);
if (globallyDisabled.indexOf(BetterMergeId) === -1 && installedExtensions.some(d => d.id === BetterMergeId)) {
globallyDisabled.push(BetterMergeId);
extensionEnablementService.setEnablement(BetterMergeId, false);
if (globallyDisabled.every(disabled => disabled.id !== BetterMergeId) && installedExtensions.some(d => d.id === BetterMergeId)) {
globallyDisabled.push({ id: BetterMergeId });
extensionEnablementService.setEnablement({ id: BetterMergeId }, false);
storageService.store(BetterMergeDisabledNowKey, true);
}
}

View File

@@ -245,8 +245,10 @@ function toExtension(galleryExtension: IRawGalleryExtension, extensionsGalleryUr
};
return {
uuid: galleryExtension.extensionId,
id: getGalleryExtensionId(galleryExtension.publisher.publisherName, galleryExtension.extensionName),
identifier: {
id: getGalleryExtensionId(galleryExtension.publisher.publisherName, galleryExtension.extensionName),
uuid: galleryExtension.extensionId
},
name: galleryExtension.extensionName,
version: version.version,
date: version.lastUpdated,
@@ -263,6 +265,13 @@ function toExtension(galleryExtension: IRawGalleryExtension, extensionsGalleryUr
dependencies: getDependencies(version),
engine: getEngine(version)
},
/* __GDPR__FRAGMENT__
"GalleryExtensionTelemetryData2" : {
"index" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"searchText": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"querySource": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
telemetryData: {
index: ((query.pageNumber - 1) * query.pageSize) + index,
searchText: query.searchText,
@@ -311,6 +320,12 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
let text = options.text || '';
const pageSize = getOrDefault(options, o => o.pageSize, 50);
/* __GDPR__
"galleryService:query" : {
"type" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"text": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this.telemetryService.publicLog('galleryService:query', { type, text });
let query = new Query()
@@ -336,6 +351,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
text = text.trim();
if (text) {
text = text.length < 200 ? text : text.substring(0, 200);
query = query.withFilter(FilterType.SearchText, text);
}
@@ -359,7 +375,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
return this.queryGallery(query).then(({ galleryExtensions, total }) => {
const extensions = galleryExtensions.map((e, index) => toExtension(e, this.extensionsGalleryUrl, index, query, options.source));
const pageSize = query.pageSize;
const getPage = pageIndex => {
const getPage = (pageIndex: number) => {
const nextPageQuery = query.withPage(pageIndex + 1);
return this.queryGallery(nextPageQuery)
.then(({ galleryExtensions }) => galleryExtensions.map((e, index) => toExtension(e, this.extensionsGalleryUrl, index, nextPageQuery, options.source)));
@@ -369,8 +385,8 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
});
}
private async queryGallery(query: Query): TPromise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> {
const commonHeaders = await this.commonHTTPHeaders;
private queryGallery(query: Query): TPromise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> {
const commonHeaders = this.commonHTTPHeaders;
const data = JSON.stringify(query.raw);
const headers = assign({}, commonHeaders, {
'Content-Type': 'application/json',
@@ -379,45 +395,40 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
'Content-Length': data.length
});
const context = await this.requestService.request({
return this.requestService.request({
type: 'POST',
url: this.api('/extensionquery'),
data,
headers
}).then(context => {
if (context.res.statusCode >= 400 && context.res.statusCode < 500) {
return { galleryExtensions: [], total: 0 };
}
return asJson<IRawGalleryQueryResult>(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 };
});
});
if (context.res.statusCode >= 400 && context.res.statusCode < 500) {
return { galleryExtensions: [], total: 0 };
}
const result = await asJson<IRawGalleryQueryResult>(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 { galleryExtensions, total };
}
async reportStatistic(publisher: string, name: string, version: string, type: StatisticType): TPromise<void> {
reportStatistic(publisher: string, name: string, version: string, type: StatisticType): TPromise<void> {
if (!this.isEnabled()) {
return;
return TPromise.as(null);
}
try {
const headers = {
...await this.commonHTTPHeaders,
Accept: '*/*;api-version=4.0-preview.1'
};
const headers = { ...this.commonHTTPHeaders, Accept: '*/*;api-version=4.0-preview.1' };
await this.requestService.request({
type: 'POST',
url: this.api(`/publishers/${publisher}/extensions/${name}/${version}/stats?statType=${type}`),
headers
});
} catch (err) {
// noop
}
return this.requestService.request({
type: 'POST',
url: this.api(`/publishers/${publisher}/extensions/${name}/${version}/stats?statType=${type}`),
headers
}).then(null, () => null);
}
download(extension: IGalleryExtension): TPromise<string> {
@@ -425,7 +436,15 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
const zipPath = path.join(tmpdir(), uuid.generateUuid());
const data = getGalleryExtensionTelemetryData(extension);
const startTime = new Date().getTime();
const log = duration => this.telemetryService.publicLog('galleryService:downloadVSIX', assign(data, { duration }));
/* __GDPR__
"galleryService:downloadVSIX" : {
"duration": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
"${include}": [
"${GalleryExtensionTelemetryData}"
]
}
*/
const log = (duration: number) => this.telemetryService.publicLog('galleryService:downloadVSIX', assign(data, { duration }));
return this.getAsset(extension.assets.download)
.then(context => download(zipPath, context))
@@ -466,7 +485,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
.withFilter(FilterType.Target, 'Microsoft.VisualStudio.Code')
.withFilter(FilterType.ExcludeWithFlags, flagsToString(Flags.Unpublished))
.withAssetTypes(AssetType.Manifest, AssetType.VSIX)
.withFilter(FilterType.ExtensionId, extension.uuid);
.withFilter(FilterType.ExtensionId, extension.identifier.uuid);
return this.queryGallery(query).then(({ galleryExtensions }) => {
const [rawExtension] = galleryExtensions;
@@ -506,7 +525,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
for (let index = 0; index < result.galleryExtensions.length; index++) {
const rawExtension = result.galleryExtensions[index];
if (ids.indexOf(rawExtension.extensionId) === -1) {
dependencies.push(toExtension(rawExtension, this.extensionsGalleryUrl, index, query));
dependencies.push(toExtension(rawExtension, this.extensionsGalleryUrl, index, query, 'dependencies'));
ids.push(rawExtension.extensionId);
}
}
@@ -534,7 +553,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
dep.properties.dependencies.forEach(d => dependenciesSet.add(d));
}
}
result = distinct(result.concat(loadedDependencies), d => d.uuid);
result = distinct(result.concat(loadedDependencies), d => d.identifier.uuid);
const dependencies: string[] = [];
dependenciesSet.forEach(d => !ExtensionGalleryService.hasExtensionByName(result, d) && dependencies.push(d));
return this.getDependenciesReccursively(dependencies, result, root);
@@ -565,7 +584,20 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
}
const message = getErrorMessage(err);
/* __GDPR__
"galleryService:requestError" : {
"url" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"cdn": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"message": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this.telemetryService.publicLog('galleryService:requestError', { url, cdn: true, message });
/* __GDPR__
"galleryService:cdnFallback" : {
"url" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"message": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this.telemetryService.publicLog('galleryService:cdnFallback', { url, message });
const fallbackOptions = assign({}, options, { url: fallbackUrl });
@@ -575,6 +607,13 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
}
const message = getErrorMessage(err);
/* __GDPR__
"galleryService:requestError" : {
"url" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"cdn": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"message": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this.telemetryService.publicLog('galleryService:requestError', { url: fallbackUrl, cdn: false, message });
return TPromise.wrapError<IRequestContext>(err);
});

View File

@@ -18,9 +18,10 @@ import {
IExtensionManagementService, IExtensionGalleryService, ILocalExtension,
IGalleryExtension, IExtensionManifest, IGalleryMetadata,
InstallExtensionEvent, DidInstallExtensionEvent, DidUninstallExtensionEvent, LocalExtensionType,
StatisticType
StatisticType,
IExtensionIdentifier
} from 'vs/platform/extensionManagement/common/extensionManagement';
import { getLocalExtensionIdFromGallery, getLocalExtensionIdFromManifest, getGalleryExtensionIdFromLocal, getIdAndVersionFromLocalExtensionId, adoptToGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { getGalleryExtensionIdFromLocal, getIdAndVersionFromLocalExtensionId, adoptToGalleryExtensionId, areSameExtensions, getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { localizeManifest } from '../common/extensionNls';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { Limiter } from 'vs/base/common/async';
@@ -31,6 +32,9 @@ import URI from 'vs/base/common/uri';
import { IChoiceService, Severity } from 'vs/platform/message/common/message';
const SystemExtensionsRoot = path.normalize(path.join(URI.parse(require.toUrl('')).fsPath, '..', 'extensions'));
const INSTALL_ERROR_OBSOLETE = 'obsolete';
const INSTALL_ERROR_GALLERY = 'gallery';
const INSTALL_ERROR_LOCAL = 'local';
function parseManifest(raw: string): TPromise<{ manifest: IExtensionManifest; metadata: IGalleryMetadata; }> {
return new TPromise((c, e) => {
@@ -68,6 +72,13 @@ function readManifest(extensionPath: string): TPromise<{ manifest: IExtensionMan
});
}
interface InstallableExtension {
zipPath: string;
id: string;
metadata: IGalleryMetadata;
current?: ILocalExtension;
}
export class ExtensionManagementService implements IExtensionManagementService {
_serviceBrand: any;
@@ -83,8 +94,8 @@ export class ExtensionManagementService implements IExtensionManagementService {
private _onDidInstallExtension = new Emitter<DidInstallExtensionEvent>();
onDidInstallExtension: Event<DidInstallExtensionEvent> = this._onDidInstallExtension.event;
private _onUninstallExtension = new Emitter<string>();
onUninstallExtension: Event<string> = this._onUninstallExtension.event;
private _onUninstallExtension = new Emitter<IExtensionIdentifier>();
onUninstallExtension: Event<IExtensionIdentifier> = this._onUninstallExtension.event;
private _onDidUninstallExtension = new Emitter<DidUninstallExtensionEvent>();
onDidUninstallExtension: Event<DidUninstallExtensionEvent> = this._onDidUninstallExtension.event;
@@ -103,142 +114,121 @@ export class ExtensionManagementService implements IExtensionManagementService {
zipPath = path.resolve(zipPath);
return validate(zipPath).then<void>(manifest => {
const id = getLocalExtensionIdFromManifest(manifest);
const identifier = { id: getLocalExtensionIdFromManifest(manifest) };
return this.isObsolete(id).then(isObsolete => {
return this.isObsolete(identifier.id).then(isObsolete => {
if (isObsolete) {
return TPromise.wrapError(new Error(nls.localize('restartCode', "Please restart Code before reinstalling {0}.", manifest.displayName || manifest.name)));
return TPromise.wrapError(new Error(nls.localize('restartCodeLocal', "Please restart Code before reinstalling {0}.", manifest.displayName || manifest.name)));
}
this._onInstallExtension.fire({ id, zipPath });
this._onInstallExtension.fire({ identifier, zipPath });
return this.installExtension(zipPath, id)
.then(
local => this._onDidInstallExtension.fire({ id, zipPath, local }),
error => { this._onDidInstallExtension.fire({ id, zipPath, error }); return TPromise.wrapError(error); }
);
});
});
}
installFromGallery(extension: IGalleryExtension, promptToInstallDependencies: boolean = true): TPromise<void> {
const id = getLocalExtensionIdFromGallery(extension, extension.version);
return this.isObsolete(id).then(isObsolete => {
if (isObsolete) {
return TPromise.wrapError<void>(new Error(nls.localize('restartCode', "Please restart Code before reinstalling {0}.", extension.displayName || extension.name)));
}
this._onInstallExtension.fire({ id, gallery: extension });
return this.installCompatibleVersion(extension, true, promptToInstallDependencies)
.then(
local => this._onDidInstallExtension.fire({ id, local, gallery: extension }),
error => {
this._onDidInstallExtension.fire({ id, gallery: extension, error });
return TPromise.wrapError(error);
}
);
});
}
private installCompatibleVersion(extension: IGalleryExtension, installDependencies: boolean, promptToInstallDependencies: boolean): TPromise<ILocalExtension> {
return this.galleryService.loadCompatibleVersion(extension)
.then(compatibleVersion => this.getDependenciesToInstall(extension, installDependencies)
.then(dependencies => {
if (!dependencies.length) {
return this.downloadAndInstall(compatibleVersion);
}
if (promptToInstallDependencies) {
const message = nls.localize('installDependeciesConfirmation', "Installing '{0}' also installs its dependencies. Would you like to continue?", extension.displayName);
const options = [
nls.localize('install', "Yes"),
nls.localize('doNotInstall', "No")
];
return this.choiceService.choose(Severity.Info, message, options, 1, true)
.then(value => {
if (value === 0) {
return this.installWithDependencies(compatibleVersion);
}
return TPromise.wrapError<ILocalExtension>(errors.canceled());
}, error => TPromise.wrapError<ILocalExtension>(errors.canceled()));
} else {
return this.installWithDependencies(compatibleVersion);
}
})
);
}
private getDependenciesToInstall(extension: IGalleryExtension, checkDependecies: boolean): TPromise<string[]> {
if (!checkDependecies) {
return TPromise.wrap([]);
}
// Filter out self
const dependencies = extension.properties.dependencies ? extension.properties.dependencies.filter(id => id !== extension.id) : [];
if (!dependencies.length) {
return TPromise.wrap([]);
}
// Filter out installed dependencies
return this.getInstalled().then(installed => {
return dependencies.filter(dep => installed.every(i => `${i.manifest.publisher}.${i.manifest.name}` !== dep));
});
}
private installWithDependencies(extension: IGalleryExtension): TPromise<ILocalExtension> {
return this.galleryService.getAllDependencies(extension)
.then(allDependencies => this.filterDependenciesToInstall(extension, allDependencies))
.then(toInstall => this.filterObsolete(...toInstall.map(i => getLocalExtensionIdFromGallery(i, i.version)))
.then((obsolete) => {
if (obsolete.length) {
return TPromise.wrapError<ILocalExtension>(new Error(nls.localize('restartCode', "Please restart Code before reinstalling {0}.", extension.displayName || extension.name)));
}
return this.bulkInstallWithDependencies(extension, toInstall);
})
);
}
private bulkInstallWithDependencies(extension: IGalleryExtension, dependecies: IGalleryExtension[]): TPromise<ILocalExtension> {
for (const dependency of dependecies) {
const id = getLocalExtensionIdFromGallery(dependency, dependency.version);
this._onInstallExtension.fire({ id, gallery: dependency });
}
return this.downloadAndInstall(extension)
.then(localExtension => {
return TPromise.join(dependecies.map((dep) => this.installCompatibleVersion(dep, false, false)))
.then(installedLocalExtensions => {
for (const installedLocalExtension of installedLocalExtensions) {
const gallery = this.getGalleryExtensionForLocalExtension(dependecies, installedLocalExtension);
this._onDidInstallExtension.fire({ id: installedLocalExtension.id, local: installedLocalExtension, gallery });
}
return localExtension;
}, error => {
return this.rollback(localExtension, dependecies).then(() => {
return TPromise.wrapError<ILocalExtension>(Array.isArray(error) ? error[error.length - 1] : error);
});
return this.galleryService.query({ names: [getGalleryExtensionId(manifest.publisher, manifest.name)], pageSize: 1 })
.then(galleryResult => {
const galleryExtension = galleryResult.firstPage[0];
const metadata = galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : null;
return this.installExtension({ zipPath, id: identifier.id, metadata })
.then(
local => this._onDidInstallExtension.fire({ identifier, zipPath, local }),
error => { this._onDidInstallExtension.fire({ identifier, zipPath, error }); return TPromise.wrapError(error); }
);
});
})
.then(localExtension => localExtension, error => {
for (const dependency of dependecies) {
this._onDidInstallExtension.fire({ id: getLocalExtensionIdFromGallery(dependency, dependency.version), gallery: dependency, error });
}
return TPromise.wrapError<ILocalExtension>(error);
});
});
}
private rollback(localExtension: ILocalExtension, dependecies: IGalleryExtension[]): TPromise<void> {
return this.doUninstall(localExtension)
.then(() => this.filterOutUninstalled(dependecies))
.then(installed => TPromise.join(installed.map((i) => this.doUninstall(i))))
.then(() => null);
installFromGallery(extension: IGalleryExtension): TPromise<void> {
return this.prepareAndCollectExtensionsToInstall(extension)
.then(extensionsToInstall => this.downloadAndInstallExtensions(extensionsToInstall)
.then(local => this.onDidInstallExtensions(extensionsToInstall, local)));
}
private prepareAndCollectExtensionsToInstall(extension: IGalleryExtension): TPromise<IGalleryExtension[]> {
this.onInstallExtensions([extension]);
return this.collectExtensionsToInstall(extension)
.then(
extensionsToInstall => this.checkForObsolete(extensionsToInstall)
.then(
extensionsToInstall => {
if (extensionsToInstall.length > 1) {
this.onInstallExtensions(extensionsToInstall.slice(1));
}
return extensionsToInstall;
},
error => this.onDidInstallExtensions([extension], null, INSTALL_ERROR_OBSOLETE, error)
),
error => this.onDidInstallExtensions([extension], null, INSTALL_ERROR_GALLERY, error)
);
}
private downloadAndInstallExtensions(extensions: IGalleryExtension[]): TPromise<ILocalExtension[]> {
return this.getInstalled(LocalExtensionType.User)
.then(installed => TPromise.join(extensions.map(extensionToInstall => this.downloadInstallableExtension(extensionToInstall, installed)))
.then(
installableExtensions => TPromise.join(installableExtensions.map(installableExtension => this.installExtension(installableExtension)))
.then(null, error => this.rollback(extensions).then(() => this.onDidInstallExtensions(extensions, null, INSTALL_ERROR_LOCAL, error))),
error => this.onDidInstallExtensions(extensions, null, INSTALL_ERROR_GALLERY, error)));
}
private collectExtensionsToInstall(extension: IGalleryExtension): TPromise<IGalleryExtension[]> {
return this.galleryService.loadCompatibleVersion(extension)
.then(extensionToInstall => this.galleryService.getAllDependencies(extension)
.then(allDependencies => this.filterDependenciesToInstall(extension, allDependencies))
.then(dependenciesToInstall => [extensionToInstall, ...dependenciesToInstall]));
}
private checkForObsolete(extensionsToInstall: IGalleryExtension[]): TPromise<IGalleryExtension[]> {
return this.filterObsolete(...extensionsToInstall.map(i => getLocalExtensionIdFromGallery(i, i.version)))
.then(obsolete => obsolete.length ? TPromise.wrapError<IGalleryExtension[]>(new Error(nls.localize('restartCodeGallery', "Please restart Code before reinstalling."))) : extensionsToInstall);
}
private downloadInstallableExtension(extension: IGalleryExtension, installed: ILocalExtension[]): TPromise<InstallableExtension> {
const current = installed.filter(i => i.identifier.uuid === extension.identifier.uuid)[0];
const id = getLocalExtensionIdFromGallery(extension, extension.version);
const metadata = <IGalleryMetadata>{
id: extension.identifier.uuid,
publisherId: extension.publisherId,
publisherDisplayName: extension.publisherDisplayName,
};
return this.galleryService.download(extension)
.then(zipPath => validate(zipPath).then(() => (<InstallableExtension>{ zipPath, id, metadata, current })));
}
private rollback(extensions: IGalleryExtension[]): TPromise<void> {
return this.filterOutUninstalled(extensions)
.then(installed => TPromise.join(installed.map(local => this.uninstallExtension(local.identifier))))
.then(() => null, () => null);
}
private onInstallExtensions(extensions: IGalleryExtension[]): void {
for (const extension of extensions) {
const id = getLocalExtensionIdFromGallery(extension, extension.version);
this._onInstallExtension.fire({ identifier: { id, uuid: extension.identifier.uuid }, gallery: extension });
}
}
private onDidInstallExtensions(extensions: IGalleryExtension[], local: ILocalExtension[], errorCode?: string, error?: any): TPromise<any> {
extensions.forEach((gallery, index) => {
const identifier = { id: getLocalExtensionIdFromGallery(gallery, gallery.version), uuid: gallery.identifier.uuid };
if (errorCode) {
this._onDidInstallExtension.fire({ identifier, gallery, error: errorCode });
} else {
this._onDidInstallExtension.fire({ identifier, gallery, local: local[index] });
}
});
return error ? TPromise.wrapError(Array.isArray(error) ? this.joinErrors(error) : error) : TPromise.as(null);
}
private filterDependenciesToInstall(extension: IGalleryExtension, dependencies: IGalleryExtension[]): TPromise<IGalleryExtension[]> {
return this.getInstalled()
.then(local => {
return dependencies.filter(d => {
if (extension.uuid === d.uuid) {
if (extension.identifier.uuid === d.identifier.uuid) {
return false;
}
const extensionId = getLocalExtensionIdFromGallery(d, d.version);
return local.every(local => local.id !== extensionId);
return local.every(({ identifier }) => identifier.id !== extensionId);
});
});
}
@@ -249,24 +239,11 @@ export class ExtensionManagementService implements IExtensionManagementService {
}
private getGalleryExtensionForLocalExtension(galleryExtensions: IGalleryExtension[], localExtension: ILocalExtension): IGalleryExtension {
const filtered = galleryExtensions.filter(galleryExtension => getLocalExtensionIdFromGallery(galleryExtension, galleryExtension.version) === localExtension.id);
const filtered = galleryExtensions.filter(galleryExtension => areSameExtensions(localExtension.identifier, { id: getLocalExtensionIdFromGallery(galleryExtension, galleryExtension.version), uuid: galleryExtension.identifier.uuid }));
return filtered.length ? filtered[0] : null;
}
private downloadAndInstall(extension: IGalleryExtension): TPromise<ILocalExtension> {
const id = getLocalExtensionIdFromGallery(extension, extension.version);
const metadata = {
id: extension.uuid,
publisherId: extension.publisherId,
publisherDisplayName: extension.publisherDisplayName,
};
return this.galleryService.download(extension)
.then(zipPath => validate(zipPath).then(() => zipPath))
.then(zipPath => this.installExtension(zipPath, id, metadata));
}
private installExtension(zipPath: string, id: string, metadata: IGalleryMetadata = null): TPromise<ILocalExtension> {
private installExtension({ zipPath, id, metadata, current }: InstallableExtension): TPromise<ILocalExtension> {
const extensionPath = path.join(this.extensionsPath, id);
return pfs.rimraf(extensionPath).then(() => {
@@ -279,14 +256,12 @@ export class ExtensionManagementService implements IExtensionManagementService {
const changelog = children.filter(child => /^changelog(\.txt|\.md|)$/i.test(child))[0];
const changelogUrl = changelog ? URI.file(path.join(extensionPath, changelog)).toString() : null;
const type = LocalExtensionType.User;
const identifier = { id, uuid: metadata ? metadata.id : null };
const local: ILocalExtension = { type, id, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl };
const manifestPath = path.join(extensionPath, 'package.json');
const local: ILocalExtension = { type, identifier, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl };
return pfs.readFile(manifestPath, 'utf8')
.then(raw => parseManifest(raw))
.then(({ manifest }) => assign(manifest, { __metadata: metadata }))
.then(manifest => pfs.writeFile(manifestPath, JSON.stringify(manifest, null, '\t')))
return this.saveMetadataForLocalExtension(local)
.then(() => this.checkForRename(current, local))
.then(() => local);
});
});
@@ -294,14 +269,52 @@ export class ExtensionManagementService implements IExtensionManagementService {
}
uninstall(extension: ILocalExtension, force = false): TPromise<void> {
return this.removeOutdatedExtensions().then(() => {
return this.scanUserExtensions().then(installed => {
const promises = installed
.filter(e => e.manifest.publisher === extension.manifest.publisher && e.manifest.name === extension.manifest.name)
.map(e => this.checkForDependenciesAndUninstall(e, installed, force));
return TPromise.join(promises);
});
}).then(() => { /* drop resolved value */ });
return this.removeOutdatedExtensions()
.then(() =>
this.scanUserExtensions()
.then(installed => {
const promises = installed
.filter(e => e.manifest.publisher === extension.manifest.publisher && e.manifest.name === extension.manifest.name)
.map(e => this.checkForDependenciesAndUninstall(e, installed, force));
return TPromise.join(promises).then(null, error => TPromise.wrapError(Array.isArray(error) ? this.joinErrors(error) : error));
}))
.then(() => { /* drop resolved value */ });
}
updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise<ILocalExtension> {
local.metadata = metadata;
return this.saveMetadataForLocalExtension(local);
}
private saveMetadataForLocalExtension(local: ILocalExtension): TPromise<ILocalExtension> {
if (!local.metadata) {
return TPromise.as(local);
}
const manifestPath = path.join(this.extensionsPath, local.identifier.id, 'package.json');
return pfs.readFile(manifestPath, 'utf8')
.then(raw => parseManifest(raw))
.then(({ manifest }) => assign(manifest, { __metadata: local.metadata }))
.then(manifest => pfs.writeFile(manifestPath, JSON.stringify(manifest, null, '\t')))
.then(() => local);
}
private checkForRename(currentExtension: ILocalExtension, newExtension: ILocalExtension): TPromise<void> {
// Check if the gallery id for current and new exensions are same, if not, remove the current one.
if (currentExtension && getGalleryExtensionIdFromLocal(currentExtension) !== getGalleryExtensionIdFromLocal(newExtension)) {
// return this.uninstallExtension(currentExtension.identifier);
return this.setObsolete(currentExtension.identifier.id);
}
return TPromise.as(null);
}
private joinErrors(errors: (Error | string)[]): Error {
if (errors.length === 1) {
return errors[0] instanceof Error ? <Error>errors[0] : new Error(<string>errors[0]);
}
return errors.reduce<Error>((previousValue: Error, currentValue: Error | string) => {
return new Error(`${previousValue.message}${previousValue.message ? ',' : ''}${currentValue instanceof Error ? currentValue.message : currentValue}`);
}, new Error(''));
}
private checkForDependenciesAndUninstall(extension: ILocalExtension, installed: ILocalExtension[], force: boolean): TPromise<void> {
@@ -309,7 +322,7 @@ export class ExtensionManagementService implements IExtensionManagementService {
.then(() => this.hasDependencies(extension, installed) ? this.promptForDependenciesAndUninstall(extension, installed, force) : this.promptAndUninstall(extension, installed, force))
.then(() => this.postUninstallExtension(extension),
error => {
this.postUninstallExtension(extension, error);
this.postUninstallExtension(extension, INSTALL_ERROR_LOCAL);
return TPromise.wrapError(error);
});
}
@@ -371,7 +384,7 @@ export class ExtensionManagementService implements IExtensionManagementService {
if (dependents.length) {
return TPromise.wrapError<void>(new Error(this.getDependentsErrorMessage(extension, dependents)));
}
return TPromise.join([this.uninstallExtension(extension.id), ...dependenciesToUninstall.map(d => this.doUninstall(d))]).then(() => null);
return TPromise.join([this.uninstallExtension(extension.identifier), ...dependenciesToUninstall.map(d => this.doUninstall(d))]).then(() => null);
}
private getDependentsErrorMessage(extension: ILocalExtension, dependents: ILocalExtension[]): string {
@@ -422,34 +435,37 @@ export class ExtensionManagementService implements IExtensionManagementService {
private doUninstall(extension: ILocalExtension): TPromise<void> {
return this.preUninstallExtension(extension)
.then(() => this.uninstallExtension(extension.id))
.then(() => this.uninstallExtension(extension.identifier))
.then(() => this.postUninstallExtension(extension),
error => {
this.postUninstallExtension(extension, error);
this.postUninstallExtension(extension, INSTALL_ERROR_LOCAL);
return TPromise.wrapError(error);
});
}
private preUninstallExtension(extension: ILocalExtension): TPromise<void> {
const extensionPath = path.join(this.extensionsPath, extension.id);
const extensionPath = path.join(this.extensionsPath, extension.identifier.id);
return pfs.exists(extensionPath)
.then(exists => exists ? null : TPromise.wrapError(new Error(nls.localize('notExists', "Could not find extension"))))
.then(() => this._onUninstallExtension.fire(extension.id));
.then(() => this._onUninstallExtension.fire(extension.identifier));
}
private uninstallExtension(id: string): TPromise<void> {
private uninstallExtension({ id }: IExtensionIdentifier): TPromise<void> {
const extensionPath = path.join(this.extensionsPath, id);
return this.setObsolete(id)
.then(() => pfs.rimraf(extensionPath))
.then(() => this.unsetObsolete(id));
}
private async postUninstallExtension(extension: ILocalExtension, error?: any): TPromise<void> {
private async postUninstallExtension(extension: ILocalExtension, error?: string): TPromise<void> {
if (!error) {
await this.galleryService.reportStatistic(extension.manifest.publisher, extension.manifest.name, extension.manifest.version, StatisticType.Uninstall);
// only report if extension has a mapped gallery extension. UUID identifies the gallery extension.
if (extension.identifier.uuid) {
await this.galleryService.reportStatistic(extension.manifest.publisher, extension.manifest.name, extension.manifest.version, StatisticType.Uninstall);
}
}
this._onDidUninstallExtension.fire({ id: extension.id, error });
this._onDidUninstallExtension.fire({ identifier: extension.identifier, error });
}
getInstalled(type: LocalExtensionType = null): TPromise<ILocalExtension[]> {
@@ -495,7 +511,8 @@ export class ExtensionManagementService implements IExtensionManagementService {
if (manifest.extensionDependencies) {
manifest.extensionDependencies = manifest.extensionDependencies.map(id => adoptToGalleryExtensionId(id));
}
return { type, id, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl };
const identifier = { id, uuid: metadata ? metadata.id : null };
return { type, identifier, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl };
});
}).then(null, () => null);
@@ -599,3 +616,15 @@ export class ExtensionManagementService implements IExtensionManagementService {
this.disposables = dispose(this.disposables);
}
}
export function getLocalExtensionIdFromGallery(extension: IGalleryExtension, version: string): string {
return getLocalExtensionId(extension.identifier.id, version);
}
export function getLocalExtensionIdFromManifest(manifest: IExtensionManifest): string {
return getLocalExtensionId(getGalleryExtensionId(manifest.publisher, manifest.name), manifest.version);
}
function getLocalExtensionId(id: string, version: string): string {
return `${id}-${version}`;
}

View File

@@ -12,7 +12,7 @@ import { TestInstantiationService } from 'vs/platform/instantiation/test/common/
import { Emitter } from 'vs/base/common/event';
import { StorageService, InMemoryLocalStorage } from 'vs/platform/storage/common/storageService';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
function storageService(instantiationService: TestInstantiationService): IStorageService {
@@ -21,9 +21,7 @@ function storageService(instantiationService: TestInstantiationService): IStorag
let workspaceContextService = instantiationService.get(IWorkspaceContextService);
if (!workspaceContextService) {
workspaceContextService = instantiationService.stub(IWorkspaceContextService, <IWorkspaceContextService>{
hasWorkspace: () => {
return true;
},
getWorkbenchState: () => WorkbenchState.FOLDER,
});
}
service = instantiationService.stub(IStorageService, instantiationService.createInstance(StorageService, new InMemoryLocalStorage(), new InMemoryLocalStorage()));
@@ -71,22 +69,22 @@ suite('ExtensionEnablementService Test', () => {
});
test('test when no extensions are disabled for workspace when there is no workspace', (done) => {
testObject.setEnablement('pub.a', false, true)
testObject.setEnablement({ id: 'pub.a' }, false, true)
.then(() => {
instantiationService.stub(IWorkspaceContextService, 'hasWorkspace', false);
instantiationService.stub(IWorkspaceContextService, 'getWorkbenchState', WorkbenchState.EMPTY);
assert.deepEqual([], testObject.getWorkspaceDisabledExtensions());
})
.then(done, done);
});
test('test disable an extension globally', (done) => {
testObject.setEnablement('pub.a', false)
.then(() => assert.deepEqual(['pub.a'], testObject.getGloballyDisabledExtensions()))
testObject.setEnablement({ id: 'pub.a' }, false)
.then(() => assert.deepEqual([{ id: 'pub.a' }], testObject.getGloballyDisabledExtensions()))
.then(done, done);
});
test('test disable an extension globally should return truthy promise', (done) => {
testObject.setEnablement('pub.a', false)
testObject.setEnablement({ id: 'pub.a' }, false)
.then(value => assert.ok(value))
.then(done, done);
});
@@ -94,180 +92,180 @@ suite('ExtensionEnablementService Test', () => {
test('test disable an extension globally triggers the change event', (done) => {
const target = sinon.spy();
testObject.onEnablementChanged(target);
testObject.setEnablement('pub.a', false)
.then(() => assert.ok(target.calledWithExactly('pub.a')))
testObject.setEnablement({ id: 'pub.a' }, false)
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.a' })))
.then(done, done);
});
test('test disable an extension globally again should return a falsy promise', (done) => {
testObject.setEnablement('pub.a', false)
.then(() => testObject.setEnablement('pub.a', false))
testObject.setEnablement({ id: 'pub.a' }, false)
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
.then(value => assert.ok(!value))
.then(done, done);
});
test('test disable an extension for workspace', (done) => {
testObject.setEnablement('pub.a', false, true)
.then(() => assert.deepEqual(['pub.a'], testObject.getWorkspaceDisabledExtensions()))
testObject.setEnablement({ id: 'pub.a' }, false, true)
.then(() => assert.deepEqual([{ id: 'pub.a' }], testObject.getWorkspaceDisabledExtensions()))
.then(done, done);
});
test('test disable an extension for workspace returns a truthy promise', (done) => {
testObject.setEnablement('pub.a', false, true)
testObject.setEnablement({ id: 'pub.a' }, false, true)
.then(value => assert.ok(value))
.then(done, done);
});
test('test disable an extension for workspace again should return a falsy promise', (done) => {
testObject.setEnablement('pub.a', false, true)
.then(() => testObject.setEnablement('pub.a', false, true))
testObject.setEnablement({ id: 'pub.a' }, false, true)
.then(() => testObject.setEnablement({ id: 'pub.a' }, false, true))
.then(value => assert.ok(!value))
.then(done, done);
});
test('test disable an extension for workspace and then globally', (done) => {
testObject.setEnablement('pub.a', false, true)
.then(() => testObject.setEnablement('pub.a', false))
testObject.setEnablement({ id: 'pub.a' }, false, true)
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
.then(() => {
assert.deepEqual(['pub.a'], testObject.getWorkspaceDisabledExtensions());
assert.deepEqual(['pub.a'], testObject.getGloballyDisabledExtensions());
assert.deepEqual([{ id: 'pub.a' }], testObject.getWorkspaceDisabledExtensions());
assert.deepEqual([{ id: 'pub.a' }], testObject.getGloballyDisabledExtensions());
})
.then(done, done);
});
test('test disable an extension for workspace and then globally return a truthy promise', (done) => {
testObject.setEnablement('pub.a', false, true)
.then(() => testObject.setEnablement('pub.a', false))
testObject.setEnablement({ id: 'pub.a' }, false, true)
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
.then(value => assert.ok(value))
.then(done, done);
});
test('test disable an extension for workspace and then globally triggers the change event', (done) => {
const target = sinon.spy();
testObject.setEnablement('pub.a', false, true)
testObject.setEnablement({ id: 'pub.a' }, false, true)
.then(() => testObject.onEnablementChanged(target))
.then(() => testObject.setEnablement('pub.a', false))
.then(() => assert.ok(target.calledWithExactly('pub.a')))
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.a' })))
.then(done, done);
});
test('test disable an extension globally and then for workspace', (done) => {
testObject.setEnablement('pub.a', false)
.then(() => testObject.setEnablement('pub.a', false, true))
testObject.setEnablement({ id: 'pub.a' }, false)
.then(() => testObject.setEnablement({ id: 'pub.a' }, false, true))
.then(() => {
assert.deepEqual(['pub.a'], testObject.getWorkspaceDisabledExtensions());
assert.deepEqual(['pub.a'], testObject.getGloballyDisabledExtensions());
assert.deepEqual([{ id: 'pub.a' }], testObject.getWorkspaceDisabledExtensions());
assert.deepEqual([{ id: 'pub.a' }], testObject.getGloballyDisabledExtensions());
})
.then(done, done);
});
test('test disable an extension globally and then for workspace return a truthy promise', (done) => {
testObject.setEnablement('pub.a', false)
.then(() => testObject.setEnablement('pub.a', false, true))
testObject.setEnablement({ id: 'pub.a' }, false)
.then(() => testObject.setEnablement({ id: 'pub.a' }, false, true))
.then(value => assert.ok(value))
.then(done, done);
});
test('test disable an extension globally and then for workspace triggers the change event', (done) => {
const target = sinon.spy();
testObject.setEnablement('pub.a', false)
testObject.setEnablement({ id: 'pub.a' }, false)
.then(() => testObject.onEnablementChanged(target))
.then(() => testObject.setEnablement('pub.a', false, true))
.then(() => assert.ok(target.calledWithExactly('pub.a')))
.then(() => testObject.setEnablement({ id: 'pub.a' }, false, true))
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.a' })))
.then(done, done);
});
test('test disable an extension for workspace when there is no workspace throws error', (done) => {
instantiationService.stub(IWorkspaceContextService, 'hasWorkspace', false);
testObject.setEnablement('pub.a', false, true)
instantiationService.stub(IWorkspaceContextService, 'getWorkbenchState', WorkbenchState.EMPTY);
testObject.setEnablement({ id: 'pub.a' }, false, true)
.then(() => assert.fail('should throw an error'), error => assert.ok(error))
.then(done, done);
});
test('test enable an extension globally', (done) => {
testObject.setEnablement('pub.a', false)
.then(() => testObject.setEnablement('pub.a', true))
testObject.setEnablement({ id: 'pub.a' }, false)
.then(() => testObject.setEnablement({ id: 'pub.a' }, true))
.then(() => assert.deepEqual([], testObject.getGloballyDisabledExtensions()))
.then(done, done);
});
test('test enable an extension globally return truthy promise', (done) => {
testObject.setEnablement('pub.a', false)
.then(() => testObject.setEnablement('pub.a', true))
testObject.setEnablement({ id: 'pub.a' }, false)
.then(() => testObject.setEnablement({ id: 'pub.a' }, true))
.then(value => assert.ok(value))
.then(done, done);
});
test('test enable an extension globally triggers change event', (done) => {
const target = sinon.spy();
testObject.setEnablement('pub.a', false)
testObject.setEnablement({ id: 'pub.a' }, false)
.then(() => testObject.onEnablementChanged(target))
.then(() => testObject.setEnablement('pub.a', true))
.then(() => assert.ok(target.calledWithExactly('pub.a')))
.then(() => testObject.setEnablement({ id: 'pub.a' }, true))
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.a' })))
.then(done, done);
});
test('test enable an extension globally when already enabled return falsy promise', (done) => {
testObject.setEnablement('pub.a', true)
testObject.setEnablement({ id: 'pub.a' }, true)
.then(value => assert.ok(!value))
.then(done, done);
});
test('test enable an extension for workspace', (done) => {
testObject.setEnablement('pub.a', false, true)
.then(() => testObject.setEnablement('pub.a', true, true))
testObject.setEnablement({ id: 'pub.a' }, false, true)
.then(() => testObject.setEnablement({ id: 'pub.a' }, true, true))
.then(() => assert.deepEqual([], testObject.getWorkspaceDisabledExtensions()))
.then(done, done);
});
test('test enable an extension for workspace return truthy promise', (done) => {
testObject.setEnablement('pub.a', false, true)
.then(() => testObject.setEnablement('pub.a', true, true))
testObject.setEnablement({ id: 'pub.a' }, false, true)
.then(() => testObject.setEnablement({ id: 'pub.a' }, true, true))
.then(value => assert.ok(value))
.then(done, done);
});
test('test enable an extension for workspace triggers change event', (done) => {
const target = sinon.spy();
testObject.setEnablement('pub.b', false, true)
testObject.setEnablement({ id: 'pub.b' }, false, true)
.then(() => testObject.onEnablementChanged(target))
.then(() => testObject.setEnablement('pub.b', true, true))
.then(() => assert.ok(target.calledWithExactly('pub.b')))
.then(() => testObject.setEnablement({ id: 'pub.b' }, true, true))
.then(() => assert.ok(target.calledWithExactly({ id: 'pub.b' })))
.then(done, done);
});
test('test enable an extension for workspace when already enabled return falsy promise', (done) => {
testObject.setEnablement('pub.a', true, true)
testObject.setEnablement({ id: 'pub.a' }, true, true)
.then(value => assert.ok(!value))
.then(done, done);
});
test('test enable an extension for workspace when disabled in workspace and gloablly', (done) => {
testObject.setEnablement('pub.a', false, true)
.then(() => testObject.setEnablement('pub.a', false))
.then(() => testObject.setEnablement('pub.a', true, true))
testObject.setEnablement({ id: 'pub.a' }, false, true)
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
.then(() => testObject.setEnablement({ id: 'pub.a' }, true, true))
.then(() => {
assert.deepEqual(['pub.a'], testObject.getGloballyDisabledExtensions());
assert.deepEqual([{ id: 'pub.a' }], testObject.getGloballyDisabledExtensions());
assert.deepEqual([], testObject.getWorkspaceDisabledExtensions());
})
.then(done, done);
});
test('test enable an extension globally when disabled in workspace and gloablly', (done) => {
testObject.setEnablement('pub.a', false, true)
.then(() => testObject.setEnablement('pub.a', false))
.then(() => testObject.setEnablement('pub.a', true))
testObject.setEnablement({ id: 'pub.a' }, false, true)
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
.then(() => testObject.setEnablement({ id: 'pub.a' }, true))
.then(() => {
assert.deepEqual(['pub.a'], testObject.getWorkspaceDisabledExtensions());
assert.deepEqual([{ id: 'pub.a' }], testObject.getWorkspaceDisabledExtensions());
assert.deepEqual([], testObject.getGloballyDisabledExtensions());
})
.then(done, done);
});
test('test remove an extension from disablement list when uninstalled', (done) => {
testObject.setEnablement('pub.a', false, true)
.then(() => testObject.setEnablement('pub.a', false))
.then(() => didUninstallEvent.fire({ id: 'pub.a-1.0.0' }))
testObject.setEnablement({ id: 'pub.a' }, false, true)
.then(() => testObject.setEnablement({ id: 'pub.a' }, false))
.then(() => didUninstallEvent.fire({ identifier: { id: 'pub.a-1.0.0' } }))
.then(() => {
assert.deepEqual([], testObject.getWorkspaceDisabledExtensions());
assert.deepEqual([], testObject.getGloballyDisabledExtensions());