@@ -45,7 +45,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
4545import { getManifest } from 'vs/platform/extensionManagement/node/extensionManagementUtil' ;
4646import { IExtensionManifest , ExtensionType } from 'vs/platform/extensions/common/extensions' ;
4747import { ExtensionsDownloader } from 'vs/platform/extensionManagement/node/extensionDownloader' ;
48- import { ExtensionsScanner } from 'vs/platform/extensionManagement/node/extensionsScanner' ;
48+ import { ExtensionsScanner , IMetadata } from 'vs/platform/extensionManagement/node/extensionsScanner' ;
4949import { ExtensionsLifecycle } from 'vs/platform/extensionManagement/node/extensionLifecycle' ;
5050
5151const INSTALL_ERROR_UNSET_UNINSTALLED = 'unsetUninstalled' ;
@@ -57,7 +57,7 @@ const ERROR_UNKNOWN = 'unknown';
5757interface InstallableExtension {
5858 zipPath : string ;
5959 identifierWithVersion : ExtensionIdentifierWithVersion ;
60- metadata : IGalleryMetadata | null ;
60+ metadata ?: IMetadata ;
6161}
6262
6363export class ExtensionManagementService extends Disposable implements IExtensionManagementService {
@@ -152,7 +152,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
152152
153153 }
154154
155- install ( vsix : URI ) : Promise < ILocalExtension > {
155+ install ( vsix : URI , isDefault : boolean = false ) : Promise < ILocalExtension > {
156156 this . logService . trace ( 'ExtensionManagementService#install' , vsix . toString ( ) ) ;
157157 return createCancelablePromise ( token => {
158158 return this . downloadVsix ( vsix ) . then ( downloadLocation => {
@@ -192,10 +192,10 @@ export class ExtensionManagementService extends Disposable implements IExtension
192192 . then ( ( ) => {
193193 this . logService . info ( 'Installing the extension:' , identifier . id ) ;
194194 this . _onInstallExtension . fire ( { identifier, zipPath } ) ;
195- return this . getMetadata ( getGalleryExtensionId ( manifest . publisher , manifest . name ) )
195+ return this . getGalleryMetadata ( getGalleryExtensionId ( manifest . publisher , manifest . name ) )
196196 . then (
197- metadata => this . installFromZipPath ( identifierWithVersion , zipPath , metadata , operation , token ) ,
198- ( ) => this . installFromZipPath ( identifierWithVersion , zipPath , null , operation , token ) )
197+ metadata => this . installFromZipPath ( identifierWithVersion , zipPath , { ... metadata , isDefault } , operation , token ) ,
198+ ( ) => this . installFromZipPath ( identifierWithVersion , zipPath , { isDefault } , operation , token ) )
199199 . then (
200200 local => { this . logService . info ( 'Successfully installed the extension:' , identifier . id ) ; return local ; } ,
201201 e => {
@@ -219,7 +219,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
219219 return this . downloadService . download ( vsix , URI . file ( downloadedLocation ) ) . then ( ( ) => URI . file ( downloadedLocation ) ) ;
220220 }
221221
222- private installFromZipPath ( identifierWithVersion : ExtensionIdentifierWithVersion , zipPath : string , metadata : IGalleryMetadata | null , operation : InstallOperation , token : CancellationToken ) : Promise < ILocalExtension > {
222+ private installFromZipPath ( identifierWithVersion : ExtensionIdentifierWithVersion , zipPath : string , metadata : IMetadata , operation : InstallOperation , token : CancellationToken ) : Promise < ILocalExtension > {
223223 return this . toNonCancellablePromise ( this . installExtension ( { zipPath, identifierWithVersion, metadata } , token )
224224 . then ( local => this . installDependenciesAndPackExtensions ( local , null )
225225 . then (
@@ -239,7 +239,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
239239 ) ) ;
240240 }
241241
242- async installFromGallery ( extension : IGalleryExtension ) : Promise < ILocalExtension > {
242+ async installFromGallery ( extension : IGalleryExtension , isDefault ?: boolean ) : Promise < ILocalExtension > {
243243 if ( ! this . galleryService . isEnabled ( ) ) {
244244 return Promise . reject ( new Error ( nls . localize ( 'MarketPlaceDisabled' , "Marketplace is not enabled" ) ) ) ;
245245 }
@@ -287,8 +287,11 @@ export class ExtensionManagementService extends Disposable implements IExtension
287287 }
288288
289289 this . downloadInstallableExtension ( extension , operation )
290- . then ( installableExtension => this . installExtension ( installableExtension , cancellationToken )
291- . then ( local => this . extensionsDownloader . delete ( URI . file ( installableExtension . zipPath ) ) . finally ( ( ) => { } ) . then ( ( ) => local ) ) )
290+ . then ( installableExtension => {
291+ installableExtension . metadata . isDefault = isDefault !== undefined ? isDefault : existingExtension . isDefault ;
292+ return this . installExtension ( installableExtension , cancellationToken )
293+ . then ( local => this . extensionsDownloader . delete ( URI . file ( installableExtension . zipPath ) ) . finally ( ( ) => { } ) . then ( ( ) => local ) ) ;
294+ } )
292295 . then ( local => this . installDependenciesAndPackExtensions ( local , existingExtension )
293296 . then ( ( ) => local , error => this . uninstall ( local , true ) . then ( ( ) => Promise . reject ( error ) , ( ) => Promise . reject ( error ) ) ) )
294297 . then (
@@ -358,7 +361,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
358361 . then ( report => getMaliciousExtensionsSet ( report ) . has ( extension . identifier . id ) ) ;
359362 }
360363
361- private downloadInstallableExtension ( extension : IGalleryExtension , operation : InstallOperation ) : Promise < InstallableExtension > {
364+ private downloadInstallableExtension ( extension : IGalleryExtension , operation : InstallOperation ) : Promise < Required < InstallableExtension > > {
362365 const metadata = < IGalleryMetadata > {
363366 id : extension . identifier . uuid ,
364367 publisherId : extension . publisherId ,
@@ -373,7 +376,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
373376 this . logService . info ( 'Downloaded extension:' , extension . identifier . id , zipPath ) ;
374377 return getManifest ( zipPath )
375378 . then (
376- manifest => ( < InstallableExtension > { zipPath, identifierWithVersion : new ExtensionIdentifierWithVersion ( extension . identifier , manifest . version ) , metadata } ) ,
379+ manifest => ( < Required < InstallableExtension > > { zipPath, identifierWithVersion : new ExtensionIdentifierWithVersion ( extension . identifier , manifest . version ) , metadata } ) ,
377380 error => Promise . reject ( new ExtensionManagementError ( this . joinErrors ( error ) . message , INSTALL_ERROR_VALIDATING ) )
378381 ) ;
379382 } ,
@@ -419,8 +422,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
419422 let local = await this . extensionsScanner . extractUserExtension ( identifierWithVersion , zipPath , token ) ;
420423 this . logService . info ( 'Installation completed.' , identifier . id ) ;
421424 if ( metadata ) {
422- this . setMetadata ( local , metadata ) ;
423- local = await this . extensionsScanner . saveMetadataForLocalExtension ( local ) ;
425+ local = await this . extensionsScanner . saveMetadataForLocalExtension ( local , metadata ) ;
424426 }
425427 return local ;
426428 }
@@ -481,15 +483,14 @@ export class ExtensionManagementService extends Disposable implements IExtension
481483
482484 async updateMetadata ( local : ILocalExtension , metadata : IGalleryMetadata ) : Promise < ILocalExtension > {
483485 this . logService . trace ( 'ExtensionManagementService#updateMetadata' , local . identifier . id ) ;
484- local . metadata = metadata ;
485- local = await this . extensionsScanner . saveMetadataForLocalExtension ( local ) ;
486+ local = await this . extensionsScanner . saveMetadataForLocalExtension ( local , { ...metadata , isDefault : local . isDefault } ) ;
486487 this . manifestCache . invalidate ( ) ;
487488 return local ;
488489 }
489490
490- private getMetadata ( extensionName : string ) : Promise < IGalleryMetadata | null > {
491+ private getGalleryMetadata ( extensionName : string ) : Promise < IGalleryMetadata | undefined > {
491492 return this . findGalleryExtensionByName ( extensionName )
492- . then ( galleryExtension => galleryExtension ? < IGalleryMetadata > { id : galleryExtension . identifier . uuid , publisherDisplayName : galleryExtension . publisherDisplayName , publisherId : galleryExtension . publisherId } : null ) ;
493+ . then ( galleryExtension => galleryExtension ? < IGalleryMetadata > { id : galleryExtension . identifier . uuid , publisherDisplayName : galleryExtension . publisherDisplayName , publisherId : galleryExtension . publisherId } : undefined ) ;
493494 }
494495
495496 private findGalleryExtension ( local : ILocalExtension ) : Promise < IGalleryExtension > {
@@ -629,11 +630,6 @@ export class ExtensionManagementService extends Disposable implements IExtension
629630 return this . extensionsScanner . scanExtensions ( type ) ;
630631 }
631632
632- private setMetadata ( local : ILocalExtension , metadata : IGalleryMetadata ) : void {
633- local . metadata = metadata ;
634- local . identifier . uuid = metadata . id ;
635- }
636-
637633 removeDeprecatedExtensions ( ) : Promise < void > {
638634 return this . extensionsScanner . cleanUp ( ) ;
639635 }
0 commit comments