Merge VS Code 1.31.1 (#4283)

This commit is contained in:
Matt Irvine
2019-03-15 13:09:45 -07:00
committed by GitHub
parent 7d31575149
commit 86bac90001
1716 changed files with 53308 additions and 48375 deletions

View File

@@ -9,7 +9,6 @@ import pkg from 'vs/platform/node/package';
import * as path from 'path';
import * as semver from 'semver';
import { TPromise } from 'vs/base/common/winjs.base';
import { sequence } from 'vs/base/common/async';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
@@ -17,7 +16,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IExtensionManagementService, IExtensionGalleryService, IExtensionManifest, IGalleryExtension, LocalExtensionType } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IExtensionManagementService, IExtensionGalleryService, IGalleryExtension } from 'vs/platform/extensionManagement/common/extensionManagement';
import { ExtensionManagementService } from 'vs/platform/extensionManagement/node/extensionManagementService';
import { ExtensionGalleryService } from 'vs/platform/extensionManagement/node/extensionGalleryService';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
@@ -36,9 +35,10 @@ import { StateService } from 'vs/platform/state/node/stateService';
import { createSpdLogService } from 'vs/platform/log/node/spdlogService';
import { ILogService, getLogLevel } from 'vs/platform/log/common/log';
import { isPromiseCanceledError } from 'vs/base/common/errors';
import { areSameExtensions, getGalleryExtensionIdFromLocal, adoptToGalleryExtensionId, getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { areSameExtensions, adoptToGalleryExtensionId, getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { URI } from 'vs/base/common/uri';
import { getManifest } from 'vs/platform/extensionManagement/node/extensionManagementUtil';
import { IExtensionManifest, ExtensionType } from 'vs/platform/extensions/common/extensions';
const notFound = (id: string) => localize('notFound', "Extension '{0}' not found.", id);
const notInstalled = (id: string) => localize('notInstalled', "Extension '{0}' is not installed.", id);
@@ -54,161 +54,164 @@ function getId(manifest: IExtensionManifest, withVersion?: boolean): string {
const EXTENSION_ID_REGEX = /^([^.]+\..+)@(\d+\.\d+\.\d+(-.*)?)$/;
export function getIdAndVersion(id: string): [string, string] {
export function getIdAndVersion(id: string): [string, string | undefined] {
const matches = EXTENSION_ID_REGEX.exec(id);
if (matches && matches[1]) {
return [adoptToGalleryExtensionId(matches[1]), matches[2]];
}
return [adoptToGalleryExtensionId(id), void 0];
return [adoptToGalleryExtensionId(id), undefined];
}
type Task = { (): TPromise<void> };
class Main {
export class Main {
constructor(
@IEnvironmentService private environmentService: IEnvironmentService,
@IExtensionManagementService private extensionManagementService: IExtensionManagementService,
@IExtensionGalleryService private extensionGalleryService: IExtensionGalleryService
@IEnvironmentService private readonly environmentService: IEnvironmentService,
@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService
) { }
run(argv: ParsedArgs): TPromise<any> {
// TODO@joao - make this contributable
let returnPromise: TPromise<any>;
async run(argv: ParsedArgs): Promise<any> {
if (argv['install-source']) {
returnPromise = this.setInstallSource(argv['install-source']);
await this.setInstallSource(argv['install-source']);
} else if (argv['list-extensions']) {
returnPromise = this.listExtensions(argv['show-versions']);
await this.listExtensions(!!argv['show-versions']);
} else if (argv['install-extension']) {
const arg = argv['install-extension'];
const args: string[] = typeof arg === 'string' ? [arg] : arg;
returnPromise = this.installExtension(args, argv['force']);
await this.installExtensions(args, argv['force']);
} else if (argv['uninstall-extension']) {
const arg = argv['uninstall-extension'];
const ids: string[] = typeof arg === 'string' ? [arg] : arg;
returnPromise = this.uninstallExtension(ids);
await this.uninstallExtension(ids);
}
return returnPromise || TPromise.as(null);
}
private setInstallSource(installSource: string): TPromise<any> {
private setInstallSource(installSource: string): Promise<any> {
return writeFile(this.environmentService.installSourcePath, installSource.slice(0, 30));
}
private listExtensions(showVersions: boolean): TPromise<any> {
return this.extensionManagementService.getInstalled(LocalExtensionType.User).then(extensions => {
extensions.forEach(e => console.log(getId(e.manifest, showVersions)));
});
private async listExtensions(showVersions: boolean): Promise<any> {
const extensions = await this.extensionManagementService.getInstalled(ExtensionType.User);
extensions.forEach(e => console.log(getId(e.manifest, showVersions)));
}
private installExtension(extensions: string[], force: boolean): TPromise<any> {
const vsixTasks: Task[] = extensions
.filter(e => /\.vsix$/i.test(e))
.map(id => () => {
const extension = path.isAbsolute(id) ? id : path.join(process.cwd(), id);
return this.validate(extension, force)
.then(valid => {
if (valid) {
return this.extensionManagementService.install(URI.file(extension)).then(() => {
console.log(localize('successVsixInstall', "Extension '{0}' was successfully installed!", getBaseLabel(extension)));
}, error => {
if (isPromiseCanceledError(error)) {
console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", getBaseLabel(extension)));
return null;
} else {
return TPromise.wrapError(error);
}
});
}
return null;
});
});
private async installExtensions(extensions: string[], force: boolean): Promise<void> {
let failed: string[] = [];
for (const extension of extensions) {
try {
await this.installExtension(extension, force);
} catch (err) {
console.error(err.message || err.stack || err);
failed.push(extension);
}
}
return failed.length ? Promise.reject(localize('installation failed', "Failed Installing Extensions: {0}", failed.join(', '))) : Promise.resolve();
}
const galleryTasks: Task[] = extensions
.filter(e => !/\.vsix$/i.test(e))
.map(e => () => {
const [id, version] = getIdAndVersion(e);
return this.extensionManagementService.getInstalled(LocalExtensionType.User)
.then(installed => this.extensionGalleryService.getExtension({ id }, version)
.then<IGalleryExtension>(null, err => {
if (err.responseText) {
try {
const response = JSON.parse(err.responseText);
return TPromise.wrapError(response.message);
} catch (e) {
// noop
}
}
return TPromise.wrapError(err);
})
.then(extension => {
if (!extension) {
return TPromise.wrapError(new Error(`${notFound(version ? `${id}@${version}` : id)}\n${useId}`));
}
private installExtension(extension: string, force: boolean): Promise<any> {
if (/\.vsix$/i.test(extension)) {
extension = path.isAbsolute(extension) ? extension : path.join(process.cwd(), extension);
const [installedExtension] = installed.filter(e => areSameExtensions({ id: getGalleryExtensionIdFromLocal(e) }, { id }));
if (installedExtension) {
if (extension.version !== installedExtension.manifest.version) {
if (version || force) {
console.log(localize('updateMessage', "Updating the Extension '{0}' to the version {1}", id, extension.version));
return this.installFromGallery(id, extension);
} else {
console.log(localize('forceUpdate', "Extension '{0}' v{1} is already installed, but a newer version {2} is available in the marketplace. Use '--force' option to update to newer version.", id, installedExtension.manifest.version, extension.version));
return Promise.resolve(null);
}
} else {
console.log(localize('alreadyInstalled', "Extension '{0}' is already installed.", version ? `${id}@${version}` : id));
return TPromise.as(null);
}
return this.validate(extension, force)
.then(valid => {
if (valid) {
return this.extensionManagementService.install(URI.file(extension)).then(() => {
console.log(localize('successVsixInstall', "Extension '{0}' was successfully installed!", getBaseLabel(extension)));
}, error => {
if (isPromiseCanceledError(error)) {
console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", getBaseLabel(extension)));
return null;
} else {
console.log(localize('foundExtension', "Found '{0}' in the marketplace.", id));
return this.installFromGallery(id, extension);
return Promise.reject(error);
}
}));
});
return sequence([...vsixTasks, ...galleryTasks]);
}
private validate(vsix: string, force: boolean): Thenable<boolean> {
return getManifest(vsix)
.then(manifest => {
if (manifest) {
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
return this.extensionManagementService.getInstalled(LocalExtensionType.User)
.then(installedExtensions => {
const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, { id: getGalleryExtensionIdFromLocal(local) }) && semver.gt(local.manifest.version, manifest.version))[0];
if (newer && !force) {
console.log(localize('forceDowngrade', "A newer version of this extension '{0}' v{1} is already installed. Use '--force' option to downgrade to older version.", newer.galleryIdentifier.id, newer.manifest.version, manifest.version));
return false;
}
return true;
});
} else {
return Promise.reject(new Error('Invalid vsix'));
}
});
}
private installFromGallery(id: string, extension: IGalleryExtension): TPromise<void> {
console.log(localize('installing', "Installing..."));
return this.extensionManagementService.installFromGallery(extension)
.then(
() => console.log(localize('successInstall', "Extension '{0}' v{1} was successfully installed!", id, extension.version)),
error => {
if (isPromiseCanceledError(error)) {
console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", id));
return null;
} else {
return TPromise.wrapError(error);
}
return null;
});
}
const [id, version] = getIdAndVersion(extension);
return this.extensionManagementService.getInstalled(ExtensionType.User)
.then(installed => this.extensionGalleryService.getCompatibleExtension({ id }, version)
.then<IGalleryExtension>(null, err => {
if (err.responseText) {
try {
const response = JSON.parse(err.responseText);
return Promise.reject(response.message);
} catch (e) {
// noop
}
}
return Promise.reject(err);
})
.then(extension => {
if (!extension) {
return Promise.reject(new Error(`${notFound(version ? `${id}@${version}` : id)}\n${useId}`));
}
const [installedExtension] = installed.filter(e => areSameExtensions(e.identifier, { id }));
if (installedExtension) {
if (extension.version !== installedExtension.manifest.version) {
if (version || force) {
console.log(localize('updateMessage', "Updating the Extension '{0}' to the version {1}", id, extension.version));
return this.installFromGallery(id, extension);
} else {
console.log(localize('forceUpdate', "Extension '{0}' v{1} is already installed, but a newer version {2} is available in the marketplace. Use '--force' option to update to newer version.", id, installedExtension.manifest.version, extension.version));
return Promise.resolve(null);
}
} else {
console.log(localize('alreadyInstalled', "Extension '{0}' is already installed.", version ? `${id}@${version}` : id));
return Promise.resolve(null);
}
} else {
console.log(localize('foundExtension', "Found '{0}' in the marketplace.", id));
return this.installFromGallery(id, extension);
}
}));
}
private uninstallExtension(extensions: string[]): TPromise<any> {
private async validate(vsix: string, force: boolean): Promise<boolean> {
const manifest = await getManifest(vsix);
if (!manifest) {
throw new Error('Invalid vsix');
}
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
const installedExtensions = await this.extensionManagementService.getInstalled(ExtensionType.User);
const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, local.identifier) && semver.gt(local.manifest.version, manifest.version))[0];
if (newer && !force) {
console.log(localize('forceDowngrade', "A newer version of this extension '{0}' v{1} is already installed. Use '--force' option to downgrade to older version.", newer.identifier.id, newer.manifest.version, manifest.version));
return false;
}
return true;
}
private async installFromGallery(id: string, extension: IGalleryExtension): Promise<void> {
console.log(localize('installing', "Installing..."));
try {
await this.extensionManagementService.installFromGallery(extension);
console.log(localize('successInstall', "Extension '{0}' v{1} was successfully installed!", id, extension.version));
} catch (error) {
if (isPromiseCanceledError(error)) {
console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", id));
} else {
throw error;
}
}
}
private uninstallExtension(extensions: string[]): Promise<any> {
async function getExtensionId(extensionDescription: string): Promise<string> {
if (!/\.vsix$/i.test(extensionDescription)) {
return extensionDescription;
@@ -221,11 +224,11 @@ class Main {
return sequence(extensions.map(extension => () => {
return getExtensionId(extension).then(id => {
return this.extensionManagementService.getInstalled(LocalExtensionType.User).then(installed => {
const [extension] = installed.filter(e => areSameExtensions({ id: getGalleryExtensionIdFromLocal(e) }, { id }));
return this.extensionManagementService.getInstalled(ExtensionType.User).then(installed => {
const [extension] = installed.filter(e => areSameExtensions(e.identifier, { id }));
if (!extension) {
return TPromise.wrapError(new Error(`${notInstalled(id)}\n${useId}`));
return Promise.reject(new Error(`${notInstalled(id)}\n${useId}`));
}
console.log(localize('uninstalling', "Uninstalling {0}...", id));
@@ -240,7 +243,7 @@ class Main {
const eventPrefix = 'monacoworkbench';
export function main(argv: ParsedArgs): TPromise<void> {
export function main(argv: ParsedArgs): Promise<void> {
const services = new ServiceCollection();
const environmentService = new EnvironmentService(argv, process.execPath);
@@ -259,13 +262,13 @@ export function main(argv: ParsedArgs): TPromise<void> {
const envService = accessor.get(IEnvironmentService);
const stateService = accessor.get(IStateService);
return TPromise.join([envService.appSettingsHome, envService.extensionsPath].map(p => mkdirp(p))).then(() => {
return Promise.all([envService.appSettingsHome, envService.extensionsPath].map(p => mkdirp(p))).then(() => {
const { appRoot, extensionsPath, extensionDevelopmentLocationURI, isBuilt, installSourcePath } = envService;
const services = new ServiceCollection();
services.set(IConfigurationService, new SyncDescriptor(ConfigurationService));
services.set(IRequestService, new SyncDescriptor(RequestService));
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService));
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService, [false]));
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService));
const appenders: AppInsightsAppender[] = [];