Merge from vscode fcf3346a8e9f5ee1e00674461d9e2c2292a14ee3 (#12295)

* Merge from vscode fcf3346a8e9f5ee1e00674461d9e2c2292a14ee3

* Fix test build break

* Update distro

* Fix build errors

* Update distro

* Update REH build file

* Update build task names for REL

* Fix product build yaml

* Fix product REH task name

* Fix type in task name

* Update linux build step

* Update windows build tasks

* Turn off server publish

* Disable REH

* Fix typo

* Bump distro

* Update vscode tests

* Bump distro

* Fix type in disto

* Bump distro

* Turn off docker build

* Remove docker step from release

Co-authored-by: ADS Merger <andresse@microsoft.com>
Co-authored-by: Karl Burtram <karlb@microsoft.com>
This commit is contained in:
Christopher Suh
2020-10-03 14:42:05 -04:00
committed by GitHub
parent 58d02b76db
commit 6ff1e3866b
687 changed files with 10507 additions and 9104 deletions

View File

@@ -10,8 +10,7 @@ import * as platform from 'vs/base/common/platform';
import { writeFileSync, writeFile, readFile, readdir, exists, rimraf, rename, RimRafMode } from 'vs/base/node/pfs';
import { IBackupMainService, IWorkspaceBackupInfo, isWorkspaceBackupInfo } from 'vs/platform/backup/electron-main/backup';
import { IBackupWorkspacesFormat, IEmptyWindowBackupInfo } from 'vs/platform/backup/node/backup';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IFilesConfiguration, HotExitConfiguration } from 'vs/platform/files/common/files';
import { ILogService } from 'vs/platform/log/common/log';
@@ -43,7 +42,7 @@ export class BackupMainService implements IBackupMainService {
@IConfigurationService private readonly configurationService: IConfigurationService,
@ILogService private readonly logService: ILogService
) {
this.backupHome = environmentService.backupHome.fsPath;
this.backupHome = environmentService.backupHome;
this.workspacesJsonPath = environmentService.backupWorkspacesPath;
}

View File

@@ -34,7 +34,7 @@ suite('BackupMainService', () => {
const backupHome = path.join(parentDir, 'Backups');
const backupWorkspacesPath = path.join(backupHome, 'workspaces.json');
const environmentService = new EnvironmentService(parseArgs(process.argv, OPTIONS), process.execPath);
const environmentService = new EnvironmentService(parseArgs(process.argv, OPTIONS));
class TestBackupMainService extends BackupMainService {

View File

@@ -89,7 +89,7 @@ suite('ConfigurationService', () => {
test('trigger configuration change event when file does not exist', async () => {
const testObject = disposables.add(new ConfigurationService(settingsResource, fileService));
await testObject.initialize();
return new Promise(async (c, e) => {
return new Promise<void>(async (c) => {
disposables.add(Event.filter(testObject.onDidChangeConfiguration, e => e.source === ConfigurationTarget.USER)(() => {
assert.equal(testObject.getValue('foo'), 'bar');
c();
@@ -104,7 +104,7 @@ suite('ConfigurationService', () => {
await fileService.writeFile(settingsResource, VSBuffer.fromString('{ "foo": "bar" }'));
await testObject.initialize();
return new Promise((c, e) => {
return new Promise<void>((c) => {
disposables.add(Event.filter(testObject.onDidChangeConfiguration, e => e.source === ConfigurationTarget.USER)(async (e) => {
assert.equal(testObject.getValue('foo'), 'barz');
c();

View File

@@ -101,7 +101,7 @@ export class ElectronExtensionHostDebugBroadcastChannel<TContext> extends Extens
});
});
await new Promise(r => server.listen(0, r));
await new Promise<void>(r => server.listen(0, r));
codeWindow.win.on('close', () => server.close());
return { rendererDebugPort: (server.address() as AddressInfo).port };

View File

@@ -1,26 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IServerChannel } from 'vs/base/parts/ipc/common/ipc';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { Event } from 'vs/base/common/event';
export class DialogChannel implements IServerChannel {
constructor(@IDialogService private readonly dialogService: IDialogService) { }
listen<T>(_: unknown, event: string): Event<T> {
throw new Error(`Event not found: ${event}`);
}
call(_: unknown, command: string, args?: any[]): Promise<any> {
switch (command) {
case 'show': return this.dialogService.show(args![0], args![1], args![2]);
case 'confirm': return this.dialogService.confirm(args![0]);
case 'about': return this.dialogService.about();
}
return Promise.reject(new Error('invalid command'));
}
}

View File

@@ -186,5 +186,5 @@ export abstract class BaseWindowDriver implements IWindowDriver {
return { x, y };
}
abstract async openDevTools(): Promise<void>;
abstract openDevTools(): Promise<void>;
}

View File

@@ -13,7 +13,7 @@ import { SimpleKeybinding, KeyCode } from 'vs/base/common/keyCodes';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
import { OS } from 'vs/base/common/platform';
import { Emitter, Event } from 'vs/base/common/event';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { ScanCodeBinding } from 'vs/base/common/scanCode';
import { KeybindingParser } from 'vs/base/common/keybindingParser';
import { timeout } from 'vs/base/common/async';

View File

@@ -8,6 +8,14 @@ import { MessageBoxOptions, MessageBoxReturnValue, OpenDevToolsOptions, SaveDial
import { IOpenedWindow, IWindowOpenable, IOpenEmptyWindowOptions, IOpenWindowOptions } from 'vs/platform/windows/common/windows';
import { INativeOpenDialogOptions } from 'vs/platform/dialogs/common/dialogs';
import { ISerializableCommandAction } from 'vs/platform/actions/common/actions';
import { ColorScheme } from 'vs/platform/theme/common/theme';
export interface IOSProperties {
type: string;
release: string;
arch: string;
platform: string;
}
export interface ICommonElectronService {
@@ -27,6 +35,8 @@ export interface ICommonElectronService {
readonly onOSResume: Event<unknown>;
readonly onColorSchemeChange: Event<ColorScheme>;
// Window
getWindows(): Promise<IOpenedWindow[]>;
getWindowCount(): Promise<number>;
@@ -73,6 +83,7 @@ export interface ICommonElectronService {
moveItemToTrash(fullPath: string, deleteOnFail?: boolean): Promise<boolean>;
isAdmin(): Promise<boolean>;
getTotalMem(): Promise<number>;
getOS(): Promise<IOSProperties>;
// Process
killProcess(pid: number, code: string): Promise<void>;

View File

@@ -3,26 +3,26 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event } from 'vs/base/common/event';
import { Emitter, Event } from 'vs/base/common/event';
import { IWindowsMainService, ICodeWindow } from 'vs/platform/windows/electron-main/windows';
import { MessageBoxOptions, MessageBoxReturnValue, shell, OpenDevToolsOptions, SaveDialogOptions, SaveDialogReturnValue, OpenDialogOptions, OpenDialogReturnValue, Menu, BrowserWindow, app, clipboard, powerMonitor } from 'electron';
import { MessageBoxOptions, MessageBoxReturnValue, shell, OpenDevToolsOptions, SaveDialogOptions, SaveDialogReturnValue, OpenDialogOptions, OpenDialogReturnValue, Menu, BrowserWindow, app, clipboard, powerMonitor, nativeTheme } from 'electron';
import { OpenContext } from 'vs/platform/windows/node/window';
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { IOpenedWindow, IOpenWindowOptions, IWindowOpenable, IOpenEmptyWindowOptions } from 'vs/platform/windows/common/windows';
import { INativeOpenDialogOptions } from 'vs/platform/dialogs/common/dialogs';
import { isMacintosh, isWindows, isRootUser } from 'vs/base/common/platform';
import { ICommonElectronService } from 'vs/platform/electron/common/electron';
import { ICommonElectronService, IOSProperties } from 'vs/platform/electron/common/electron';
import { ISerializableCommandAction } from 'vs/platform/actions/common/actions';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { AddFirstParameterToFunctions } from 'vs/base/common/types';
import { IDialogMainService } from 'vs/platform/dialogs/electron-main/dialogs';
import { dirExists } from 'vs/base/node/pfs';
import { URI } from 'vs/base/common/uri';
import { ITelemetryData, ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { MouseInputEvent } from 'vs/base/parts/sandbox/common/electronTypes';
import { totalmem } from 'os';
import { arch, totalmem, release, platform, type } from 'os';
import { ColorScheme } from 'vs/platform/theme/common/theme';
export interface IElectronMainService extends AddFirstParameterToFunctions<ICommonElectronService, Promise<unknown> /* only methods, not events */, number | undefined /* window ID */> { }
@@ -39,8 +39,27 @@ export class ElectronMainService implements IElectronMainService {
@IEnvironmentService private readonly environmentService: INativeEnvironmentService,
@ITelemetryService private readonly telemetryService: ITelemetryService
) {
this.registerListeners();
}
private registerListeners(): void {
// Color Scheme changes
nativeTheme.on('updated', () => {
let colorScheme: ColorScheme;
if (nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors) {
colorScheme = ColorScheme.HIGH_CONTRAST;
} else if (nativeTheme.shouldUseDarkColors) {
colorScheme = ColorScheme.DARK;
} else {
colorScheme = ColorScheme.LIGHT;
}
this._onColorSchemeChange.fire(colorScheme);
});
}
//#region Properties
get windowId(): never { throw new Error('Not implemented in electron-main'); }
@@ -62,6 +81,9 @@ export class ElectronMainService implements IElectronMainService {
readonly onOSResume = Event.fromNodeEventEmitter(powerMonitor, 'resume');
private readonly _onColorSchemeChange = new Emitter<ColorScheme>();
readonly onColorSchemeChange = this._onColorSchemeChange.event;
//#endregion
//#region Window
@@ -316,6 +338,15 @@ export class ElectronMainService implements IElectronMainService {
return totalmem();
}
async getOS(): Promise<IOSProperties> {
return {
arch: arch(),
platform: platform(),
release: release(),
type: type()
};
}
//#endregion

View File

@@ -0,0 +1,105 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
* A list of command line arguments we support natively.
*/
export interface NativeParsedArgs {
_: string[];
'folder-uri'?: string[]; // undefined or array of 1 or more
'file-uri'?: string[]; // undefined or array of 1 or more
_urls?: string[];
help?: boolean;
version?: boolean;
telemetry?: boolean;
status?: boolean;
wait?: boolean;
waitMarkerFilePath?: string;
diff?: boolean;
add?: boolean;
goto?: boolean;
'new-window'?: boolean;
'unity-launch'?: boolean; // Always open a new window, except if opening the first window or opening a file or folder as part of the launch.
'reuse-window'?: boolean;
locale?: string;
'user-data-dir'?: string;
'prof-startup'?: boolean;
'prof-startup-prefix'?: string;
'prof-append-timers'?: string;
verbose?: boolean;
trace?: boolean;
'trace-category-filter'?: string;
'trace-options'?: string;
'open-devtools'?: boolean;
log?: string;
logExtensionHostCommunication?: boolean;
'extensions-dir'?: string;
'extensions-download-dir'?: string;
'builtin-extensions-dir'?: string;
extensionDevelopmentPath?: string[]; // // undefined or array of 1 or more local paths or URIs
extensionTestsPath?: string; // either a local path or a URI
'inspect-extensions'?: string;
'inspect-brk-extensions'?: string;
debugId?: string;
'inspect-search'?: string;
'inspect-brk-search'?: string;
'disable-extensions'?: boolean;
'disable-extension'?: string[]; // undefined or array of 1 or more
'list-extensions'?: boolean;
'show-versions'?: boolean;
'category'?: string;
'install-extension'?: string[]; // undefined or array of 1 or more
'uninstall-extension'?: string[]; // undefined or array of 1 or more
'locate-extension'?: string[]; // undefined or array of 1 or more
'enable-proposed-api'?: string[]; // undefined or array of 1 or more
'open-url'?: boolean;
'skip-release-notes'?: boolean;
'disable-restore-windows'?: boolean;
'disable-telemetry'?: boolean;
'export-default-configuration'?: string;
'install-source'?: string;
'disable-updates'?: boolean;
'disable-crash-reporter'?: boolean;
'crash-reporter-directory'?: string;
'crash-reporter-id'?: string;
'skip-add-to-recently-opened'?: boolean;
'max-memory'?: string;
'file-write'?: boolean;
'file-chmod'?: boolean;
'driver'?: string;
'driver-verbose'?: boolean;
'remote'?: string;
'disable-user-env-probe'?: boolean;
'force'?: boolean;
'do-not-sync'?: boolean;
'force-user-env'?: boolean;
'sync'?: 'on' | 'off';
'__sandbox'?: boolean;
// {{SQL CARBON EDIT}} Start
aad?: boolean;
database?: string;
integrated?: boolean;
server?: string;
user?: string;
command?: string;
// {{SQL CARBON EDIT}} End
// chromium command line args: https://electronjs.org/docs/all#supported-chrome-command-line-switches
'no-proxy-server'?: boolean;
'proxy-server'?: string;
'proxy-bypass-list'?: string;
'proxy-pac-url'?: string;
'inspect'?: string;
'inspect-brk'?: string;
'js-flags'?: string;
'disable-gpu'?: boolean;
'nolazy'?: boolean;
'force-device-scale-factor'?: string;
'force-renderer-accessibility'?: boolean;
'ignore-certificate-errors'?: boolean;
'allow-insecure-localhost'?: boolean;
'log-net-log'?: string;
}

View File

@@ -5,6 +5,7 @@
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { URI } from 'vs/base/common/uri';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
export const IEnvironmentService = createDecorator<IEnvironmentService>('environmentService');
@@ -17,14 +18,18 @@ export interface IExtensionHostDebugParams extends IDebugParams {
debugId?: string;
}
export const BACKUPS = 'Backups';
/**
* A basic environment service that can be used in various processes,
* such as main, renderer and shared process. Use subclasses of this
* service for specific environment.
*/
export interface IEnvironmentService {
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NOTE: DO NOT ADD ANY OTHER PROPERTY INTO THE COLLECTION HERE
// UNLESS THIS PROPERTY IS SUPPORTED BOTH IN WEB AND NATIVE!!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NOTE: KEEP THIS INTERFACE AS SMALL AS POSSIBLE. AS SUCH:
// - PUT NON-WEB PROPERTIES INTO NATIVE ENV SERVICE
// - PUT WORKBENCH ONLY PROPERTIES INTO WB ENV SERVICE
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
readonly _serviceBrand: undefined;
@@ -37,7 +42,6 @@ export interface IEnvironmentService {
snippetsHome: URI;
// --- data paths
backupHome: URI;
untitledWorkspacesHome: URI;
globalStorageHome: URI;
@@ -55,8 +59,6 @@ export interface IEnvironmentService {
disableExtensions: boolean | string[];
extensionDevelopmentLocationURI?: URI[];
extensionTestsLocationURI?: URI;
extensionEnabledProposedApi?: string[];
logExtensionHostCommunication?: boolean;
// --- logging
logsPath: string;
@@ -68,8 +70,57 @@ export interface IEnvironmentService {
disableTelemetry: boolean;
serviceMachineIdResource: URI;
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NOTE: DO NOT ADD ANY OTHER PROPERTY INTO THE COLLECTION HERE
// UNLESS THIS PROPERTY IS SUPPORTED BOTH IN WEB AND NATIVE!!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NOTE: KEEP THIS INTERFACE AS SMALL AS POSSIBLE. AS SUCH:
// - PUT NON-WEB PROPERTIES INTO NATIVE ENV SERVICE
// - PUT WORKBENCH ONLY PROPERTIES INTO WB ENV SERVICE
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
/**
* A subclass of the `IEnvironmentService` to be used only in native
* environments (Windows, Linux, macOS) but not e.g. web.
*/
export interface INativeEnvironmentService extends IEnvironmentService {
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NOTE: KEEP THIS INTERFACE AS SMALL AS POSSIBLE. AS SUCH:
// - PUT WORKBENCH ONLY PROPERTIES INTO WB ENV SERVICE
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// --- CLI Arguments
args: NativeParsedArgs;
// --- paths
appRoot: string;
userHome: URI;
appSettingsHome: URI;
userDataPath: string;
machineSettingsResource: URI;
backupHome: string;
backupWorkspacesPath: string;
nodeCachedDataDir?: string;
installSourcePath: string;
// --- IPC Handles
mainIPCHandle: string;
sharedIPCHandle: string;
// --- Extensions
extensionsPath?: string;
extensionsDownloadPath: string;
builtinExtensionsPath: string;
// --- Smoke test support
driverHandle?: string;
driverVerbose: boolean;
// --- Misc. config
disableUpdates: boolean;
sandbox: boolean;
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NOTE: KEEP THIS INTERFACE AS SMALL AS POSSIBLE. AS SUCH:
// - PUT WORKBENCH ONLY PROPERTIES INTO WB ENV SERVICE
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}

View File

@@ -6,104 +6,7 @@
import * as minimist from 'minimist';
import { localize } from 'vs/nls';
import { isWindows } from 'vs/base/common/platform';
export interface ParsedArgs {
_: string[];
'folder-uri'?: string[]; // undefined or array of 1 or more
'file-uri'?: string[]; // undefined or array of 1 or more
_urls?: string[];
help?: boolean;
version?: boolean;
telemetry?: boolean;
status?: boolean;
wait?: boolean;
waitMarkerFilePath?: string;
diff?: boolean;
add?: boolean;
goto?: boolean;
'new-window'?: boolean;
'unity-launch'?: boolean; // Always open a new window, except if opening the first window or opening a file or folder as part of the launch.
'reuse-window'?: boolean;
locale?: string;
'user-data-dir'?: string;
'prof-startup'?: boolean;
'prof-startup-prefix'?: string;
'prof-append-timers'?: string;
verbose?: boolean;
trace?: boolean;
'trace-category-filter'?: string;
'trace-options'?: string;
'open-devtools'?: boolean;
log?: string;
logExtensionHostCommunication?: boolean;
'extensions-dir'?: string;
'extensions-download-dir'?: string;
'builtin-extensions-dir'?: string;
extensionDevelopmentPath?: string[]; // // undefined or array of 1 or more local paths or URIs
extensionTestsPath?: string; // either a local path or a URI
'inspect-extensions'?: string;
'inspect-brk-extensions'?: string;
debugId?: string;
'inspect-search'?: string;
'inspect-brk-search'?: string;
'disable-extensions'?: boolean;
'disable-extension'?: string[]; // undefined or array of 1 or more
'list-extensions'?: boolean;
'show-versions'?: boolean;
'category'?: string;
'install-extension'?: string[]; // undefined or array of 1 or more
'uninstall-extension'?: string[]; // undefined or array of 1 or more
'locate-extension'?: string[]; // undefined or array of 1 or more
'enable-proposed-api'?: string[]; // undefined or array of 1 or more
'open-url'?: boolean;
'skip-release-notes'?: boolean;
'disable-restore-windows'?: boolean;
'disable-telemetry'?: boolean;
'export-default-configuration'?: string;
'install-source'?: string;
'disable-updates'?: boolean;
'disable-crash-reporter'?: boolean;
'crash-reporter-directory'?: string;
'crash-reporter-id'?: string;
'skip-add-to-recently-opened'?: boolean;
'max-memory'?: string;
'file-write'?: boolean;
'file-chmod'?: boolean;
'driver'?: string;
'driver-verbose'?: boolean;
'remote'?: string;
'disable-user-env-probe'?: boolean;
'force'?: boolean;
'do-not-sync'?: boolean;
'force-user-env'?: boolean;
'sync'?: 'on' | 'off';
'__sandbox'?: boolean;
// {{SQL CARBON EDIT}} Start
aad?: boolean;
database?: string;
integrated?: boolean;
server?: string;
user?: string;
command?: string;
// {{SQL CARBON EDIT}} End
// chromium command line args: https://electronjs.org/docs/all#supported-chrome-command-line-switches
'no-proxy-server'?: boolean;
'proxy-server'?: string;
'proxy-bypass-list'?: string;
'proxy-pac-url'?: string;
'inspect'?: string;
'inspect-brk'?: string;
'js-flags'?: string;
'disable-gpu'?: boolean;
'nolazy'?: boolean;
'force-device-scale-factor'?: string;
'force-renderer-accessibility'?: boolean;
'ignore-certificate-errors'?: boolean;
'allow-insecure-localhost'?: boolean;
'log-net-log'?: string;
}
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
/**
* This code is also used by standalone cli's. Avoid adding any other dependencies.
@@ -134,7 +37,7 @@ type OptionTypeName<T> =
T extends undefined ? 'undefined' :
'unknown';
export const OPTIONS: OptionDescriptions<Required<ParsedArgs>> = {
export const OPTIONS: OptionDescriptions<Required<NativeParsedArgs>> = {
'diff': { type: 'boolean', cat: 'o', alias: 'd', args: ['file', 'file'], description: localize('diff', "Compare two files with each other.") },
'add': { type: 'boolean', cat: 'o', alias: 'a', args: 'folder', description: localize('add', "Add folder(s) to the last active window.") },
'goto': { type: 'boolean', cat: 'o', alias: 'g', args: 'file:line[:character]', description: localize('goto', "Open a file at the path on the specified line and character position.") },
@@ -423,4 +326,3 @@ export function buildHelpMessage(productName: string, executableName: string, ve
export function buildVersionMessage(version: string | undefined, commit: string | undefined): string {
return `${version || localize('unknownVersion', "Unknown version")}\n${commit || localize('unknownCommit', "Unknown commit")}\n${process.arch}`;
}

View File

@@ -4,12 +4,12 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { firstIndex } from 'vs/base/common/arrays';
import { localize } from 'vs/nls';
import { MIN_MAX_MEMORY_SIZE_MB } from 'vs/platform/files/common/files';
import { parseArgs, ErrorReporter, OPTIONS, ParsedArgs } from 'vs/platform/environment/node/argv';
import { parseArgs, ErrorReporter, OPTIONS } from 'vs/platform/environment/node/argv';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
function parseAndValidate(cmdLineArgs: string[], reportWarnings: boolean): ParsedArgs {
function parseAndValidate(cmdLineArgs: string[], reportWarnings: boolean): NativeParsedArgs {
const errorReporter: ErrorReporter = {
onUnknownOption: (id) => {
console.warn(localize('unknownOption', "Warning: '{0}' is not in the list of known options, but still passed to Electron/Chromium.", id));
@@ -32,7 +32,7 @@ function parseAndValidate(cmdLineArgs: string[], reportWarnings: boolean): Parse
}
function stripAppPath(argv: string[]): string[] | undefined {
const index = firstIndex(argv, a => !/^-/.test(a));
const index = argv.findIndex(a => !/^-/.test(a));
if (index > -1) {
return [...argv.slice(0, index), ...argv.slice(index + 1)];
@@ -43,7 +43,7 @@ function stripAppPath(argv: string[]): string[] | undefined {
/**
* Use this to parse raw code process.argv such as: `Electron . --verbose --wait`
*/
export function parseMainProcessArgv(processArgv: string[]): ParsedArgs {
export function parseMainProcessArgv(processArgv: string[]): NativeParsedArgs {
let [, ...args] = processArgv;
// If dev, remove the first non-option argument: it's the app location
@@ -59,7 +59,7 @@ export function parseMainProcessArgv(processArgv: string[]): ParsedArgs {
/**
* Use this to parse raw code CLI process.argv such as: `Electron cli.js . --verbose --wait`
*/
export function parseCLIProcessArgv(processArgv: string[]): ParsedArgs {
export function parseCLIProcessArgv(processArgv: string[]): NativeParsedArgs {
let [, , ...args] = processArgv;
if (process.env['VSCODE_DEV']) {

View File

@@ -3,8 +3,8 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IEnvironmentService, IDebugParams, IExtensionHostDebugParams, BACKUPS } from 'vs/platform/environment/common/environment';
import { ParsedArgs } from 'vs/platform/environment/node/argv';
import { IDebugParams, IExtensionHostDebugParams, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import * as crypto from 'crypto';
import * as paths from 'vs/base/node/paths';
import * as os from 'os';
@@ -13,54 +13,19 @@ import * as resources from 'vs/base/common/resources';
import { memoize } from 'vs/base/common/decorators';
import product from 'vs/platform/product/common/product';
import { toLocalISOString } from 'vs/base/common/date';
import { isWindows, isLinux, Platform, platform } from 'vs/base/common/platform';
import { isWindows, Platform, platform } from 'vs/base/common/platform';
import { getPathFromAmdModule } from 'vs/base/common/amd';
import { URI } from 'vs/base/common/uri';
export interface INativeEnvironmentService extends IEnvironmentService {
args: ParsedArgs;
appRoot: string;
execPath: string;
appSettingsHome: URI;
userDataPath: string;
userHome: URI;
machineSettingsResource: URI;
backupWorkspacesPath: string;
nodeCachedDataDir?: string;
mainIPCHandle: string;
sharedIPCHandle: string;
installSourcePath: string;
extensionsPath?: string;
extensionsDownloadPath: string;
builtinExtensionsPath: string;
driverHandle?: string;
driverVerbose: boolean;
disableUpdates: boolean;
sandbox: boolean;
}
export class EnvironmentService implements INativeEnvironmentService {
declare readonly _serviceBrand: undefined;
get args(): ParsedArgs { return this._args; }
get args(): NativeParsedArgs { return this._args; }
@memoize
get appRoot(): string { return path.dirname(getPathFromAmdModule(require, '')); }
get execPath(): string { return this._execPath; }
@memoize
get cliPath(): string { return getCLIPath(this.execPath, this.appRoot, this.isBuilt); }
readonly logsPath: string;
@memoize
@@ -129,10 +94,10 @@ export class EnvironmentService implements INativeEnvironmentService {
get isExtensionDevelopment(): boolean { return !!this._args.extensionDevelopmentPath; }
@memoize
get backupHome(): URI { return URI.file(path.join(this.userDataPath, BACKUPS)); }
get backupHome(): string { return path.join(this.userDataPath, 'Backups'); }
@memoize
get backupWorkspacesPath(): string { return path.join(this.backupHome.fsPath, 'workspaces.json'); }
get backupWorkspacesPath(): string { return path.join(this.backupHome, 'workspaces.json'); }
@memoize
get untitledWorkspacesHome(): URI { return URI.file(path.join(this.userDataPath, 'Workspaces')); }
@@ -222,22 +187,8 @@ export class EnvironmentService implements INativeEnvironmentService {
return false;
}
get extensionEnabledProposedApi(): string[] | undefined {
if (Array.isArray(this.args['enable-proposed-api'])) {
return this.args['enable-proposed-api'];
}
if ('enable-proposed-api' in this.args) {
return [];
}
return undefined;
}
@memoize
get debugExtensionHost(): IExtensionHostDebugParams { return parseExtensionHostPort(this._args, this.isBuilt); }
@memoize
get logExtensionHostCommunication(): boolean { return !!this.args.logExtensionHostCommunication; }
get isBuilt(): boolean { return !process.env['VSCODE_DEV']; }
get verbose(): boolean { return !!this._args.verbose; }
@@ -266,7 +217,7 @@ export class EnvironmentService implements INativeEnvironmentService {
get sandbox(): boolean { return !!this._args['__sandbox']; }
constructor(private _args: ParsedArgs, private _execPath: string) {
constructor(private _args: NativeParsedArgs) {
if (!process.env['VSCODE_LOGS']) {
const key = toLocalISOString(new Date()).replace(/-|:|\.\d+Z$/g, '');
process.env['VSCODE_LOGS'] = path.join(this.userDataPath, 'logs', key);
@@ -327,39 +278,11 @@ function getIPCHandle(userDataPath: string, type: string): string {
return getNixIPCHandle(userDataPath, type);
}
function getCLIPath(execPath: string, appRoot: string, isBuilt: boolean): string {
// Windows
if (isWindows) {
if (isBuilt) {
return path.join(path.dirname(execPath), 'bin', `${product.applicationName}.cmd`);
}
return path.join(appRoot, 'scripts', 'code-cli.bat');
}
// Linux
if (isLinux) {
if (isBuilt) {
return path.join(path.dirname(execPath), 'bin', `${product.applicationName}`);
}
return path.join(appRoot, 'scripts', 'code-cli.sh');
}
// macOS
if (isBuilt) {
return path.join(appRoot, 'bin', 'code');
}
return path.join(appRoot, 'scripts', 'code-cli.sh');
}
export function parseExtensionHostPort(args: ParsedArgs, isBuild: boolean): IExtensionHostDebugParams {
export function parseExtensionHostPort(args: NativeParsedArgs, isBuild: boolean): IExtensionHostDebugParams {
return parseDebugPort(args['inspect-extensions'], args['inspect-brk-extensions'], 5870, isBuild, args.debugId);
}
export function parseSearchPort(args: ParsedArgs, isBuild: boolean): IDebugParams {
export function parseSearchPort(args: NativeParsedArgs, isBuild: boolean): IDebugParams {
return parseDebugPort(args['inspect-search'], args['inspect-brk-search'], 5876, isBuild);
}
@@ -387,6 +310,6 @@ export function parsePathArg(arg: string | undefined, process: NodeJS.Process):
return path.resolve(process.env['VSCODE_CWD'] || process.cwd(), arg);
}
export function parseUserDataDir(args: ParsedArgs, process: NodeJS.Process): string {
export function parseUserDataDir(args: NativeParsedArgs, process: NodeJS.Process): string {
return parsePathArg(args['user-data-dir'], process) || path.resolve(paths.getDefaultUserDataPath(process.platform));
}

View File

@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import { URI } from 'vs/base/common/uri';
import { endsWith } from 'vs/base/common/strings';
const SshProtocolMatcher = /^([^@:]+@)?([^:]+):/;
const SshUrlMatcher = /^([^@:]+@)?([^:]+):(.+)$/;
@@ -76,7 +75,7 @@ function stripPort(authority: string): string | null {
function normalizeRemote(host: string | null, path: string, stripEndingDotGit: boolean): string | null {
if (host && path) {
if (stripEndingDotGit && endsWith(path, '.git')) {
if (stripEndingDotGit && path.endsWith('.git')) {
path = path.substr(0, path.length - 4);
}
return (path.indexOf('/') === 0) ? `${host}${path}` : `${host}/${path}`;

View File

@@ -6,7 +6,7 @@
import { getErrorMessage, isPromiseCanceledError, canceled } from 'vs/base/common/errors';
import { StatisticType, IGalleryExtension, IExtensionGalleryService, IGalleryExtensionAsset, IQueryOptions, SortBy, SortOrder, IExtensionIdentifier, IReportedExtension, InstallOperation, ITranslation, IGalleryExtensionVersion, IGalleryExtensionAssets, isIExtensionIdentifier, DefaultIconPath } from 'vs/platform/extensionManagement/common/extensionManagement';
import { getGalleryExtensionId, getGalleryExtensionTelemetryData, adoptToGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { assign, getOrDefault } from 'vs/base/common/objects';
import { getOrDefault } from 'vs/base/common/objects';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IPager } from 'vs/base/common/paging';
import { IRequestService, asJson, asText } from 'vs/platform/request/common/request';
@@ -21,7 +21,6 @@ import { IFileService } from 'vs/platform/files/common/files';
import { URI } from 'vs/base/common/uri';
import { IProductService } from 'vs/platform/product/common/productService';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { find } from 'vs/base/common/arrays';
import { getServiceMachineId } from 'vs/platform/serviceMachineId/common/serviceMachineId';
import { optional } from 'vs/platform/instantiation/common/instantiation';
import { joinPath } from 'vs/base/common/resources';
@@ -166,7 +165,7 @@ class Query {
get criteria(): ICriterium[] { return this.state.criteria ? this.state.criteria : []; }
withPage(pageNumber: number, pageSize: number = this.state.pageSize): Query {
return new Query(assign({}, this.state, { pageNumber, pageSize }));
return new Query({ ...this.state, pageNumber, pageSize });
}
withFilter(filterType: FilterType, ...values: string[]): Query {
@@ -175,23 +174,23 @@ class Query {
...values.length ? values.map(value => ({ filterType, value })) : [{ filterType }]
];
return new Query(assign({}, this.state, { criteria }));
return new Query({ ...this.state, criteria });
}
withSortBy(sortBy: SortBy): Query {
return new Query(assign({}, this.state, { sortBy }));
return new Query({ ...this.state, sortBy });
}
withSortOrder(sortOrder: SortOrder): Query {
return new Query(assign({}, this.state, { sortOrder }));
return new Query({ ...this.state, sortOrder });
}
withFlags(...flags: Flags[]): Query {
return new Query(assign({}, this.state, { flags: flags.reduce((r, f) => r | f, 0) }));
return new Query({ ...this.state, flags: flags.reduce<number>((r, f) => r | f, 0) });
}
withAssetTypes(...assetTypes: string[]): Query {
return new Query(assign({}, this.state, { assetTypes }));
return new Query({ ...this.state, assetTypes });
}
get raw(): any {
@@ -429,7 +428,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
}
}
private getCompatibleExtensionByEngine(arg1: IExtensionIdentifier | IGalleryExtension, version?: string): Promise<IGalleryExtension | null> {
private async getCompatibleExtensionByEngine(arg1: IExtensionIdentifier | IGalleryExtension, version?: string): Promise<IGalleryExtension | null> {
const extension: IGalleryExtension | null = isIExtensionIdentifier(arg1) ? null : arg1;
// {{SQL CARBON EDIT}}
// Change to original version: removed the extension version validation
@@ -451,40 +450,38 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
query = query.withFilter(FilterType.ExtensionName, id);
}
return this.queryGallery(query, CancellationToken.None)
.then(({ galleryExtensions }) => {
const [rawExtension] = galleryExtensions;
if (!rawExtension || !rawExtension.versions.length) {
return null;
const { galleryExtensions } = await this.queryGallery(query, CancellationToken.None);
const [rawExtension] = galleryExtensions;
if (!rawExtension || !rawExtension.versions.length) {
return null;
}
if (version) {
const versionAsset = rawExtension.versions.filter(v => v.version === version)[0];
if (versionAsset) {
const extension = toExtension(rawExtension, versionAsset, 0, query);
if (extension.properties.engine && isEngineValid(extension.properties.engine, this.productService.version)) {
return extension;
}
if (version) {
const versionAsset = rawExtension.versions.filter(v => v.version === version)[0];
if (versionAsset) {
const extension = toExtension(rawExtension, versionAsset, 0, query);
if (extension.properties.engine && isEngineValid(extension.properties.engine, this.productService.version)) {
return extension;
}
}
return null;
}
return this.getLastValidExtensionVersion(rawExtension, rawExtension.versions)
.then(rawVersion => {
if (rawVersion) {
return toExtension(rawExtension, rawVersion, 0, query);
}
return null;
});
});
}
return null;
}
const rawVersion = await this.getLastValidExtensionVersion(rawExtension, rawExtension.versions);
if (rawVersion) {
return toExtension(rawExtension, rawVersion, 0, query);
}
return null;
}
query(token: CancellationToken): Promise<IPager<IGalleryExtension>>;
query(options: IQueryOptions, token: CancellationToken): Promise<IPager<IGalleryExtension>>;
query(arg1: any, arg2?: any): Promise<IPager<IGalleryExtension>> {
async query(arg1: any, arg2?: any): Promise<IPager<IGalleryExtension>> {
const options: IQueryOptions = CancellationToken.isCancellationToken(arg1) ? {} : arg1;
const token: CancellationToken = CancellationToken.isCancellationToken(arg1) ? arg1 : arg2;
if (!this.isEnabled()) {
return Promise.reject(new Error('No extension gallery service configured.'));
throw new Error('No extension gallery service configured.');
}
const type = options.names ? 'ids' : (options.text ? 'text' : 'all');
@@ -549,22 +546,19 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
query = query.withSortOrder(options.sortOrder);
}
return this.queryGallery(query, token).then(({ galleryExtensions, total }) => {
const extensions = galleryExtensions.map((e, index) => toExtension(e, e.versions[0], index, query, options.source));
// {{SQL CARBON EDIT}}
const pageSize = extensions.length;
const getPage = (pageIndex: number, ct: CancellationToken) => {
if (ct.isCancellationRequested) {
return Promise.reject(canceled());
}
const { galleryExtensions, total } = await this.queryGallery(query, token);
const extensions = galleryExtensions.map((e, index) => toExtension(e, e.versions[0], index, query, options.source));
const getPage = async (pageIndex: number, ct: CancellationToken) => {
if (ct.isCancellationRequested) {
throw canceled();
}
const nextPageQuery = query.withPage(pageIndex + 1);
const { galleryExtensions } = await this.queryGallery(nextPageQuery, ct);
return galleryExtensions.map((e, index) => toExtension(e, e.versions[0], index, nextPageQuery, options.source));
};
const nextPageQuery = query.withPage(pageIndex + 1);
return this.queryGallery(nextPageQuery, ct)
.then(({ galleryExtensions }) => galleryExtensions.map((e, index) => toExtension(e, e.versions[0], index, nextPageQuery, options.source)));
};
return { firstPage: extensions, total, pageSize, getPage } as IPager<IGalleryExtension>;
});
// {{ SQL CARBON EDIT }}
return { firstPage: extensions, total, pageSize: extensions.length, getPage } as IPager<IGalleryExtension>;
}
// {{SQL CARBON EDIT}}
@@ -579,16 +573,16 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
if (query.criteria) {
const ids = query.criteria.filter(x => x.filterType === FilterType.ExtensionId).map(v => v.value ? v.value.toLocaleLowerCase() : undefined);
if (ids && ids.length > 0) {
filteredExtensions = filteredExtensions.filter(e => e.extensionId && find(ids, x => x === e.extensionId.toLocaleLowerCase()));
filteredExtensions = filteredExtensions.filter(e => e.extensionId && ids.find(x => x === e.extensionId.toLocaleLowerCase()));
}
const names = query.criteria.filter(x => x.filterType === FilterType.ExtensionName).map(v => v.value ? v.value.toLocaleLowerCase() : undefined);
if (names && names.length > 0) {
filteredExtensions = filteredExtensions.filter(e => e.extensionName && e.publisher.publisherName && find(names, x => x === `${e.publisher.publisherName.toLocaleLowerCase()}.${e.extensionName.toLocaleLowerCase()}`));
filteredExtensions = filteredExtensions.filter(e => e.extensionName && e.publisher.publisherName && names.find(x => x === `${e.publisher.publisherName.toLocaleLowerCase()}.${e.extensionName.toLocaleLowerCase()}`));
}
const categoryFilters = query.criteria.filter(x => x.filterType === FilterType.Category).map(v => v.value ? v.value.toLowerCase() : undefined);
if (categoryFilters && categoryFilters.length > 0) {
// Implement the @category: "language packs" filtering
if (find(categoryFilters, x => x === 'language packs')) {
if (categoryFilters.find(x => x === 'language packs')) {
filteredExtensions = filteredExtensions.filter(e => {
// we only have 1 version for our extensions in the gallery file, so this should always be the case
if (e.versions.length === 1) {
@@ -670,74 +664,72 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
return a[fieldName] < b[fieldName] ? -1 : 1;
}
private queryGallery(query: Query, token: CancellationToken): Promise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> {
private async queryGallery(query: Query, token: CancellationToken): Promise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> {
if (!this.isEnabled()) {
throw new Error('No extension gallery service configured.');
}
// Always exclude non validated and unpublished extensions
query = query
.withFlags(query.flags, Flags.ExcludeNonValidated)
.withFilter(FilterType.ExcludeWithFlags, flagsToString(Flags.Unpublished));
if (!this.isEnabled()) {
return Promise.reject(new Error('No extension gallery service configured.'));
const commonHeaders = await this.commonHeadersPromise;
const data = JSON.stringify(query.raw);
const headers = {
...commonHeaders,
'Content-Type': 'application/json',
'Accept': 'application/json;api-version=3.0-preview.1',
'Accept-Encoding': 'gzip',
'Content-Length': String(data.length)
};
const context = await this.requestService.request({
// {{SQL CARBON EDIT}}
type: 'GET',
url: this.api('/extensionquery'),
data,
headers
}, token);
// {{SQL CARBON EDIT}}
let extensionPolicy: string = this.configurationService.getValue<string>(ExtensionsPolicyKey);
if (context.res.statusCode && context.res.statusCode >= 400 && context.res.statusCode < 500 || extensionPolicy === ExtensionsPolicy.allowNone) {
return { galleryExtensions: [], total: 0 };
}
return this.commonHeadersPromise.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
});
return this.requestService.request({
// {{SQL CARBON EDIT}}
type: 'GET',
url: this.api('/extensionquery'),
data,
headers
}, token).then(context => {
const result = await asJson<IRawGalleryQueryResult>(context);
if (result) {
const r = result.results[0];
const galleryExtensions = r.extensions;
// const resultCount = r.resultMetadata && r.resultMetadata.filter(m => m.metadataType === 'ResultCount')[0]; {{SQL CARBON EDIT}} comment out for no unused
// const total = resultCount && resultCount.metadataItems.filter(i => i.name === 'TotalCount')[0].count || 0; {{SQL CARBON EDIT}} comment out for no unused
// {{SQL CARBON EDIT}}
let extensionPolicy: string = this.configurationService.getValue<string>(ExtensionsPolicyKey);
if (context.res.statusCode && context.res.statusCode >= 400 && context.res.statusCode < 500 || extensionPolicy === ExtensionsPolicy.allowNone) {
return { galleryExtensions: [], total: 0 };
}
// {{SQL CARBON EDIT}}
let filteredExtensionsResult = this.createQueryResult(query, galleryExtensions);
return asJson<IRawGalleryQueryResult>(context).then(result => {
if (result) {
const r = result.results[0];
const galleryExtensions = r.extensions;
// const resultCount = r.resultMetadata && r.resultMetadata.filter(m => m.metadataType === 'ResultCount')[0]; {{SQL CARBON EDIT}} comment out for no unused
// const total = resultCount && resultCount.metadataItems.filter(i => i.name === 'TotalCount')[0].count || 0; {{SQL CARBON EDIT}} comment out for no unused
// {{SQL CARBON EDIT}}
let filteredExtensionsResult = this.createQueryResult(query, galleryExtensions);
return { galleryExtensions: filteredExtensionsResult.galleryExtensions, total: filteredExtensionsResult.total };
// {{SQL CARBON EDIT}} - End
}
return { galleryExtensions: [], total: 0 };
});
});
});
return { galleryExtensions: filteredExtensionsResult.galleryExtensions, total: filteredExtensionsResult.total };
// {{SQL CARBON EDIT}} - End
}
return { galleryExtensions: [], total: 0 };
}
reportStatistic(publisher: string, name: string, version: string, type: StatisticType): Promise<void> {
async reportStatistic(publisher: string, name: string, version: string, type: StatisticType): Promise<void> {
if (!this.isEnabled()) {
return Promise.resolve(undefined);
return undefined;
}
return this.commonHeadersPromise.then(commonHeaders => {
const headers = { ...commonHeaders, Accept: '*/*;api-version=4.0-preview.1' };
return this.requestService.request({
const commonHeaders = await this.commonHeadersPromise;
const headers = { ...commonHeaders, Accept: '*/*;api-version=4.0-preview.1' };
try {
await this.requestService.request({
type: 'POST',
url: this.api(`/publishers/${publisher}/extensions/${name}/${version}/stats?statType=${type}`),
headers
}, CancellationToken.None).then(undefined, () => undefined);
});
}, CancellationToken.None);
} catch (error) { /* Ignore */ }
}
download(extension: IGalleryExtension, location: URI, operation: InstallOperation): Promise<void> {
async download(extension: IGalleryExtension, location: URI, operation: InstallOperation): Promise<void> {
this.logService.trace('ExtensionGalleryService#download', extension.identifier.id);
const data = getGalleryExtensionTelemetryData(extension);
const startTime = new Date().getTime();
@@ -749,7 +741,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
]
}
*/
const log = (duration: number) => this.telemetryService.publicLog('galleryService:downloadVSIX', assign(data, { duration }));
const log = (duration: number) => this.telemetryService.publicLog('galleryService:downloadVSIX', { ...data, duration });
// {{SQL Carbon Edit}} - Don't append install or update on to the URL
// const operationParam = operation === InstallOperation.Install ? 'install' : operation === InstallOperation.Update ? 'update' : '';
@@ -759,46 +751,46 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
fallbackUri: `${extension.assets.download.fallbackUri}?${operationParam}=true`
} : extension.assets.download;
return this.getAsset(downloadAsset)
.then(context => this.fileService.writeFile(location, context.stream))
.then(() => log(new Date().getTime() - startTime));
const context = await this.getAsset(downloadAsset);
await this.fileService.writeFile(location, context.stream);
log(new Date().getTime() - startTime);
}
getReadme(extension: IGalleryExtension, token: CancellationToken): Promise<string> {
async getReadme(extension: IGalleryExtension, token: CancellationToken): Promise<string> {
if (extension.assets.readme) {
return this.getAsset(extension.assets.readme, {}, token)
.then(context => asText(context))
.then(content => content || '');
const context = await this.getAsset(extension.assets.readme, {}, token);
const content = await asText(context);
return content || '';
}
return Promise.resolve('');
return '';
}
getManifest(extension: IGalleryExtension, token: CancellationToken): Promise<IExtensionManifest | null> {
async getManifest(extension: IGalleryExtension, token: CancellationToken): Promise<IExtensionManifest | null> {
if (extension.assets.manifest) {
return this.getAsset(extension.assets.manifest, {}, token)
.then(asText)
.then(text => text ? JSON.parse(text) : null);
const context = await this.getAsset(extension.assets.manifest, {}, token);
const text = await asText(context);
return text ? JSON.parse(text) : null;
}
return Promise.resolve(null);
return null;
}
getCoreTranslation(extension: IGalleryExtension, languageId: string): Promise<ITranslation | null> {
async getCoreTranslation(extension: IGalleryExtension, languageId: string): Promise<ITranslation | null> {
const asset = extension.assets.coreTranslations.filter(t => t[0] === languageId.toUpperCase())[0];
if (asset) {
return this.getAsset(asset[1])
.then(asText)
.then(text => text ? JSON.parse(text) : null);
const context = await this.getAsset(asset[1]);
const text = await asText(context);
return text ? JSON.parse(text) : null;
}
return Promise.resolve(null);
return null;
}
getChangelog(extension: IGalleryExtension, token: CancellationToken): Promise<string> {
async getChangelog(extension: IGalleryExtension, token: CancellationToken): Promise<string> {
if (extension.assets.changelog) {
return this.getAsset(extension.assets.changelog, {}, token)
.then(context => asText(context))
.then(content => content || '');
const context = await this.getAsset(extension.assets.changelog, {}, token);
const content = await asText(context);
return content || '';
}
return Promise.resolve('');
return '';
}
async getAllVersions(extension: IGalleryExtension, compatible: boolean): Promise<IGalleryExtensionVersion[]> {
@@ -833,48 +825,45 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
return result;
}
private getAsset(asset: IGalleryExtensionAsset, options: IRequestOptions = {}, token: CancellationToken = CancellationToken.None): Promise<IRequestContext> {
return this.commonHeadersPromise.then(commonHeaders => {
const baseOptions = { type: 'GET' };
const headers = assign({}, commonHeaders, options.headers || {});
options = assign({}, options, baseOptions, { headers });
private async getAsset(asset: IGalleryExtensionAsset, options: IRequestOptions = {}, token: CancellationToken = CancellationToken.None): Promise<IRequestContext> {
const commonHeaders = await this.commonHeadersPromise;
const baseOptions = { type: 'GET' };
const headers = { ...commonHeaders, ...(options.headers || {}) };
options = { ...options, ...baseOptions, headers };
const url = asset.uri;
const fallbackUrl = asset.fallbackUri;
const firstOptions = assign({}, options, { url });
const url = asset.uri;
const fallbackUrl = asset.fallbackUri;
const firstOptions = { ...options, url };
return this.requestService.request(firstOptions, token)
.then(context => {
if (context.res.statusCode === 200) {
return Promise.resolve(context);
}
try {
const context = await this.requestService.request(firstOptions, token);
if (context.res.statusCode === 200) {
return context;
}
const message = await asText(context);
throw new Error(`Expected 200, got back ${context.res.statusCode} instead.\n\n${message}`);
} catch (err) {
if (isPromiseCanceledError(err)) {
throw err;
}
return asText(context)
.then(message => Promise.reject(new Error(`Expected 200, got back ${context.res.statusCode} instead.\n\n${message}`)));
})
.then(undefined, err => {
if (isPromiseCanceledError(err)) {
return Promise.reject(err);
}
const message = getErrorMessage(err);
type GalleryServiceCDNFallbackClassification = {
url: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
message: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
};
type GalleryServiceCDNFallbackEvent = {
url: string;
message: string;
};
this.telemetryService.publicLog2<GalleryServiceCDNFallbackEvent, GalleryServiceCDNFallbackClassification>('galleryService:cdnFallback', { url, message });
const message = getErrorMessage(err);
type GalleryServiceCDNFallbackClassification = {
url: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
message: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
};
type GalleryServiceCDNFallbackEvent = {
url: string;
message: string;
};
this.telemetryService.publicLog2<GalleryServiceCDNFallbackEvent, GalleryServiceCDNFallbackClassification>('galleryService:cdnFallback', { url, message });
const fallbackOptions = assign({}, options, { url: fallbackUrl });
return this.requestService.request(fallbackOptions, token);
});
});
const fallbackOptions = { ...options, url: fallbackUrl };
return this.requestService.request(fallbackOptions, token);
}
}
private getLastValidExtensionVersion(extension: IRawGalleryExtension, versions: IRawGalleryExtensionVersion[]): Promise<IRawGalleryExtensionVersion | null> {
private async getLastValidExtensionVersion(extension: IRawGalleryExtension, versions: IRawGalleryExtensionVersion[]): Promise<IRawGalleryExtensionVersion | null> {
const version = this.getLastValidExtensionVersionFromProperties(extension, versions);
if (version) {
return version;
@@ -882,7 +871,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
return this.getLastValidExtensionVersionRecursively(extension, versions);
}
private getLastValidExtensionVersionFromProperties(extension: IRawGalleryExtension, versions: IRawGalleryExtensionVersion[]): Promise<IRawGalleryExtensionVersion> | null {
private getLastValidExtensionVersionFromProperties(extension: IRawGalleryExtension, versions: IRawGalleryExtensionVersion[]): IRawGalleryExtensionVersion | null {
for (const version of versions) {
// {{SQL CARBON EDIT}}
const vsCodeEngine = getEngine(version);
@@ -894,75 +883,75 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
const vsCodeEngineValid = !vsCodeEngine || (vsCodeEngine && isEngineValid(vsCodeEngine, this.productService.vscodeVersion));
const azDataEngineValid = !azDataEngine || (azDataEngine && isEngineValid(azDataEngine, this.productService.version));
if (vsCodeEngineValid && azDataEngineValid) {
return Promise.resolve(version);
return version;
}
}
return null;
}
private getEngine(version: IRawGalleryExtensionVersion): Promise<string> {
private async getEngine(version: IRawGalleryExtensionVersion): Promise<string> {
const engine = getEngine(version);
if (engine) {
return Promise.resolve(engine);
return engine;
}
const manifest = getVersionAsset(version, AssetType.Manifest);
if (!manifest) {
return Promise.reject('Manifest was not found');
const manifestAsset = getVersionAsset(version, AssetType.Manifest);
if (!manifestAsset) {
throw new Error('Manifest was not found');
}
const headers = { 'Accept-Encoding': 'gzip' };
return this.getAsset(manifest, { headers })
.then(context => asJson<IExtensionManifest>(context))
.then(manifest => manifest ? manifest.engines.vscode : Promise.reject<string>('Error while reading manifest'));
const context = await this.getAsset(manifestAsset, { headers });
const manifest = await asJson<IExtensionManifest>(context);
if (manifest) {
return manifest.engines.vscode;
}
throw new Error('Error while reading manifest');
}
private getLastValidExtensionVersionRecursively(extension: IRawGalleryExtension, versions: IRawGalleryExtensionVersion[]): Promise<IRawGalleryExtensionVersion | null> {
private async getLastValidExtensionVersionRecursively(extension: IRawGalleryExtension, versions: IRawGalleryExtensionVersion[]): Promise<IRawGalleryExtensionVersion | null> {
if (!versions.length) {
return Promise.resolve(null);
return null;
}
const version = versions[0];
return this.getEngine(version)
.then(engine => {
if (!isEngineValid(engine, this.productService.version)) {
return this.getLastValidExtensionVersionRecursively(extension, versions.slice(1));
}
const engine = await this.getEngine(version);
if (!isEngineValid(engine, this.productService.version)) {
return this.getLastValidExtensionVersionRecursively(extension, versions.slice(1));
}
version.properties = version.properties || [];
version.properties.push({ key: PropertyType.Engine, value: engine });
return version;
});
version.properties = version.properties || [];
version.properties.push({ key: PropertyType.Engine, value: engine });
return version;
}
getExtensionsReport(): Promise<IReportedExtension[]> {
async getExtensionsReport(): Promise<IReportedExtension[]> {
if (!this.isEnabled()) {
return Promise.reject(new Error('No extension gallery service configured.'));
throw new Error('No extension gallery service configured.');
}
if (!this.extensionsControlUrl) {
return Promise.resolve([]);
return [];
}
return this.requestService.request({ type: 'GET', url: this.extensionsControlUrl }, CancellationToken.None).then(context => {
if (context.res.statusCode !== 200) {
return Promise.reject(new Error('Could not get extensions report.'));
const context = await this.requestService.request({ type: 'GET', url: this.extensionsControlUrl }, CancellationToken.None);
if (context.res.statusCode !== 200) {
throw new Error('Could not get extensions report.');
}
const result = await asJson<IRawExtensionsReport>(context);
const map = new Map<string, IReportedExtension>();
if (result) {
for (const id of result.malicious) {
const ext = map.get(id) || { id: { id }, malicious: true, slow: false };
ext.malicious = true;
map.set(id, ext);
}
}
return asJson<IRawExtensionsReport>(context).then(result => {
const map = new Map<string, IReportedExtension>();
if (result) {
for (const id of result.malicious) {
const ext = map.get(id) || { id: { id }, malicious: true, slow: false };
ext.malicious = true;
map.set(id, ext);
}
}
return [...map.values()];
});
});
return [...map.values()];
}
}

View File

@@ -6,9 +6,8 @@
import { Disposable } from 'vs/base/common/lifecycle';
import { IFileService, IFileStatWithMetadata } from 'vs/platform/files/common/files';
import { IExtensionGalleryService, IGalleryExtension, InstallOperation } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { URI } from 'vs/base/common/uri';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { joinPath } from 'vs/base/common/resources';
import { ExtensionIdentifierWithVersion, groupByExtension } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { ILogService } from 'vs/platform/log/common/log';

View File

@@ -12,7 +12,6 @@ import { join } from 'vs/base/common/path';
import { Limiter } from 'vs/base/common/async';
import { Event } from 'vs/base/common/event';
import { Schemas } from 'vs/base/common/network';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { rimraf } from 'vs/base/node/pfs';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
@@ -21,7 +20,7 @@ export class ExtensionsLifecycle extends Disposable {
private processesLimiter: Limiter<void> = new Limiter(5); // Run max 5 processes in parallel
constructor(
@IEnvironmentService private environmentService: INativeEnvironmentService,
@IEnvironmentService private environmentService: IEnvironmentService,
@ILogService private readonly logService: ILogService
) {
super();

View File

@@ -6,7 +6,6 @@
import * as nls from 'vs/nls';
import * as path from 'vs/base/common/path';
import * as pfs from 'vs/base/node/pfs';
import { assign } from 'vs/base/common/objects';
import { toDisposable, Disposable } from 'vs/base/common/lifecycle';
import { zip, IFile } from 'vs/base/node/zip';
import {
@@ -22,8 +21,7 @@ import {
ExtensionManagementError
} from 'vs/platform/extensionManagement/common/extensionManagement';
import { areSameExtensions, getGalleryExtensionId, getMaliciousExtensionsSet, getGalleryExtensionTelemetryData, getLocalExtensionTelemetryData, ExtensionIdentifierWithVersion } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { createCancelablePromise, CancelablePromise } from 'vs/base/common/async';
import { Event, Emitter } from 'vs/base/common/event';
import * as semver from 'semver-umd';
@@ -66,7 +64,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
private readonly extensionsScanner: ExtensionsScanner;
private reportedExtensions: Promise<IReportedExtension[]> | undefined;
private lastReportTimestamp = 0;
private readonly installingExtensions: Map<string, CancelablePromise<ILocalExtension>> = new Map<string, CancelablePromise<ILocalExtension>>();
private readonly installingExtensions = new Map<string, CancelablePromise<ILocalExtension>>();
private readonly uninstallingExtensions: Map<string, CancelablePromise<void>> = new Map<string, CancelablePromise<void>>();
private readonly manifestCache: ExtensionsManifestCache;
private readonly extensionsDownloader: ExtensionsDownloader;
@@ -105,16 +103,17 @@ export class ExtensionManagementService extends Disposable implements IExtension
}));
}
zip(extension: ILocalExtension): Promise<URI> {
async zip(extension: ILocalExtension): Promise<URI> {
this.logService.trace('ExtensionManagementService#zip', extension.identifier.id);
return this.collectFiles(extension)
.then(files => zip(path.join(tmpdir(), generateUuid()), files))
.then<URI>(path => URI.file(path));
const files = await this.collectFiles(extension);
const location = await zip(path.join(tmpdir(), generateUuid()), files);
return URI.file(location);
}
unzip(zipLocation: URI): Promise<IExtensionIdentifier> {
async unzip(zipLocation: URI): Promise<IExtensionIdentifier> {
this.logService.trace('ExtensionManagementService#unzip', zipLocation.toString());
return this.install(zipLocation).then(local => local.identifier);
const local = await this.install(zipLocation);
return local.identifier;
}
async getManifest(vsix: URI): Promise<IExtensionManifest> {
@@ -123,7 +122,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
return getManifest(zipPath);
}
private collectFiles(extension: ILocalExtension): Promise<IFile[]> {
private async collectFiles(extension: ILocalExtension): Promise<IFile[]> {
const collectFilesFromDirectory = async (dir: string): Promise<string[]> => {
let entries = await pfs.readdir(dir);
@@ -144,113 +143,119 @@ export class ExtensionManagementService extends Disposable implements IExtension
return promise;
};
return collectFilesFromDirectory(extension.location.fsPath)
.then(files => files.map(f => (<IFile>{ path: `extension/${path.relative(extension.location.fsPath, f)}`, localPath: f })));
const files = await collectFilesFromDirectory(extension.location.fsPath);
return files.map(f => (<IFile>{ path: `extension/${path.relative(extension.location.fsPath, f)}`, localPath: f }));
}
install(vsix: URI, isMachineScoped?: boolean): Promise<ILocalExtension> {
async install(vsix: URI, isMachineScoped?: boolean): Promise<ILocalExtension> {
// {{SQL CARBON EDIT}}
let startTime = new Date().getTime();
this.logService.trace('ExtensionManagementService#install', vsix.toString());
return createCancelablePromise(token => {
return this.downloadVsix(vsix).then(downloadLocation => {
const zipPath = path.resolve(downloadLocation.fsPath);
return createCancelablePromise(async token => {
return getManifest(zipPath)
.then(manifest => {
const identifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
// let operation: InstallOperation = InstallOperation.Install; {{SQL CARBON EDIT}} comment out for no unused
// {{SQL CARBON EDIT - Check VSCode and ADS version}}
if (manifest.engines && ((manifest.engines.vscode && !isEngineValid(manifest.engines.vscode, product.vscodeVersion)) || (manifest.engines.azdata && !isEngineValid(manifest.engines.azdata, product.version)))) {
return Promise.reject(new Error(nls.localize('incompatible', "Unable to install extension '{0}' as it is not compatible with Azure Data Studio '{1}'.", identifier.id, product.version)));
}
const identifierWithVersion = new ExtensionIdentifierWithVersion(identifier, manifest.version);
return this.getInstalled(ExtensionType.User)
.then(installedExtensions => {
const existing = installedExtensions.filter(i => areSameExtensions(identifier, i.identifier))[0];
if (existing) {
isMachineScoped = isMachineScoped || existing.isMachineScoped;
// operation = InstallOperation.Update;
if (identifierWithVersion.equals(new ExtensionIdentifierWithVersion(existing.identifier, existing.manifest.version))) {
return this.extensionsScanner.removeExtension(existing, 'existing').then(null, e => Promise.reject(new Error(nls.localize('restartCode', "Please restart Azure Data Studio before reinstalling {0}.", manifest.displayName || manifest.name))));
} else if (semver.gt(existing.manifest.version, manifest.version)) {
return this.uninstallExtension(existing);
}
} else {
// Remove the extension with same version if it is already uninstalled.
// Installing a VSIX extension shall replace the existing extension always.
return this.unsetUninstalledAndGetLocal(identifierWithVersion)
.then(existing => {
if (existing) {
return this.extensionsScanner.removeExtension(existing, 'existing').then(null, e => Promise.reject(new Error(nls.localize('restartCode', "Please restart Azure Data Studio before reinstalling {0}.", manifest.displayName || manifest.name))));
}
return undefined;
});
}
return undefined;
})
.then(() => {
this.logService.info('Installing the extension:', identifier.id);
this._onInstallExtension.fire({ identifier, zipPath });
// {{SQL CARBON EDIT}}
// Until there's a gallery for SQL Ops Studio, skip retrieving the metadata from the gallery
return this.installExtension({ zipPath, identifierWithVersion, metadata: { isMachineScoped } }, token)
.then(
local => {
this.reportTelemetry(this.getTelemetryEvent(InstallOperation.Install), getLocalExtensionTelemetryData(local), new Date().getTime() - startTime, void 0);
this._onDidInstallExtension.fire({ identifier, zipPath, local, operation: InstallOperation.Install });
return local;
},
error => { this._onDidInstallExtension.fire({ identifier, zipPath, error, operation: InstallOperation.Install }); return Promise.reject(error); }
);
// return this.getMetadata(getGalleryExtensionId(manifest.publisher, manifest.name))
// .then(
// metadata => this.installFromZipPath(identifierWithVersion, zipPath, metadata, type, operation, token),
// () => this.installFromZipPath(identifierWithVersion, zipPath, null, type, operation, token))
// .then(
// local => { this.logService.info('Successfully installed the extension:', identifier.id); return local; },
// e => {
// this.logService.error('Failed to install the extension:', identifier.id, e.message);
// return Promise.reject(e);
// });
// {{SQL CARBON EDIT}} - End
});
});
});
const downloadLocation = await this.downloadVsix(vsix);
const zipPath = path.resolve(downloadLocation.fsPath);
const manifest = await getManifest(zipPath);
const identifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
// let operation: InstallOperation = InstallOperation.Install; {{ SQL CARBON EDIT }}
// {{ SQL CARBON EDIT }}
if (manifest.engines && ((manifest.engines.vscode && !isEngineValid(manifest.engines.vscode, product.vscodeVersion)) || (manifest.engines.azdata && !isEngineValid(manifest.engines.azdata, product.version)))) {
throw new Error(nls.localize('incompatible', "Unable to install extension '{0}' as it is not compatible with VS Code '{1}'.", identifier.id, product.version));
}
const identifierWithVersion = new ExtensionIdentifierWithVersion(identifier, manifest.version);
const installedExtensions = await this.getInstalled(ExtensionType.User);
const existing = installedExtensions.find(i => areSameExtensions(identifier, i.identifier));
if (existing) {
isMachineScoped = isMachineScoped || existing.isMachineScoped;
// operation = InstallOperation.Update; {{ SQL CARBON EDIT }}
if (identifierWithVersion.equals(new ExtensionIdentifierWithVersion(existing.identifier, existing.manifest.version))) {
try {
await this.extensionsScanner.removeExtension(existing, 'existing');
} catch (e) {
throw new Error(nls.localize('restartCode', "Please restart VS Code before reinstalling {0}.", manifest.displayName || manifest.name));
}
} else if (semver.gt(existing.manifest.version, manifest.version)) {
await this.uninstallExtension(existing);
}
} else {
// Remove the extension with same version if it is already uninstalled.
// Installing a VSIX extension shall replace the existing extension always.
const existing = await this.unsetUninstalledAndGetLocal(identifierWithVersion);
if (existing) {
try {
await this.extensionsScanner.removeExtension(existing, 'existing');
} catch (e) {
throw new Error(nls.localize('restartCode', "Please restart VS Code before reinstalling {0}.", manifest.displayName || manifest.name));
}
}
}
this.logService.info('Installing the extension:', identifier.id);
this._onInstallExtension.fire({ identifier, zipPath });
// {{SQL CARBON EDIT}}
// Until there's a gallery for SQL Ops Studio, skip retrieving the metadata from the gallery
return this.installExtension({ zipPath, identifierWithVersion, metadata: { isMachineScoped } }, token)
.then(
local => {
this.reportTelemetry(this.getTelemetryEvent(InstallOperation.Install), getLocalExtensionTelemetryData(local), new Date().getTime() - startTime, void 0);
this._onDidInstallExtension.fire({ identifier, zipPath, local, operation: InstallOperation.Install });
return local;
},
error => { this._onDidInstallExtension.fire({ identifier, zipPath, error, operation: InstallOperation.Install }); return Promise.reject(error); }
);
// {{ SQL CARBON EDIT }}
// let metadata: IGalleryMetadata | undefined;
// try {
// metadata = await this.getGalleryMetadata(getGalleryExtensionId(manifest.publisher, manifest.name));
// } catch (e) { /* Ignore */ }
// try {
// const local = await this.installFromZipPath(identifierWithVersion, zipPath, isMachineScoped ? { ...(metadata || {}), isMachineScoped } : metadata, operation, token);
// this.logService.info('Successfully installed the extension:', identifier.id);
// return local;
// } catch (e) {
// this.logService.error('Failed to install the extension:', identifier.id, e.message);
// throw e;
// }
});
}
private downloadVsix(vsix: URI): Promise<URI> {
private async downloadVsix(vsix: URI): Promise<URI> {
if (vsix.scheme === Schemas.file) {
return Promise.resolve(vsix);
return vsix;
}
if (!this.downloadService) {
throw new Error('Download service is not available');
}
const downloadedLocation = path.join(tmpdir(), generateUuid());
return this.downloadService.download(vsix, URI.file(downloadedLocation)).then(() => URI.file(downloadedLocation));
const downloadedLocation = URI.file(path.join(tmpdir(), generateUuid()));
await this.downloadService.download(vsix, downloadedLocation);
return downloadedLocation;
}
/*private installFromZipPath(identifierWithVersion: ExtensionIdentifierWithVersion, zipPath: string, metadata: IMetadata | undefined, operation: InstallOperation, token: CancellationToken): Promise<ILocalExtension> { {{SQL CARBON EDIT}}
return this.toNonCancellablePromise(this.installExtension({ zipPath, identifierWithVersion, metadata }, token)
.then(local => this.installDependenciesAndPackExtensions(local, undefined)
.then(
() => local,
error => {
if (isNonEmptyArray(local.manifest.extensionDependencies)) {
this.logService.warn(`Cannot install dependencies of extension:`, local.identifier.id, error.message);
}
if (isNonEmptyArray(local.manifest.extensionPack)) {
this.logService.warn(`Cannot install packed extensions of extension:`, local.identifier.id, error.message);
}
return local;
}))
.then(
local => { this._onDidInstallExtension.fire({ identifier: identifierWithVersion.identifier, zipPath, local, operation }); return local; },
error => { this._onDidInstallExtension.fire({ identifier: identifierWithVersion.identifier, zipPath, operation, error }); return Promise.reject(error); }
));
// {{ SQL CARBON EDIT }}
/*private async installFromZipPath(identifierWithVersion: ExtensionIdentifierWithVersion, zipPath: string, metadata: IMetadata | undefined, operation: InstallOperation, token: CancellationToken): Promise<ILocalExtension> {
try {
const local = await this.installExtension({ zipPath, identifierWithVersion, metadata }, token);
try {
await this.installDependenciesAndPackExtensions(local, undefined);
} catch (error) {
if (isNonEmptyArray(local.manifest.extensionDependencies)) {
this.logService.warn(`Cannot install dependencies of extension:`, local.identifier.id, error.message);
}
if (isNonEmptyArray(local.manifest.extensionPack)) {
this.logService.warn(`Cannot install packed extensions of extension:`, local.identifier.id, error.message);
}
}
this._onDidInstallExtension.fire({ identifier: identifierWithVersion.identifier, zipPath, local, operation });
return local;
} catch (error) {
this._onDidInstallExtension.fire({ identifier: identifierWithVersion.identifier, zipPath, operation, error });
throw error;
}
}*/
async canInstall(extension: IGalleryExtension): Promise<boolean> {
@@ -259,17 +264,68 @@ export class ExtensionManagementService extends Disposable implements IExtension
async installFromGallery(extension: IGalleryExtension, isMachineScoped?: boolean): Promise<ILocalExtension> {
if (!this.galleryService.isEnabled()) {
return Promise.reject(new Error(nls.localize('MarketPlaceDisabled', "Marketplace is not enabled")));
throw new Error(nls.localize('MarketPlaceDisabled', "Marketplace is not enabled"));
}
const startTime = new Date().getTime();
const onDidInstallExtensionSuccess = (extension: IGalleryExtension, operation: InstallOperation, local: ILocalExtension) => {
try {
extension = await this.checkAndGetCompatibleVersion(extension);
} catch (error) {
const errorCode = error && (<ExtensionManagementError>error).code ? (<ExtensionManagementError>error).code : ERROR_UNKNOWN;
this.logService.error(`Failed to install extension:`, extension.identifier.id, error ? error.message : errorCode);
this.reportTelemetry(this.getTelemetryEvent(InstallOperation.Install), getGalleryExtensionTelemetryData(extension), undefined, error);
if (error instanceof Error) {
error.name = errorCode;
}
throw error;
}
const key = new ExtensionIdentifierWithVersion(extension.identifier, extension.version).key();
let cancellablePromise = this.installingExtensions.get(key);
if (!cancellablePromise) {
cancellablePromise = createCancelablePromise(token => this.doInstallFromGallery(extension, !!isMachineScoped, token));
this.installingExtensions.set(key, cancellablePromise);
cancellablePromise.finally(() => this.installingExtensions.delete(key));
}
return cancellablePromise;
}
private async doInstallFromGallery(extension: IGalleryExtension, isMachineScoped: boolean, token: CancellationToken): Promise<ILocalExtension> {
const startTime = new Date().getTime();
let operation: InstallOperation = InstallOperation.Install;
this.logService.info('Installing extension:', extension.identifier.id);
this._onInstallExtension.fire({ identifier: extension.identifier, gallery: extension });
try {
const installed = await this.getInstalled(ExtensionType.User);
const existingExtension = installed.find(i => areSameExtensions(i.identifier, extension.identifier));
if (existingExtension) {
operation = InstallOperation.Update;
}
const installableExtension = await this.downloadInstallableExtension(extension, operation);
installableExtension.metadata.isMachineScoped = isMachineScoped || existingExtension?.isMachineScoped;
const local = await this.installExtension(installableExtension, token);
try { await this.extensionsDownloader.delete(URI.file(installableExtension.zipPath)); } catch (error) { /* Ignore */ }
try {
await this.installDependenciesAndPackExtensions(local, existingExtension);
} catch (error) {
try { await this.uninstall(local); } catch (error) { /* Ignore */ }
throw error;
}
if (existingExtension && semver.neq(existingExtension.manifest.version, extension.version)) {
await this.setUninstalled(existingExtension);
}
this.logService.info(`Extensions installed successfully:`, extension.identifier.id);
this._onDidInstallExtension.fire({ identifier: extension.identifier, gallery: extension, local, operation });
this.reportTelemetry(this.getTelemetryEvent(operation), getGalleryExtensionTelemetryData(extension), new Date().getTime() - startTime, undefined);
};
return local;
const onDidInstallExtensionFailure = (extension: IGalleryExtension, operation: InstallOperation, error: Error) => {
} catch (error) {
const errorCode = error && (<ExtensionManagementError>error).code ? (<ExtensionManagementError>error).code : ERROR_UNKNOWN;
this.logService.error(`Failed to install extension:`, extension.identifier.id, error ? error.message : errorCode);
this._onDidInstallExtension.fire({ identifier: extension.identifier, gallery: extension, operation, error: errorCode });
@@ -277,162 +333,107 @@ export class ExtensionManagementService extends Disposable implements IExtension
if (error instanceof Error) {
error.name = errorCode;
}
};
try {
extension = await this.checkAndGetCompatibleVersion(extension);
} catch (error) {
onDidInstallExtensionFailure(extension, InstallOperation.Install, error);
return Promise.reject(error);
throw error;
}
const key = new ExtensionIdentifierWithVersion(extension.identifier, extension.version).key();
let cancellablePromise = this.installingExtensions.get(key);
if (!cancellablePromise) {
this.logService.info('Installing extension:', extension.identifier.id);
this._onInstallExtension.fire({ identifier: extension.identifier, gallery: extension });
let operation: InstallOperation = InstallOperation.Install;
let cancellationToken: CancellationToken, successCallback: (local: ILocalExtension) => void, errorCallback: (e?: any) => any | null;
cancellablePromise = createCancelablePromise(token => { cancellationToken = token; return new Promise((c, e) => { successCallback = c; errorCallback = e; }); });
this.installingExtensions.set(key, cancellablePromise);
try {
const installed = await this.getInstalled(ExtensionType.User);
const existingExtension = installed.find(i => areSameExtensions(i.identifier, extension.identifier));
if (existingExtension) {
operation = InstallOperation.Update;
}
this.downloadInstallableExtension(extension, operation)
.then(installableExtension => {
installableExtension.metadata.isMachineScoped = isMachineScoped || existingExtension?.isMachineScoped;
return this.installExtension(installableExtension, cancellationToken)
.then(local => this.extensionsDownloader.delete(URI.file(installableExtension.zipPath)).finally(() => { }).then(() => local));
})
.then(local => this.installDependenciesAndPackExtensions(local, existingExtension)
.then(() => local, error => this.uninstall(local).then(() => Promise.reject(error), () => Promise.reject(error))))
.then(
async local => {
if (existingExtension && semver.neq(existingExtension.manifest.version, extension.version)) {
await this.setUninstalled(existingExtension);
}
this.installingExtensions.delete(key);
onDidInstallExtensionSuccess(extension, operation, local);
successCallback(local);
},
error => {
this.installingExtensions.delete(key);
onDidInstallExtensionFailure(extension, operation, error);
errorCallback(error);
});
} catch (error) {
this.installingExtensions.delete(key);
onDidInstallExtensionFailure(extension, operation, error);
return Promise.reject(error);
}
}
return cancellablePromise;
}
private async checkAndGetCompatibleVersion(extension: IGalleryExtension): Promise<IGalleryExtension> {
if (await this.isMalicious(extension)) {
return Promise.reject(new ExtensionManagementError(nls.localize('malicious extension', "Can't install extension since it was reported to be problematic."), INSTALL_ERROR_MALICIOUS));
throw new ExtensionManagementError(nls.localize('malicious extension', "Can't install extension since it was reported to be problematic."), INSTALL_ERROR_MALICIOUS);
}
const compatibleExtension = await this.galleryService.getCompatibleExtension(extension);
if (!compatibleExtension) {
return Promise.reject(new ExtensionManagementError(nls.localize('notFoundCompatibleDependency', "Unable to install '{0}' extension because it is not compatible with the current version of VS Code (version {1}).", extension.identifier.id, product.version), INSTALL_ERROR_INCOMPATIBLE));
throw new ExtensionManagementError(nls.localize('notFoundCompatibleDependency', "Unable to install '{0}' extension because it is not compatible with the current version of VS Code (version {1}).", extension.identifier.id, product.version), INSTALL_ERROR_INCOMPATIBLE);
}
return compatibleExtension;
}
reinstallFromGallery(extension: ILocalExtension): Promise<void> {
async reinstallFromGallery(extension: ILocalExtension): Promise<void> {
this.logService.trace('ExtensionManagementService#reinstallFromGallery', extension.identifier.id);
if (!this.galleryService.isEnabled()) {
return Promise.reject(new Error(nls.localize('MarketPlaceDisabled', "Marketplace is not enabled")));
throw new Error(nls.localize('MarketPlaceDisabled', "Marketplace is not enabled"));
}
return this.findGalleryExtension(extension)
.then(galleryExtension => {
if (galleryExtension) {
return this.setUninstalled(extension)
.then(() => this.extensionsScanner.removeUninstalledExtension(extension)
.then(
() => this.installFromGallery(galleryExtension).then(),
e => Promise.reject(new Error(nls.localize('removeError', "Error while removing the extension: {0}. Please Quit and Start VS Code before trying again.", toErrorMessage(e))))));
}
return Promise.reject(new Error(nls.localize('Not a Marketplace extension', "Only Marketplace Extensions can be reinstalled")));
});
const galleryExtension = await this.findGalleryExtension(extension);
if (!galleryExtension) {
throw new Error(nls.localize('Not a Marketplace extension', "Only Marketplace Extensions can be reinstalled"));
}
await this.setUninstalled(extension);
try {
await this.extensionsScanner.removeUninstalledExtension(extension);
} catch (e) {
throw new Error(nls.localize('removeError', "Error while removing the extension: {0}. Please Quit and Start VS Code before trying again.", toErrorMessage(e)));
}
await this.installFromGallery(galleryExtension);
}
private getTelemetryEvent(operation: InstallOperation): string {
return operation === InstallOperation.Update ? 'extensionGallery:update' : 'extensionGallery:install';
}
private isMalicious(extension: IGalleryExtension): Promise<boolean> {
return this.getExtensionsReport()
.then(report => getMaliciousExtensionsSet(report).has(extension.identifier.id));
private async isMalicious(extension: IGalleryExtension): Promise<boolean> {
const report = await this.getExtensionsReport();
return getMaliciousExtensionsSet(report).has(extension.identifier.id);
}
private downloadInstallableExtension(extension: IGalleryExtension, operation: InstallOperation): Promise<Required<InstallableExtension>> {
private async downloadInstallableExtension(extension: IGalleryExtension, operation: InstallOperation): Promise<Required<InstallableExtension>> {
const metadata = <IGalleryMetadata>{
id: extension.identifier.uuid,
publisherId: extension.publisherId,
publisherDisplayName: extension.publisherDisplayName,
};
this.logService.trace('Started downloading extension:', extension.identifier.id);
return this.extensionsDownloader.downloadExtension(extension, operation)
.then(
zip => {
const zipPath = zip.fsPath;
this.logService.info('Downloaded extension:', extension.identifier.id, zipPath);
return getManifest(zipPath)
.then(
manifest => (<Required<InstallableExtension>>{ zipPath, identifierWithVersion: new ExtensionIdentifierWithVersion(extension.identifier, manifest.version), metadata }),
error => Promise.reject(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_VALIDATING))
);
},
error => Promise.reject(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_DOWNLOADING)));
let zipPath;
try {
this.logService.trace('Started downloading extension:', extension.identifier.id);
const zip = await this.extensionsDownloader.downloadExtension(extension, operation);
this.logService.info('Downloaded extension:', extension.identifier.id, zipPath);
zipPath = zip.fsPath;
} catch (error) {
throw new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_DOWNLOADING);
}
try {
const manifest = await getManifest(zipPath);
return (<Required<InstallableExtension>>{ zipPath, identifierWithVersion: new ExtensionIdentifierWithVersion(extension.identifier, manifest.version), metadata });
} catch (error) {
throw new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_VALIDATING);
}
}
private installExtension(installableExtension: InstallableExtension, token: CancellationToken): Promise<ILocalExtension> {
return this.unsetUninstalledAndGetLocal(installableExtension.identifierWithVersion)
.then(
local => {
if (local) {
return local;
}
return this.extractAndInstall(installableExtension, token);
},
e => {
if (isMacintosh) {
return Promise.reject(new ExtensionManagementError(nls.localize('quitCode', "Unable to install the extension. Please Quit and Start VS Code before reinstalling."), INSTALL_ERROR_UNSET_UNINSTALLED));
}
return Promise.reject(new ExtensionManagementError(nls.localize('exitCode', "Unable to install the extension. Please Exit and Start VS Code before reinstalling."), INSTALL_ERROR_UNSET_UNINSTALLED));
});
private async installExtension(installableExtension: InstallableExtension, token: CancellationToken): Promise<ILocalExtension> {
try {
const local = await this.unsetUninstalledAndGetLocal(installableExtension.identifierWithVersion);
if (local) {
return local;
}
} catch (e) {
if (isMacintosh) {
throw new ExtensionManagementError(nls.localize('quitCode', "Unable to install the extension. Please Quit and Start VS Code before reinstalling."), INSTALL_ERROR_UNSET_UNINSTALLED);
} else {
throw new ExtensionManagementError(nls.localize('exitCode', "Unable to install the extension. Please Exit and Start VS Code before reinstalling."), INSTALL_ERROR_UNSET_UNINSTALLED);
}
}
return this.extractAndInstall(installableExtension, token);
}
private unsetUninstalledAndGetLocal(identifierWithVersion: ExtensionIdentifierWithVersion): Promise<ILocalExtension | null> {
return this.isUninstalled(identifierWithVersion)
.then<ILocalExtension | null>(isUninstalled => {
if (isUninstalled) {
this.logService.trace('Removing the extension from uninstalled list:', identifierWithVersion.identifier.id);
// If the same version of extension is marked as uninstalled, remove it from there and return the local.
return this.unsetUninstalled(identifierWithVersion)
.then(() => {
this.logService.info('Removed the extension from uninstalled list:', identifierWithVersion.identifier.id);
return this.getInstalled(ExtensionType.User);
})
.then(installed => installed.filter(i => new ExtensionIdentifierWithVersion(i.identifier, i.manifest.version).equals(identifierWithVersion))[0]);
}
return null;
});
private async unsetUninstalledAndGetLocal(identifierWithVersion: ExtensionIdentifierWithVersion): Promise<ILocalExtension | null> {
const isUninstalled = await this.isUninstalled(identifierWithVersion);
if (!isUninstalled) {
return null;
}
this.logService.trace('Removing the extension from uninstalled list:', identifierWithVersion.identifier.id);
// If the same version of extension is marked as uninstalled, remove it from there and return the local.
await this.unsetUninstalled(identifierWithVersion);
this.logService.info('Removed the extension from uninstalled list:', identifierWithVersion.identifier.id);
const installed = await this.getInstalled(ExtensionType.User);
return installed.find(i => new ExtensionIdentifierWithVersion(i.identifier, i.manifest.version).equals(identifierWithVersion)) || null;
}
private async extractAndInstall({ zipPath, identifierWithVersion, metadata }: InstallableExtension, token: CancellationToken): Promise<ILocalExtension> {
@@ -446,57 +447,56 @@ export class ExtensionManagementService extends Disposable implements IExtension
}
private async installDependenciesAndPackExtensions(installed: ILocalExtension, existing: ILocalExtension | undefined): Promise<void> {
if (this.galleryService.isEnabled()) {
const dependenciesAndPackExtensions: string[] = installed.manifest.extensionDependencies || [];
if (installed.manifest.extensionPack) {
for (const extension of installed.manifest.extensionPack) {
// add only those extensions which are new in currently installed extension
if (!(existing && existing.manifest.extensionPack && existing.manifest.extensionPack.some(old => areSameExtensions({ id: old }, { id: extension })))) {
if (dependenciesAndPackExtensions.every(e => !areSameExtensions({ id: e }, { id: extension }))) {
dependenciesAndPackExtensions.push(extension);
}
if (!this.galleryService.isEnabled()) {
return;
}
const dependenciesAndPackExtensions: string[] = installed.manifest.extensionDependencies || [];
if (installed.manifest.extensionPack) {
for (const extension of installed.manifest.extensionPack) {
// add only those extensions which are new in currently installed extension
if (!(existing && existing.manifest.extensionPack && existing.manifest.extensionPack.some(old => areSameExtensions({ id: old }, { id: extension })))) {
if (dependenciesAndPackExtensions.every(e => !areSameExtensions({ id: e }, { id: extension }))) {
dependenciesAndPackExtensions.push(extension);
}
}
}
if (dependenciesAndPackExtensions.length) {
return this.getInstalled()
.then(installed => {
// filter out installed extensions
const names = dependenciesAndPackExtensions.filter(id => installed.every(({ identifier: galleryIdentifier }) => !areSameExtensions(galleryIdentifier, { id })));
if (names.length) {
return this.galleryService.query({ names, pageSize: dependenciesAndPackExtensions.length }, CancellationToken.None)
.then(galleryResult => {
const extensionsToInstall = galleryResult.firstPage;
return Promise.all(extensionsToInstall.map(e => this.installFromGallery(e)))
.then(undefined, errors => this.rollback(extensionsToInstall).then(() => Promise.reject(errors), () => Promise.reject(errors)));
});
}
return undefined; // {{SQL CARBON EDIT}} strict-null-checks
});
}
if (dependenciesAndPackExtensions.length) {
const installed = await this.getInstalled();
// filter out installed extensions
const names = dependenciesAndPackExtensions.filter(id => installed.every(({ identifier: galleryIdentifier }) => !areSameExtensions(galleryIdentifier, { id })));
if (names.length) {
const galleryResult = await this.galleryService.query({ names, pageSize: dependenciesAndPackExtensions.length }, CancellationToken.None);
const extensionsToInstall = galleryResult.firstPage;
try {
await Promise.all(extensionsToInstall.map(e => this.installFromGallery(e)));
} catch (error) {
try { await this.rollback(extensionsToInstall); } catch (e) { /* ignore */ }
throw error;
}
}
}
return Promise.resolve(undefined);
}
private rollback(extensions: IGalleryExtension[]): Promise<void> {
return this.getInstalled(ExtensionType.User)
.then(installed =>
Promise.all(installed.filter(local => extensions.some(galleryExtension => new ExtensionIdentifierWithVersion(local.identifier, local.manifest.version).equals(new ExtensionIdentifierWithVersion(galleryExtension.identifier, galleryExtension.version)))) // Check with version because we want to rollback the exact version
.map(local => this.uninstall(local))))
.then(() => undefined, () => undefined);
private async rollback(extensions: IGalleryExtension[]): Promise<void> {
const installed = await this.getInstalled(ExtensionType.User);
const extensionsToUninstall = installed.filter(local => extensions.some(galleryExtension => new ExtensionIdentifierWithVersion(local.identifier, local.manifest.version).equals(new ExtensionIdentifierWithVersion(galleryExtension.identifier, galleryExtension.version)))); // Check with version because we want to rollback the exact version
await Promise.all(extensionsToUninstall.map(local => this.uninstall(local)));
}
uninstall(extension: ILocalExtension): Promise<void> {
async uninstall(extension: ILocalExtension): Promise<void> {
this.logService.trace('ExtensionManagementService#uninstall', extension.identifier.id);
return this.toNonCancellablePromise(this.getInstalled(ExtensionType.User)
.then(installed => {
const extensionToUninstall = installed.filter(e => areSameExtensions(e.identifier, extension.identifier))[0];
if (extensionToUninstall) {
return this.checkForDependenciesAndUninstall(extensionToUninstall, installed).then(undefined, error => Promise.reject(this.joinErrors(error)));
} else {
return Promise.reject(new Error(nls.localize('notInstalled', "Extension '{0}' is not installed.", extension.manifest.displayName || extension.manifest.name)));
}
}));
const installed = await this.getInstalled(ExtensionType.User);
const extensionToUninstall = installed.find(e => areSameExtensions(e.identifier, extension.identifier));
if (!extensionToUninstall) {
throw new Error(nls.localize('notInstalled', "Extension '{0}' is not installed.", extension.manifest.displayName || extension.manifest.name));
}
try {
await this.checkForDependenciesAndUninstall(extensionToUninstall, installed);
} catch (error) {
throw this.joinErrors(error);
}
}
async updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): Promise<ILocalExtension> {
@@ -506,25 +506,28 @@ export class ExtensionManagementService extends Disposable implements IExtension
return local;
}
/*private getGalleryMetadata(extensionName: string): Promise<IGalleryMetadata | undefined> { {{SQL CARBON EDIT}}
return this.findGalleryExtensionByName(extensionName)
.then(galleryExtension => galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : undefined);
// {{ SQL CARBON EDIT }}
/*private async getGalleryMetadata(extensionName: string): Promise<IGalleryMetadata | undefined> {
const galleryExtension = await this.findGalleryExtensionByName(extensionName);
return galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : undefined;
}*/
private findGalleryExtension(local: ILocalExtension): Promise<IGalleryExtension> {
private async findGalleryExtension(local: ILocalExtension): Promise<IGalleryExtension> {
if (local.identifier.uuid) {
return this.findGalleryExtensionById(local.identifier.uuid)
.then(galleryExtension => galleryExtension ? galleryExtension : this.findGalleryExtensionByName(local.identifier.id));
const galleryExtension = await this.findGalleryExtensionById(local.identifier.uuid);
return galleryExtension ? galleryExtension : this.findGalleryExtensionByName(local.identifier.id);
}
return this.findGalleryExtensionByName(local.identifier.id);
}
private findGalleryExtensionById(uuid: string): Promise<IGalleryExtension> {
return this.galleryService.query({ ids: [uuid], pageSize: 1 }, CancellationToken.None).then(galleryResult => galleryResult.firstPage[0]);
private async findGalleryExtensionById(uuid: string): Promise<IGalleryExtension> {
const galleryResult = await this.galleryService.query({ ids: [uuid], pageSize: 1 }, CancellationToken.None);
return galleryResult.firstPage[0];
}
private findGalleryExtensionByName(name: string): Promise<IGalleryExtension> {
return this.galleryService.query({ names: [name], pageSize: 1 }, CancellationToken.None).then(galleryResult => galleryResult.firstPage[0]);
private async findGalleryExtensionByName(name: string): Promise<IGalleryExtension> {
const galleryResult = await this.galleryService.query({ names: [name], pageSize: 1 }, CancellationToken.None);
return galleryResult.firstPage[0];
}
private joinErrors(errorOrErrors: (Error | string) | (Array<Error | string>)): Error {
@@ -537,20 +540,20 @@ export class ExtensionManagementService extends Disposable implements IExtension
}, new Error(''));
}
private checkForDependenciesAndUninstall(extension: ILocalExtension, installed: ILocalExtension[]): Promise<void> {
return this.preUninstallExtension(extension)
.then(() => {
const packedExtensions = this.getAllPackExtensionsToUninstall(extension, installed);
if (packedExtensions.length) {
return this.uninstallExtensions(extension, packedExtensions, installed);
}
return this.uninstallExtensions(extension, [], installed);
})
.then(() => this.postUninstallExtension(extension),
error => {
this.postUninstallExtension(extension, new ExtensionManagementError(error instanceof Error ? error.message : error, INSTALL_ERROR_LOCAL));
return Promise.reject(error);
});
private async checkForDependenciesAndUninstall(extension: ILocalExtension, installed: ILocalExtension[]): Promise<void> {
try {
await this.preUninstallExtension(extension);
const packedExtensions = this.getAllPackExtensionsToUninstall(extension, installed);
if (packedExtensions.length) {
await this.uninstallExtensions(extension, packedExtensions, installed);
} else {
await this.uninstallExtensions(extension, [], installed);
}
} catch (error) {
await this.postUninstallExtension(extension, new ExtensionManagementError(error instanceof Error ? error.message : error, INSTALL_ERROR_LOCAL));
throw error;
}
await this.postUninstallExtension(extension);
}
private async uninstallExtensions(extension: ILocalExtension, otherExtensionsToUninstall: ILocalExtension[], installed: ILocalExtension[]): Promise<void> {
@@ -621,33 +624,36 @@ export class ExtensionManagementService extends Disposable implements IExtension
return installed.filter(e => e.manifest.extensionDependencies && e.manifest.extensionDependencies.some(id => areSameExtensions({ id }, extension.identifier)));
}
private doUninstall(extension: ILocalExtension): Promise<void> {
return this.preUninstallExtension(extension)
.then(() => this.uninstallExtension(extension))
.then(() => this.postUninstallExtension(extension),
error => {
this.postUninstallExtension(extension, new ExtensionManagementError(error instanceof Error ? error.message : error, INSTALL_ERROR_LOCAL));
return Promise.reject(error);
});
private async doUninstall(extension: ILocalExtension): Promise<void> {
try {
await this.preUninstallExtension(extension);
await this.uninstallExtension(extension);
} catch (error) {
await this.postUninstallExtension(extension, new ExtensionManagementError(error instanceof Error ? error.message : error, INSTALL_ERROR_LOCAL));
throw error;
}
await this.postUninstallExtension(extension);
}
private preUninstallExtension(extension: ILocalExtension): Promise<void> {
return Promise.resolve(pfs.exists(extension.location.fsPath))
.then(exists => exists ? null : Promise.reject(new Error(nls.localize('notExists', "Could not find extension"))))
.then(() => {
this.logService.info('Uninstalling extension:', extension.identifier.id);
this._onUninstallExtension.fire(extension.identifier);
});
private async preUninstallExtension(extension: ILocalExtension): Promise<void> {
const exists = await pfs.exists(extension.location.fsPath);
if (!exists) {
throw new Error(nls.localize('notExists', "Could not find extension"));
}
this.logService.info('Uninstalling extension:', extension.identifier.id);
this._onUninstallExtension.fire(extension.identifier);
}
private uninstallExtension(local: ILocalExtension): Promise<void> {
private async uninstallExtension(local: ILocalExtension): Promise<void> {
let promise = this.uninstallingExtensions.get(local.identifier.id);
if (!promise) {
// Set all versions of the extension as uninstalled
promise = createCancelablePromise(token => this.extensionsScanner.scanUserExtensions(false)
.then(userExtensions => this.setUninstalled(...userExtensions.filter(u => areSameExtensions(u.identifier, local.identifier))))
.then(() => { this.uninstallingExtensions.delete(local.identifier.id); }));
promise = createCancelablePromise(async () => {
const userExtensions = await this.extensionsScanner.scanUserExtensions(false);
await this.setUninstalled(...userExtensions.filter(u => areSameExtensions(u.identifier, local.identifier)));
});
this.uninstallingExtensions.set(local.identifier.id, promise);
promise.finally(() => this.uninstallingExtensions.delete(local.identifier.id));
}
return promise;
}
@@ -659,7 +665,9 @@ export class ExtensionManagementService extends Disposable implements IExtension
this.logService.info('Successfully uninstalled extension:', extension.identifier.id);
// 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);
try {
await this.galleryService.reportStatistic(extension.manifest.publisher, extension.manifest.name, extension.manifest.version, StatisticType.Uninstall);
} catch (error) { /* ignore */ }
}
}
this.reportTelemetry('extensionGallery:uninstall', getLocalExtensionTelemetryData(extension), undefined, error);
@@ -675,8 +683,9 @@ export class ExtensionManagementService extends Disposable implements IExtension
return this.extensionsScanner.cleanUp();
}
private isUninstalled(identifier: ExtensionIdentifierWithVersion): Promise<boolean> {
return this.filterUninstalled(identifier).then(uninstalled => uninstalled.length === 1);
private async isUninstalled(identifier: ExtensionIdentifierWithVersion): Promise<boolean> {
const uninstalled = await this.filterUninstalled(identifier);
return uninstalled.length === 1;
}
private filterUninstalled(...identifiers: ExtensionIdentifierWithVersion[]): Promise<string[]> {
@@ -693,7 +702,10 @@ export class ExtensionManagementService extends Disposable implements IExtension
private setUninstalled(...extensions: ILocalExtension[]): Promise<{ [id: string]: boolean }> {
const ids: ExtensionIdentifierWithVersion[] = extensions.map(e => new ExtensionIdentifierWithVersion(e.identifier, e.manifest.version));
return this.extensionsScanner.withUninstalledExtensions(uninstalled => assign(uninstalled, ids.reduce((result, id) => { result[id.key()] = true; return result; }, {} as { [id: string]: boolean })));
return this.extensionsScanner.withUninstalledExtensions(uninstalled => {
ids.forEach(id => uninstalled[id.key()] = true);
return uninstalled;
});
}
private unsetUninstalled(extensionIdentifier: ExtensionIdentifierWithVersion): Promise<void> {
@@ -711,21 +723,16 @@ export class ExtensionManagementService extends Disposable implements IExtension
return this.reportedExtensions;
}
private updateReportCache(): Promise<IReportedExtension[]> {
this.logService.trace('ExtensionManagementService.refreshReportedCache');
return this.galleryService.getExtensionsReport()
.then(result => {
this.logService.trace(`ExtensionManagementService.refreshReportedCache - got ${result.length} reported extensions from service`);
return result;
}, err => {
this.logService.trace('ExtensionManagementService.refreshReportedCache - failed to get extension report');
return [];
});
}
private toNonCancellablePromise<T>(promise: Promise<T>): Promise<T> {
return new Promise((c, e) => promise.then(result => c(result), error => e(error)));
private async updateReportCache(): Promise<IReportedExtension[]> {
try {
this.logService.trace('ExtensionManagementService.refreshReportedCache');
const result = await this.galleryService.getExtensionsReport();
this.logService.trace(`ExtensionManagementService.refreshReportedCache - got ${result.length} reported extensions from service`);
return result;
} catch (err) {
this.logService.trace('ExtensionManagementService.refreshReportedCache - failed to get extension report');
return [];
}
}
private reportTelemetry(eventName: string, extensionData: any, duration?: number, error?: Error): void {
@@ -761,6 +768,6 @@ export class ExtensionManagementService extends Disposable implements IExtension
]
}
*/
this.telemetryService.publicLogError(eventName, assign(extensionData, { success: !error, duration, errorcode }));
this.telemetryService.publicLogError(eventName, { ...extensionData, success: !error, duration, errorcode });
}
}

View File

@@ -6,9 +6,8 @@
import { URI } from 'vs/base/common/uri';
import { join, } from 'vs/base/common/path';
import { IProductService } from 'vs/platform/product/common/productService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { env as processEnv } from 'vs/base/common/process';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IFileService } from 'vs/platform/files/common/files';
import { isWindows } from 'vs/base/common/platform';
import { isNonEmptyArray } from 'vs/base/common/arrays';

View File

@@ -5,7 +5,7 @@
import { Disposable } from 'vs/base/common/lifecycle';
import { join } from 'vs/base/common/path';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { IExtensionManagementService, DidInstallExtensionEvent, DidUninstallExtensionEvent } from 'vs/platform/extensionManagement/common/extensionManagement';
import { MANIFEST_CACHE_FOLDER, USER_MANIFEST_CACHE_FILE } from 'vs/platform/extensions/common/extensions';
import * as pfs from 'vs/base/node/pfs';

View File

@@ -13,8 +13,7 @@ import { ExtensionType, IExtensionManifest, IExtensionIdentifier } from 'vs/plat
import { areSameExtensions, ExtensionIdentifierWithVersion, groupByExtension, getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { Limiter, Queue } from 'vs/base/common/async';
import { URI } from 'vs/base/common/uri';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { getPathFromAmdModule } from 'vs/base/common/amd';
import { localizeManifest } from 'vs/platform/extensionManagement/common/extensionNls';
import { localize } from 'vs/nls';
@@ -23,7 +22,7 @@ import { CancellationToken } from 'vscode';
import { extract, ExtractError } from 'vs/base/node/zip';
import { isWindows } from 'vs/base/common/platform';
import { flatten } from 'vs/base/common/arrays';
import { assign } from 'vs/base/common/objects';
import { IStringDictionary } from 'vs/base/common/collections';
const ERROR_SCANNING_SYS_EXTENSIONS = 'scanningSystem';
const ERROR_SCANNING_USER_EXTENSIONS = 'scanningUser';
@@ -32,6 +31,7 @@ const INSTALL_ERROR_DELETING = 'deleting';
const INSTALL_ERROR_RENAMING = 'renaming';
export type IMetadata = Partial<IGalleryMetadata & { isMachineScoped: boolean; }>;
type ILocalExtensionManifest = IExtensionManifest & { __metadata?: IMetadata };
export class ExtensionsScanner extends Disposable {
@@ -69,7 +69,12 @@ export class ExtensionsScanner extends Disposable {
promises.push(this.scanUserExtensions(true).then(null, e => Promise.reject(new ExtensionManagementError(this.joinErrors(e).message, ERROR_SCANNING_USER_EXTENSIONS))));
}
return Promise.all<ILocalExtension[]>(promises).then(flatten, errors => Promise.reject(this.joinErrors(errors)));
try {
const result = await Promise.all(promises);
return flatten(result);
} catch (error) {
throw this.joinErrors(error);
}
}
async scanUserExtensions(excludeOutdated: boolean): Promise<ILocalExtension[]> {
@@ -134,7 +139,7 @@ export class ExtensionsScanner extends Disposable {
const manifestPath = path.join(local.location.fsPath, 'package.json');
const raw = await pfs.readFile(manifestPath, 'utf8');
const { manifest } = await this.parseManifest(raw);
assign(manifest, { __metadata: metadata });
(manifest as ILocalExtensionManifest).__metadata = metadata;
await pfs.writeFile(manifestPath, JSON.stringify(manifest, null, '\t'));
return local;
}
@@ -143,22 +148,33 @@ export class ExtensionsScanner extends Disposable {
return this.withUninstalledExtensions(uninstalled => uninstalled);
}
async withUninstalledExtensions<T>(fn: (uninstalled: { [id: string]: boolean; }) => T): Promise<T> {
async withUninstalledExtensions<T>(fn: (uninstalled: IStringDictionary<boolean>) => T): Promise<T> {
return this.uninstalledFileLimiter.queue(async () => {
let result: T | null = null;
return pfs.readFile(this.uninstalledPath, 'utf8')
.then(undefined, err => err.code === 'ENOENT' ? Promise.resolve('{}') : Promise.reject(err))
.then<{ [id: string]: boolean }>(raw => { try { return JSON.parse(raw); } catch (e) { return {}; } })
.then(uninstalled => { result = fn(uninstalled); return uninstalled; })
.then(uninstalled => {
if (Object.keys(uninstalled).length === 0) {
return pfs.rimraf(this.uninstalledPath);
} else {
const raw = JSON.stringify(uninstalled);
return pfs.writeFile(this.uninstalledPath, raw);
}
})
.then(() => result);
let raw: string | undefined;
try {
raw = await pfs.readFile(this.uninstalledPath, 'utf8');
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
let uninstalled = {};
if (raw) {
try {
uninstalled = JSON.parse(raw);
} catch (e) { /* ignore */ }
}
const result = fn(uninstalled);
if (Object.keys(uninstalled).length) {
await pfs.writeFile(this.uninstalledPath, JSON.stringify(uninstalled));
} else {
await pfs.rimraf(this.uninstalledPath);
}
return result;
});
}
@@ -173,27 +189,35 @@ export class ExtensionsScanner extends Disposable {
await this.withUninstalledExtensions(uninstalled => delete uninstalled[new ExtensionIdentifierWithVersion(extension.identifier, extension.manifest.version).key()]);
}
private extractAtLocation(identifier: IExtensionIdentifier, zipPath: string, location: string, token: CancellationToken): Promise<void> {
private async extractAtLocation(identifier: IExtensionIdentifier, zipPath: string, location: string, token: CancellationToken): Promise<void> {
this.logService.trace(`Started extracting the extension from ${zipPath} to ${location}`);
return pfs.rimraf(location)
.then(
() => extract(zipPath, location, { sourcePath: 'extension', overwrite: true }, token)
.then(
() => this.logService.info(`Extracted extension to ${location}:`, identifier.id),
e => pfs.rimraf(location).finally(() => { })
.then(() => Promise.reject(new ExtensionManagementError(e.message, e instanceof ExtractError && e.type ? e.type : INSTALL_ERROR_EXTRACTING)))),
e => Promise.reject(new ExtensionManagementError(this.joinErrors(e).message, INSTALL_ERROR_DELETING)));
// Clean the location
try {
await pfs.rimraf(location);
} catch (e) {
throw new ExtensionManagementError(this.joinErrors(e).message, INSTALL_ERROR_DELETING);
}
try {
await extract(zipPath, location, { sourcePath: 'extension', overwrite: true }, token);
this.logService.info(`Extracted extension to ${location}:`, identifier.id);
} catch (e) {
try { await pfs.rimraf(location); } catch (e) { /* Ignore */ }
throw new ExtensionManagementError(e.message, e instanceof ExtractError && e.type ? e.type : INSTALL_ERROR_EXTRACTING);
}
}
private rename(identifier: IExtensionIdentifier, extractPath: string, renamePath: string, retryUntil: number): Promise<void> {
return pfs.rename(extractPath, renamePath)
.then(undefined, error => {
if (isWindows && error && error.code === 'EPERM' && Date.now() < retryUntil) {
this.logService.info(`Failed renaming ${extractPath} to ${renamePath} with 'EPERM' error. Trying again...`, identifier.id);
return this.rename(identifier, extractPath, renamePath, retryUntil);
}
return Promise.reject(new ExtensionManagementError(error.message || localize('renameError', "Unknown error while renaming {0} to {1}", extractPath, renamePath), error.code || INSTALL_ERROR_RENAMING));
});
private async rename(identifier: IExtensionIdentifier, extractPath: string, renamePath: string, retryUntil: number): Promise<void> {
try {
await pfs.rename(extractPath, renamePath);
} catch (error) {
if (isWindows && error && error.code === 'EPERM' && Date.now() < retryUntil) {
this.logService.info(`Failed renaming ${extractPath} to ${renamePath} with 'EPERM' error. Trying again...`, identifier.id);
return this.rename(identifier, extractPath, renamePath, retryUntil);
}
throw new ExtensionManagementError(error.message || localize('renameError', "Unknown error while renaming {0} to {1}", extractPath, renamePath), error.code || INSTALL_ERROR_RENAMING);
}
}
private async scanSystemExtensions(): Promise<ILocalExtension[]> {

View File

@@ -53,7 +53,7 @@ suite('Extension Gallery Service', () => {
test('marketplace machine id', () => {
const args = ['--user-data-dir', marketplaceHome];
const environmentService = new EnvironmentService(parseArgs(args, OPTIONS), process.execPath);
const environmentService = new EnvironmentService(parseArgs(args, OPTIONS));
const storageService: IStorageService = new TestStorageService();
return resolveMarketplaceHeaders(product.version, environmentService, fileService, storageService).then(headers => {

View File

@@ -856,6 +856,7 @@ export function whenProviderRegistered(file: URI, fileService: IFileService): Pr
if (fileService.canHandleResource(URI.from({ scheme: file.scheme }))) {
return Promise.resolve();
}
return new Promise((c, e) => {
const disposable = fileService.onDidChangeFileSystemProviderRegistrations(e => {
if (e.scheme === file.scheme && e.added) {

View File

@@ -85,7 +85,7 @@ export class FileWatcher extends Disposable {
}
// Handle emit through delayer to accommodate for bulk changes and thus reduce spam
this.fileChangesDelayer.trigger(() => {
this.fileChangesDelayer.trigger(async () => {
const fileChanges = this.fileChangesBuffer;
this.fileChangesBuffer = [];
@@ -103,8 +103,6 @@ export class FileWatcher extends Disposable {
if (normalizedFileChanges.length > 0) {
this.onDidFilesChange(normalizedFileChanges);
}
return Promise.resolve();
});
}

View File

@@ -22,8 +22,8 @@ nsfwActionToRawChangeType[nsfw.actions.MODIFIED] = FileChangeType.UPDATED;
nsfwActionToRawChangeType[nsfw.actions.DELETED] = FileChangeType.DELETED;
interface IWatcherObjet {
start(): any;
stop(): any;
start(): void;
stop(): void;
}
interface IPathWatcher {
@@ -142,7 +142,7 @@ export class NsfwWatcherService implements IWatcherService {
}
// Delay and send buffer
fileEventDelayer.trigger(() => {
fileEventDelayer.trigger(async () => {
const events = undeliveredFileEvents;
undeliveredFileEvents = [];
@@ -169,8 +169,6 @@ export class NsfwWatcherService implements IWatcherService {
this.log(` >> normalized ${r.type === FileChangeType.ADDED ? '[ADDED]' : r.type === FileChangeType.DELETED ? '[DELETED]' : '[CHANGED]'} ${r.path}`);
});
}
return Promise.resolve(undefined);
});
}).then(watcher => {
this._pathWatchers[request.path].watcher = watcher;
@@ -180,8 +178,7 @@ export class NsfwWatcherService implements IWatcherService {
});
}
public setRoots(roots: IWatcherRequest[]): Promise<void> {
const promises: Promise<void>[] = [];
async setRoots(roots: IWatcherRequest[]): Promise<void> {
const normalizedRoots = this._normalizeRoots(roots);
// Gather roots that are not currently being watched
@@ -214,23 +211,19 @@ export class NsfwWatcherService implements IWatcherService {
this._pathWatchers[root.path].ignored = Array.isArray(root.excludes) ? root.excludes.map(ignored => glob.parse(ignored)) : [];
}
});
return Promise.all(promises).then(() => undefined);
}
public setVerboseLogging(enabled: boolean): Promise<void> {
async setVerboseLogging(enabled: boolean): Promise<void> {
this._verboseLogging = enabled;
return Promise.resolve(undefined);
}
public stop(): Promise<void> {
async stop(): Promise<void> {
for (let path in this._pathWatchers) {
let watcher = this._pathWatchers[path];
watcher.ready.then(watcher => watcher.stop());
delete this._pathWatchers[path];
}
this._pathWatchers = Object.create(null);
return Promise.resolve();
}
/**

View File

@@ -10,11 +10,14 @@ import { NsfwWatcherService } from 'vs/platform/files/node/watcher/nsfw/nsfwWatc
import { IWatcherRequest } from 'vs/platform/files/node/watcher/nsfw/watcher';
class TestNsfwWatcherService extends NsfwWatcherService {
public normalizeRoots(roots: string[]): string[] {
normalizeRoots(roots: string[]): string[] {
// Work with strings as paths to simplify testing
const requests: IWatcherRequest[] = roots.map(r => {
return { path: r, excludes: [] };
});
return this._normalizeRoots(requests).map(r => r.path);
}
}

View File

@@ -23,7 +23,7 @@ process.noAsar = true; // disable ASAR support in watcher process
interface IWatcher {
requests: ExtendedWatcherRequest[];
stop(): any;
stop(): Promise<void>;
}
interface ExtendedWatcherRequest extends IWatcherRequest {
@@ -61,13 +61,11 @@ export class ChokidarWatcherService implements IWatcherService {
return this.onWatchEvent;
}
setVerboseLogging(enabled: boolean): Promise<void> {
async setVerboseLogging(enabled: boolean): Promise<void> {
this._verboseLogging = enabled;
return Promise.resolve();
}
setRoots(requests: IWatcherRequest[]): Promise<void> {
async setRoots(requests: IWatcherRequest[]): Promise<void> {
const watchers = Object.create(null);
const newRequests: string[] = [];
@@ -86,7 +84,7 @@ export class ChokidarWatcherService implements IWatcherService {
// stop all old watchers
for (const path in this._watchers) {
this._watchers[path].stop();
await this._watchers[path].stop();
}
// start all new watchers
@@ -96,7 +94,6 @@ export class ChokidarWatcherService implements IWatcherService {
}
this._watchers = watchers;
return Promise.resolve();
}
// for test purposes
@@ -166,13 +163,13 @@ export class ChokidarWatcherService implements IWatcherService {
const watcher: IWatcher = {
requests,
stop: () => {
stop: async () => {
try {
if (this._verboseLogging) {
this.log(`Stop watching: ${basePath}]`);
}
if (chokidarWatcher) {
chokidarWatcher.close();
await chokidarWatcher.close();
this._watcherCount--;
chokidarWatcher = null;
}
@@ -248,8 +245,9 @@ export class ChokidarWatcherService implements IWatcherService {
undeliveredFileEvents.push(event);
if (fileEventDelayer) {
// Delay and send buffer
fileEventDelayer.trigger(() => {
fileEventDelayer.trigger(async () => {
const events = undeliveredFileEvents;
undeliveredFileEvents = [];
@@ -264,7 +262,7 @@ export class ChokidarWatcherService implements IWatcherService {
});
}
return Promise.resolve(undefined);
return undefined;
});
}
});
@@ -291,15 +289,13 @@ export class ChokidarWatcherService implements IWatcherService {
return watcher;
}
stop(): Promise<void> {
async stop(): Promise<void> {
for (const path in this._watchers) {
const watcher = this._watchers[path];
watcher.stop();
await watcher.stop();
}
this._watchers = Object.create(null);
return Promise.resolve();
}
private log(message: string) {

View File

@@ -131,7 +131,7 @@ export class OutOfProcessWin32FolderWatcher {
this.logCallback({ type: 'trace', message: `[File Watcher (C#)] ${message}` });
}
public dispose(): void {
dispose(): void {
if (this.handle) {
this.handle.kill();
this.handle = undefined;

View File

@@ -26,16 +26,16 @@ export class NullFileSystemProvider implements IFileSystemProvider {
constructor(private disposableFactory: () => IDisposable = () => Disposable.None) { }
watch(resource: URI, opts: IWatchOptions): IDisposable { return this.disposableFactory(); }
stat(resource: URI): Promise<IStat> { return Promise.resolve(undefined!); }
mkdir(resource: URI): Promise<void> { return Promise.resolve(undefined!); }
readdir(resource: URI): Promise<[string, FileType][]> { return Promise.resolve(undefined!); }
delete(resource: URI, opts: FileDeleteOptions): Promise<void> { return Promise.resolve(undefined!); }
rename(from: URI, to: URI, opts: FileOverwriteOptions): Promise<void> { return Promise.resolve(undefined!); }
copy?(from: URI, to: URI, opts: FileOverwriteOptions): Promise<void> { return Promise.resolve(undefined!); }
readFile?(resource: URI): Promise<Uint8Array> { return Promise.resolve(undefined!); }
writeFile?(resource: URI, content: Uint8Array, opts: FileWriteOptions): Promise<void> { return Promise.resolve(undefined!); }
open?(resource: URI, opts: FileOpenOptions): Promise<number> { return Promise.resolve(undefined!); }
close?(fd: number): Promise<void> { return Promise.resolve(undefined!); }
read?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number> { return Promise.resolve(undefined!); }
write?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number> { return Promise.resolve(undefined!); }
async stat(resource: URI): Promise<IStat> { return undefined!; }
async mkdir(resource: URI): Promise<void> { return undefined; }
async readdir(resource: URI): Promise<[string, FileType][]> { return undefined!; }
async delete(resource: URI, opts: FileDeleteOptions): Promise<void> { return undefined; }
async rename(from: URI, to: URI, opts: FileOverwriteOptions): Promise<void> { return undefined; }
async copy?(from: URI, to: URI, opts: FileOverwriteOptions): Promise<void> { return undefined; }
async readFile?(resource: URI): Promise<Uint8Array> { return undefined!; }
async writeFile?(resource: URI, content: Uint8Array, opts: FileWriteOptions): Promise<void> { return undefined; }
async open?(resource: URI, opts: FileOpenOptions): Promise<number> { return undefined!; }
async close?(fd: number): Promise<void> { return undefined; }
async read?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number> { return undefined!; }
async write?(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number> { return undefined!; }
}

View File

@@ -17,8 +17,7 @@ export interface WindowData {
export const enum IssueType {
Bug,
PerformanceIssue,
FeatureRequest,
SettingsSearchIssue
FeatureRequest
}
export interface IssueReporterStyles extends WindowStyles {
@@ -66,13 +65,6 @@ export interface ISettingSearchResult {
score: number;
}
export interface ISettingsSearchIssueReporterData extends IssueReporterData {
issueType: IssueType.SettingsSearchIssue;
actualSearchResults: ISettingSearchResult[];
query: string;
filterResultCount: number;
}
export interface IssueReporterFeatures {
}

View File

@@ -13,8 +13,7 @@ import { BrowserWindow, ipcMain, screen, IpcMainEvent, Display, shell } from 'el
import { ILaunchMainService } from 'vs/platform/launch/electron-main/launchMainService';
import { PerformanceInfo, isRemoteDiagnosticError } from 'vs/platform/diagnostics/common/diagnostics';
import { IDiagnosticsService } from 'vs/platform/diagnostics/node/diagnosticsService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { isMacintosh, IProcessEnvironment } from 'vs/base/common/platform';
import { ILogService } from 'vs/platform/log/common/log';
import { IWindowState } from 'vs/platform/windows/electron-main/windows';
@@ -200,6 +199,7 @@ export class IssueMainService implements ICommonIssueService {
preload: URI.parse(require.toUrl('vs/base/parts/sandbox/electron-browser/preload.js')).fsPath,
enableWebSQL: false,
enableRemoteModule: false,
spellcheck: false,
nativeWindowOpen: true,
zoomFactor: zoomLevelToZoomFactor(data.zoomLevel),
...this.environmentService.sandbox ?
@@ -265,6 +265,7 @@ export class IssueMainService implements ICommonIssueService {
preload: URI.parse(require.toUrl('vs/base/parts/sandbox/electron-browser/preload.js')).fsPath,
enableWebSQL: false,
enableRemoteModule: false,
spellcheck: false,
nativeWindowOpen: true,
zoomFactor: zoomLevelToZoomFactor(data.zoomLevel),
...this.environmentService.sandbox ?

View File

@@ -6,7 +6,7 @@
import { ILogService } from 'vs/platform/log/common/log';
import { IURLService } from 'vs/platform/url/common/url';
import { IProcessEnvironment, isMacintosh } from 'vs/base/common/platform';
import { ParsedArgs } from 'vs/platform/environment/node/argv';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IWindowSettings } from 'vs/platform/windows/common/windows';
import { OpenContext } from 'vs/platform/windows/node/window';
@@ -24,7 +24,7 @@ export const ID = 'launchMainService';
export const ILaunchMainService = createDecorator<ILaunchMainService>(ID);
export interface IStartArguments {
args: ParsedArgs;
args: NativeParsedArgs;
userEnv: IProcessEnvironment;
}
@@ -33,7 +33,7 @@ export interface IRemoteDiagnosticOptions {
includeWorkspaceMetadata?: boolean;
}
function parseOpenUrl(args: ParsedArgs): URI[] {
function parseOpenUrl(args: NativeParsedArgs): URI[] {
if (args['open-url'] && args._urls && args._urls.length > 0) {
// --open-url must contain -- followed by the url(s)
// process.argv is used over args._ as args._ are resolved to file paths at this point
@@ -52,7 +52,7 @@ function parseOpenUrl(args: ParsedArgs): URI[] {
export interface ILaunchMainService {
readonly _serviceBrand: undefined;
start(args: ParsedArgs, userEnv: IProcessEnvironment): Promise<void>;
start(args: NativeParsedArgs, userEnv: IProcessEnvironment): Promise<void>;
getMainProcessId(): Promise<number>;
getMainProcessInfo(): Promise<IMainProcessInfo>;
getRemoteDiagnostics(options: IRemoteDiagnosticOptions): Promise<(IRemoteDiagnosticInfo | IRemoteDiagnosticError)[]>;
@@ -70,7 +70,7 @@ export class LaunchMainService implements ILaunchMainService {
@IConfigurationService private readonly configurationService: IConfigurationService
) { }
async start(args: ParsedArgs, userEnv: IProcessEnvironment): Promise<void> {
async start(args: NativeParsedArgs, userEnv: IProcessEnvironment): Promise<void> {
this.logService.trace('Received data from other instance: ', args, userEnv);
// Since we now start to open a window, make sure the app has focus.
@@ -103,7 +103,7 @@ export class LaunchMainService implements ILaunchMainService {
}
}
private startOpenWindow(args: ParsedArgs, userEnv: IProcessEnvironment): Promise<void> {
private startOpenWindow(args: NativeParsedArgs, userEnv: IProcessEnvironment): Promise<void> {
const context = !!userEnv['VSCODE_CLI'] ? OpenContext.CLI : OpenContext.DESKTOP;
let usedWindows: ICodeWindow[] = [];
@@ -238,7 +238,7 @@ export class LaunchMainService implements ILaunchMainService {
getRemoteDiagnostics(options: IRemoteDiagnosticOptions): Promise<(IRemoteDiagnosticInfo | IRemoteDiagnosticError)[]> {
const windows = this.windowsMainService.getWindows();
const promises: Promise<IDiagnosticInfo | IRemoteDiagnosticError | undefined>[] = windows.map(window => {
return new Promise((resolve, reject) => {
return new Promise<IDiagnosticInfo | IRemoteDiagnosticError | undefined>((resolve) => {
const remoteAuthority = window.remoteAuthority;
if (remoteAuthority) {
const replyChannel = `vscode:getDiagnosticInfoResponse${window.id}`;
@@ -262,7 +262,7 @@ export class LaunchMainService implements ILaunchMainService {
resolve({ hostName: remoteAuthority, errorMessage: `Fetching remote diagnostics for '${remoteAuthority}' timed out.` });
}, 5000);
} else {
resolve();
resolve(undefined);
}
});
});

View File

@@ -13,7 +13,7 @@ import { handleVetos } from 'vs/platform/lifecycle/common/lifecycle';
import { isMacintosh, isWindows } from 'vs/base/common/platform';
import { Disposable } from 'vs/base/common/lifecycle';
import { Barrier, timeout } from 'vs/base/common/async';
import { ParsedArgs } from 'vs/platform/environment/node/argv';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
export const ILifecycleMainService = createDecorator<ILifecycleMainService>('lifecycleMainService');
@@ -86,7 +86,7 @@ export interface ILifecycleMainService {
/**
* Reload a window. All lifecycle event handlers are triggered.
*/
reload(window: ICodeWindow, cli?: ParsedArgs): Promise<void>;
reload(window: ICodeWindow, cli?: NativeParsedArgs): Promise<void>;
/**
* Unload a window for the provided reason. All lifecycle event handlers are triggered.
@@ -366,7 +366,7 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
});
}
async reload(window: ICodeWindow, cli?: ParsedArgs): Promise<void> {
async reload(window: ICodeWindow, cli?: NativeParsedArgs): Promise<void> {
// Only reload when the window has not vetoed this
const veto = await this.unload(window, UnloadReason.RELOAD);

View File

@@ -7,8 +7,7 @@ import * as pfs from 'vs/base/node/pfs';
import { createHash } from 'crypto';
import { IExtensionManagementService, ILocalExtension, IExtensionIdentifier } from 'vs/platform/extensionManagement/common/extensionManagement';
import { Disposable } from 'vs/base/common/lifecycle';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { Queue } from 'vs/base/common/async';
import { areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { ILogService } from 'vs/platform/log/common/log';

View File

@@ -5,7 +5,7 @@
import * as nls from 'vs/nls';
import { isMacintosh, language } from 'vs/base/common/platform';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { app, shell, Menu, MenuItem, BrowserWindow, MenuItemConstructorOptions, WebContents, Event, KeyboardEvent } from 'electron';
import { getTitleBarStyle, INativeRunActionInWindowRequest, INativeRunKeybindingInWindowRequest, IWindowOpenable } from 'vs/platform/windows/common/windows';
import { OpenContext } from 'vs/platform/windows/node/window';
@@ -24,7 +24,6 @@ import { IStateService } from 'vs/platform/state/node/state';
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification } from 'vs/base/common/actions';
import { IElectronMainService } from 'vs/platform/electron/electron-main/electronMainService';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
const telemetryFrom = 'menu';

View File

@@ -6,10 +6,8 @@
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
export const REMOTE_HOST_SCHEME = Schemas.vscodeRemote;
export function getRemoteAuthority(uri: URI): string | undefined {
return uri.scheme === REMOTE_HOST_SCHEME ? uri.authority : undefined;
return uri.scheme === Schemas.vscodeRemote ? uri.authority : undefined;
}
export function getRemoteName(authority: string): string;

View File

@@ -5,7 +5,6 @@
import { IRequestOptions, IRequestContext } from 'vs/base/parts/request/common/request';
import { RequestService as NodeRequestService, IRawRequestFunction } from 'vs/platform/request/node/requestService';
import { assign } from 'vs/base/common/objects';
import { net } from 'electron';
import { CancellationToken } from 'vs/base/common/cancellation';
@@ -16,6 +15,6 @@ function getRawRequest(options: IRequestOptions): IRawRequestFunction {
export class RequestMainService extends NodeRequestService {
request(options: IRequestOptions, token: CancellationToken): Promise<IRequestContext> {
return super.request(assign({}, options || {}, { getRawRequest }), token);
return super.request({ ...(options || {}), getRawRequest }, token);
}
}

View File

@@ -9,7 +9,6 @@ import * as streams from 'vs/base/common/stream';
import { createGunzip } from 'zlib';
import { parse as parseUrl } from 'url';
import { Disposable } from 'vs/base/common/lifecycle';
import { assign } from 'vs/base/common/objects';
import { isBoolean, isNumber } from 'vs/base/common/types';
import { canceled } from 'vs/base/common/errors';
import { CancellationToken } from 'vs/base/common/cancellation';
@@ -67,7 +66,10 @@ export class RequestService extends Disposable implements IRequestService {
options.strictSSL = strictSSL;
if (this.authorization) {
options.headers = assign(options.headers || {}, { 'Proxy-Authorization': this.authorization });
options.headers = {
...(options.headers || {}),
'Proxy-Authorization': this.authorization
};
}
return this._request(options, token);
@@ -107,10 +109,11 @@ export class RequestService extends Disposable implements IRequestService {
req = rawRequest(opts, (res: http.IncomingMessage) => {
const followRedirects: number = isNumber(options.followRedirects) ? options.followRedirects : 3;
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && followRedirects > 0 && res.headers['location']) {
this._request(assign({}, options, {
this._request({
...options,
url: res.headers['location'],
followRedirects: followRedirects - 1
}), token).then(c, e);
}, token).then(c, e);
} else {
let stream: streams.ReadableStreamEvents<Uint8Array> = res;

View File

@@ -5,8 +5,7 @@
import * as path from 'vs/base/common/path';
import * as fs from 'fs';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { writeFileSync, readFile } from 'vs/base/node/pfs';
import { isUndefined, isUndefinedOrNull } from 'vs/base/common/types';
import { IStateService } from 'vs/platform/state/node/state';

View File

@@ -8,7 +8,6 @@ import { Event, Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { SQLiteStorageDatabase, ISQLiteStorageDatabaseLoggingOptions } from 'vs/base/parts/storage/node/storage';
import { Storage, IStorage, InMemoryStorageDatabase } from 'vs/base/parts/storage/common/storage';
import { join } from 'vs/base/common/path';
@@ -105,7 +104,7 @@ export class StorageMainService extends Disposable implements IStorageMainServic
constructor(
@ILogService private readonly logService: ILogService,
@IEnvironmentService private readonly environmentService: INativeEnvironmentService
@IEnvironmentService private readonly environmentService: IEnvironmentService
) {
super();

View File

@@ -13,7 +13,6 @@ import { mark } from 'vs/base/common/performance';
import { join } from 'vs/base/common/path';
import { copy, exists, mkdirp, writeFile } from 'vs/base/node/pfs';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IWorkspaceInitializationPayload, isWorkspaceIdentifier, isSingleFolderWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces';
import { assertIsDefined } from 'vs/base/common/types';
import { RunOnceScheduler, runWhenIdle } from 'vs/base/common/async';
@@ -45,7 +44,7 @@ export class NativeStorageService extends Disposable implements IStorageService
constructor(
private globalStorageDatabase: IStorageDatabase,
@ILogService private readonly logService: ILogService,
@IEnvironmentService private readonly environmentService: INativeEnvironmentService
@IEnvironmentService private readonly environmentService: IEnvironmentService
) {
super();

View File

@@ -87,7 +87,7 @@ suite('StorageService', () => {
class StorageTestEnvironmentService extends EnvironmentService {
constructor(private workspaceStorageFolderPath: URI, private _extensionsPath: string) {
super(parseArgs(process.argv, OPTIONS), process.execPath);
super(parseArgs(process.argv, OPTIONS));
}
get workspaceStorageHome(): URI {

View File

@@ -0,0 +1,13 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
* Color scheme used by the OS and by color themes.
*/
export enum ColorScheme {
DARK = 'dark',
LIGHT = 'light',
HIGH_CONTRAST = 'hc'
}

View File

@@ -10,6 +10,7 @@ import * as platform from 'vs/platform/registry/common/platform';
import { ColorIdentifier } from 'vs/platform/theme/common/colorRegistry';
import { Event, Emitter } from 'vs/base/common/event';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ColorScheme } from 'vs/platform/theme/common/theme';
export const IThemeService = createDecorator<IThemeService>('themeService');
@@ -65,16 +66,10 @@ export namespace ThemeIcon {
export const FileThemeIcon = { id: 'file' };
export const FolderThemeIcon = { id: 'folder' };
// base themes
export const DARK: ThemeType = 'dark';
export const LIGHT: ThemeType = 'light';
export const HIGH_CONTRAST: ThemeType = 'hc';
export type ThemeType = 'light' | 'dark' | 'hc';
export function getThemeTypeSelector(type: ThemeType): string {
export function getThemeTypeSelector(type: ColorScheme): string {
switch (type) {
case DARK: return 'vs-dark';
case HIGH_CONTRAST: return 'hc-black';
case ColorScheme.DARK: return 'vs-dark';
case ColorScheme.HIGH_CONTRAST: return 'hc-black';
default: return 'vs';
}
}
@@ -88,7 +83,7 @@ export interface ITokenStyle {
export interface IColorTheme {
readonly type: ThemeType;
readonly type: ColorScheme;
readonly label: string;

View File

@@ -4,14 +4,15 @@
*--------------------------------------------------------------------------------------------*/
import { Event, Emitter } from 'vs/base/common/event';
import { IThemeService, IColorTheme, DARK, IFileIconTheme, ITokenStyle } from 'vs/platform/theme/common/themeService';
import { IThemeService, IColorTheme, IFileIconTheme, ITokenStyle } from 'vs/platform/theme/common/themeService';
import { Color } from 'vs/base/common/color';
import { ColorScheme } from 'vs/platform/theme/common/theme';
export class TestColorTheme implements IColorTheme {
public readonly label = 'test';
constructor(private colors: { [id: string]: string; } = {}, public type = DARK) {
constructor(private colors: { [id: string]: string; } = {}, public type = ColorScheme.DARK) {
}
getColor(color: string, useDefault?: boolean): Color | undefined {

View File

@@ -9,8 +9,7 @@ import { IConfigurationService, getMigratedSettingValue } from 'vs/platform/conf
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import product from 'vs/platform/product/common/product';
import { IUpdateService, State, StateType, AvailableForDownload, UpdateType } from 'vs/platform/update/common/update';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/platform/log/common/log';
import { IRequestService } from 'vs/platform/request/common/request';
import { CancellationToken } from 'vs/base/common/cancellation';

View File

@@ -11,8 +11,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { State, IUpdate, StateType, UpdateType } from 'vs/platform/update/common/update';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/platform/log/common/log';
import { AbstractUpdateService, createUpdateURL, UpdateNotAvailableClassification } from 'vs/platform/update/electron-main/abstractUpdateService';
import { IRequestService } from 'vs/platform/request/common/request';

View File

@@ -8,8 +8,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { State, IUpdate, AvailableForDownload, UpdateType } from 'vs/platform/update/common/update';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/platform/log/common/log';
import { createUpdateURL, AbstractUpdateService, UpdateNotAvailableClassification } from 'vs/platform/update/electron-main/abstractUpdateService';
import { IRequestService, asJson } from 'vs/platform/request/common/request';

View File

@@ -7,8 +7,7 @@ import { Event, Emitter } from 'vs/base/common/event';
import { timeout } from 'vs/base/common/async';
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { IUpdateService, State, StateType, AvailableForDownload, UpdateType } from 'vs/platform/update/common/update';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/platform/log/common/log';
import * as path from 'vs/base/common/path';
import { realpath, watch } from 'fs';

View File

@@ -12,8 +12,7 @@ import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifec
import product from 'vs/platform/product/common/product';
import { State, IUpdate, StateType, AvailableForDownload, UpdateType } from 'vs/platform/update/common/update';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/platform/log/common/log';
import { createUpdateURL, AbstractUpdateService, UpdateNotAvailableClassification } from 'vs/platform/update/electron-main/abstractUpdateService';
import { IRequestService, asJson } from 'vs/platform/request/common/request';

View File

@@ -8,7 +8,6 @@ import { URI } from 'vs/base/common/uri';
import { Event } from 'vs/base/common/event';
import { IURLHandler, IOpenURLOptions } from 'vs/platform/url/common/url';
import { CancellationToken } from 'vs/base/common/cancellation';
import { first } from 'vs/base/common/arrays';
export class URLHandlerChannel implements IServerChannel {
@@ -54,7 +53,7 @@ export class URLHandlerRouter implements IClientRouter<string> {
if (match) {
const windowId = match[1];
const regex = new RegExp(`window:${windowId}`);
const connection = first(hub.connections, c => regex.test(c.ctx));
const connection = hub.connections.find(c => regex.test(c.ctx));
if (connection) {
return connection;

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { Event } from 'vs/base/common/event';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { IURLService } from 'vs/platform/url/common/url';
import product from 'vs/platform/product/common/product';
import { app, Event as ElectronEvent } from 'electron';

View File

@@ -6,7 +6,7 @@
import * as objects from 'vs/base/common/objects';
import { parse } from 'vs/base/common/json';
import { IUserFriendlyKeybinding } from 'vs/platform/keybinding/common/keybinding';
import { firstIndex as findFirstIndex, equals } from 'vs/base/common/arrays';
import { equals } from 'vs/base/common/arrays';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import * as contentUtil from 'vs/platform/userDataSync/common/content';
import { IStringDictionary } from 'vs/base/common/collections';
@@ -346,7 +346,7 @@ function removeKeybindings(content: string, command: string, formattingOptions:
function updateKeybindings(content: string, command: string, keybindings: IUserFriendlyKeybinding[], formattingOptions: FormattingOptions): string {
const allKeybindings = parseKeybindings(content);
const location = findFirstIndex(allKeybindings, keybinding => keybinding.command === command || keybinding.command === `-${command}`);
const location = allKeybindings.findIndex(keybinding => keybinding.command === command || keybinding.command === `-${command}`);
// Remove all entries with this command
for (let index = allKeybindings.length - 1; index >= 0; index--) {
if (allKeybindings[index].command === command || allKeybindings[index].command === `-${command}`) {

View File

@@ -10,7 +10,7 @@ import { IStringDictionary } from 'vs/base/common/collections';
import { FormattingOptions, Edit, getEOL } from 'vs/base/common/jsonFormatter';
import * as contentUtil from 'vs/platform/userDataSync/common/content';
import { IConflictSetting, getDisallowedIgnoredSettings } from 'vs/platform/userDataSync/common/userDataSync';
import { firstIndex, distinct } from 'vs/base/common/arrays';
import { distinct } from 'vs/base/common/arrays';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
export interface IMergeResult {
@@ -320,7 +320,7 @@ interface InsertLocation {
function getInsertLocation(key: string, sourceTree: INode[], targetTree: INode[]): InsertLocation {
const sourceNodeIndex = firstIndex(sourceTree, (node => node.setting?.key === key));
const sourceNodeIndex = sourceTree.findIndex(node => node.setting?.key === key);
const sourcePreviousNode: INode = sourceTree[sourceNodeIndex - 1];
if (sourcePreviousNode) {

View File

@@ -15,7 +15,6 @@ import { getServiceMachineId } from 'vs/platform/serviceMachineId/common/service
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IFileService } from 'vs/platform/files/common/files';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { assign } from 'vs/base/common/objects';
import { generateUuid } from 'vs/base/common/uuid';
import { isWeb } from 'vs/base/common/platform';
import { Emitter, Event } from 'vs/base/common/event';
@@ -355,10 +354,12 @@ export class UserDataSyncStoreClient extends Disposable implements IUserDataSync
this.setDonotMakeRequestsUntil(undefined);
const commonHeaders = await this.commonHeadersPromise;
options.headers = assign(options.headers || {}, commonHeaders, {
options.headers = {
...(options.headers || {}),
...commonHeaders,
'X-Account-Type': this.authToken.type,
'authorization': `Bearer ${this.authToken.token}`,
});
};
// Add session headers
this.addSessionHeaders(options.headers);

View File

@@ -4,9 +4,9 @@
*--------------------------------------------------------------------------------------------*/
import { IDisposable } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
import { IAddress } from 'vs/platform/remote/common/remoteAgentConnection';
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
import { extractLocalHostUriMetaDataForPortMapping, ITunnelService, RemoteTunnel } from 'vs/platform/remote/common/tunnel';
export interface IWebviewPortMapping {
@@ -37,7 +37,7 @@ export class WebviewPortMappingManager implements IDisposable {
for (const mapping of this._getMappings()) {
if (mapping.webviewPort === requestLocalHostInfo.port) {
const extensionLocation = this._getExtensionLocation();
if (extensionLocation && extensionLocation.scheme === REMOTE_HOST_SCHEME) {
if (extensionLocation && extensionLocation.scheme === Schemas.vscodeRemote) {
const tunnel = resolveAuthority && await this.getOrCreateTunnel(resolveAuthority, mapping.extensionHostPort);
if (tunnel) {
if (tunnel.tunnelLocalPort === mapping.webviewPort) {

View File

@@ -11,7 +11,6 @@ import { Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
import { FileOperationError, FileOperationResult, IFileService } from 'vs/platform/files/common/files';
import { IRemoteConnectionData } from 'vs/platform/remote/common/remoteAuthorityResolver';
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
import { IRequestService } from 'vs/platform/request/common/request';
import { loadLocalResource, webviewPartitionId, WebviewResourceResponse } from 'vs/platform/webview/common/resourceLoader';
import { IWindowsMainService } from 'vs/platform/windows/electron-main/windows';
@@ -161,7 +160,7 @@ export class WebviewProtocolProvider extends Disposable {
if (metadata.remoteConnectionData) {
rewriteUri = (uri) => {
if (metadata.remoteConnectionData) {
if (uri.scheme === Schemas.vscodeRemote || (metadata.extensionLocation?.scheme === REMOTE_HOST_SCHEME)) {
if (uri.scheme === Schemas.vscodeRemote || (metadata.extensionLocation?.scheme === Schemas.vscodeRemote)) {
return URI.parse(`http://${metadata.remoteConnectionData.host}:${metadata.remoteConnectionData.port}`).with({
path: '/vscode-remote-resource',
query: `tkn=${metadata.remoteConnectionData.connectionToken}&path=${encodeURIComponent(uri.path)}`,

View File

@@ -3,11 +3,15 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { isMacintosh, isLinux, isWeb } from 'vs/base/common/platform';
import { isMacintosh, isLinux, isWeb, IProcessEnvironment } from 'vs/base/common/platform';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { URI, UriComponents } from 'vs/base/common/uri';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { LogLevel } from 'vs/platform/log/common/log';
import { ExportData } from 'vs/base/common/performance';
import { ColorScheme } from 'vs/platform/theme/common/theme';
export interface IBaseOpenWindowsOptions {
forceReuseWindow?: boolean;
@@ -208,13 +212,41 @@ export interface IWindowConfiguration {
remoteAuthority?: string;
highContrast?: boolean;
colorScheme: ColorScheme;
autoDetectHighContrast?: boolean;
filesToOpenOrCreate?: IPath[];
filesToDiff?: IPath[];
}
export interface INativeWindowConfiguration extends IWindowConfiguration, NativeParsedArgs {
mainPid: number;
windowId: number;
machineId: string;
appRoot: string;
execPath: string;
backupPath?: string;
nodeCachedDataDir?: string;
partsSplashPath: string;
workspace?: IWorkspaceIdentifier;
folderUri?: ISingleFolderWorkspaceIdentifier;
isInitialStartup?: boolean;
logLevel: LogLevel;
zoomLevel?: number;
fullscreen?: boolean;
maximized?: boolean;
accessibilitySupport?: boolean;
perfEntries: ExportData;
userEnv: IProcessEnvironment;
filesToWait?: IPathsToWaitFor;
}
/**
* According to Electron docs: `scale := 1.2 ^ level`.
* https://github.com/electron/electron/blob/master/docs/api/web-contents.md#contentssetzoomlevellevel

View File

@@ -3,9 +3,9 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IWindowOpenable, IOpenEmptyWindowOptions } from 'vs/platform/windows/common/windows';
import { INativeWindowConfiguration, OpenContext } from 'vs/platform/windows/node/window';
import { ParsedArgs } from 'vs/platform/environment/node/argv';
import { IWindowOpenable, IOpenEmptyWindowOptions, INativeWindowConfiguration } from 'vs/platform/windows/common/windows';
import { OpenContext } from 'vs/platform/windows/node/window';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { Event } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IProcessEnvironment } from 'vs/base/common/platform';
@@ -59,7 +59,7 @@ export interface ICodeWindow extends IDisposable {
addTabbedWindow(window: ICodeWindow): void;
load(config: INativeWindowConfiguration, isReload?: boolean): void;
reload(configuration?: INativeWindowConfiguration, cli?: ParsedArgs): void;
reload(configuration?: INativeWindowConfiguration, cli?: NativeParsedArgs): void;
focus(options?: { force: boolean }): void;
close(): void;
@@ -121,7 +121,7 @@ export interface IBaseOpenConfiguration {
}
export interface IOpenConfiguration extends IBaseOpenConfiguration {
readonly cli: ParsedArgs;
readonly cli: NativeParsedArgs;
readonly userEnv?: IProcessEnvironment;
readonly urisToOpen?: IWindowOpenable[];
readonly waitMarkerFileURI?: URI;

View File

@@ -10,17 +10,16 @@ import * as arrays from 'vs/base/common/arrays';
import { mixin } from 'vs/base/common/objects';
import { IBackupMainService } from 'vs/platform/backup/electron-main/backup';
import { IEmptyWindowBackupInfo } from 'vs/platform/backup/node/backup';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ParsedArgs } from 'vs/platform/environment/node/argv';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { IStateService } from 'vs/platform/state/node/state';
import { CodeWindow, defaultWindowState } from 'vs/code/electron-main/window';
import { screen, BrowserWindow, MessageBoxOptions, Display, app, nativeTheme } from 'electron';
import { screen, BrowserWindow, MessageBoxOptions, Display, app } from 'electron';
import { ILifecycleMainService, UnloadReason, LifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ILogService } from 'vs/platform/log/common/log';
import { IWindowSettings, IPath, isFileToOpen, isWorkspaceToOpen, isFolderToOpen, IWindowOpenable, IOpenEmptyWindowOptions, IAddFoldersRequest, IPathsToWaitFor } from 'vs/platform/windows/common/windows';
import { getLastActiveWindow, findBestWindowOrFolderForFile, findWindowOnWorkspace, findWindowOnExtensionDevelopmentPath, findWindowOnWorkspaceOrFolderUri, INativeWindowConfiguration, OpenContext } from 'vs/platform/windows/node/window';
import { IWindowSettings, IPath, isFileToOpen, isWorkspaceToOpen, isFolderToOpen, IWindowOpenable, IOpenEmptyWindowOptions, IAddFoldersRequest, IPathsToWaitFor, INativeWindowConfiguration } from 'vs/platform/windows/common/windows';
import { getLastActiveWindow, findBestWindowOrFolderForFile, findWindowOnWorkspace, findWindowOnExtensionDevelopmentPath, findWindowOnWorkspaceOrFolderUri, OpenContext } from 'vs/platform/windows/node/window';
import { Emitter } from 'vs/base/common/event';
import product from 'vs/platform/product/common/product';
import { IWindowsMainService, IOpenConfiguration, IWindowsCountChangedEvent, ICodeWindow, IWindowState as ISingleWindowState, WindowMode, IOpenEmptyConfiguration } from 'vs/platform/windows/electron-main/windows';
@@ -64,7 +63,7 @@ type RestoreWindowsSetting = 'all' | 'folders' | 'one' | 'none';
interface IOpenBrowserWindowOptions {
userEnv?: IProcessEnvironment;
cli?: ParsedArgs;
cli?: NativeParsedArgs;
workspace?: IWorkspaceIdentifier;
folderUri?: URI;
@@ -210,17 +209,6 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
private registerListeners(): void {
// React to HC color scheme changes (Windows, macOS)
if (isWindows || isMacintosh) {
nativeTheme.on('updated', () => {
if (nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors) {
this.sendToAll('vscode:enterHighContrast');
} else {
this.sendToAll('vscode:leaveHighContrast');
}
});
}
// When a window looses focus, save all windows state. This allows to
// prevent loss of window-state data when OS is restarted without properly
// shutting down the application (https://github.com/microsoft/vscode/issues/87171)
@@ -899,7 +887,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
return pathsToOpen;
}
private doExtractPathsFromCLI(cli: ParsedArgs): IPath[] {
private doExtractPathsFromCLI(cli: NativeParsedArgs): IPath[] {
const pathsToOpen: IPathToOpen[] = [];
const parseOptions: IPathParseOptions = { ignoreFileNotFound: true, gotoLineMode: cli.goto, remoteAuthority: cli.remote || undefined };
@@ -1370,7 +1358,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
// For all other cases we first call into registerEmptyWindowBackupSync() to set it before
// loading the window.
if (options.emptyWindowBackupInfo) {
configuration.backupPath = join(this.environmentService.backupHome.fsPath, options.emptyWindowBackupInfo.backupFolder);
configuration.backupPath = join(this.environmentService.backupHome, options.emptyWindowBackupInfo.backupFolder);
}
let window: ICodeWindow | undefined;

View File

@@ -3,15 +3,11 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IWindowConfiguration, IPathsToWaitFor } from 'vs/platform/windows/common/windows';
import { URI } from 'vs/base/common/uri';
import * as platform from 'vs/base/common/platform';
import * as extpath from 'vs/base/common/extpath';
import { IWorkspaceIdentifier, IResolvedWorkspace, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { extUriBiasedIgnorePathCase } from 'vs/base/common/resources';
import { LogLevel } from 'vs/platform/log/common/log';
import { ExportData } from 'vs/base/common/performance';
import { ParsedArgs } from 'vs/platform/environment/node/argv';
export const enum OpenContext {
@@ -34,34 +30,6 @@ export const enum OpenContext {
API
}
export interface INativeWindowConfiguration extends IWindowConfiguration, ParsedArgs {
mainPid: number;
windowId: number;
machineId: string;
appRoot: string;
execPath: string;
backupPath?: string;
nodeCachedDataDir?: string;
partsSplashPath: string;
workspace?: IWorkspaceIdentifier;
folderUri?: ISingleFolderWorkspaceIdentifier;
isInitialStartup?: boolean;
logLevel: LogLevel;
zoomLevel?: number;
fullscreen?: boolean;
maximized?: boolean;
accessibilitySupport?: boolean;
perfEntries: ExportData;
userEnv: platform.IProcessEnvironment;
filesToWait?: IPathsToWaitFor;
}
export interface IWindowContext {
openedWorkspace?: IWorkspaceIdentifier;
openedFolderUri?: URI;
@@ -75,7 +43,6 @@ export interface IBestWindowOrFolderOptions<W extends IWindowContext> {
newWindow: boolean;
context: OpenContext;
fileUri?: URI;
userHome?: string;
codeSettingsFolder?: string;
localWorkspaceResolver: (workspace: IWorkspaceIdentifier) => IResolvedWorkspace | null;
}

View File

@@ -17,8 +17,7 @@ import { ThrottledDelayer } from 'vs/base/common/async';
import { isEqual, dirname, originalFSPath, basename, extUriBiasedIgnorePathCase } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { exists } from 'vs/base/node/pfs';
import { ILifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';

View File

@@ -4,8 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { IWorkspaceIdentifier, hasWorkspaceFileExtension, UNTITLED_WORKSPACE_NAME, IResolvedWorkspace, IStoredWorkspaceFolder, isStoredWorkspaceFolder, IWorkspaceFolderCreationData, IUntitledWorkspaceInfo, getStoredWorkspaceFolder, IEnterWorkspaceResult, isUntitledWorkspace } from 'vs/platform/workspaces/common/workspaces';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { join, dirname } from 'vs/base/common/path';
import { mkdirp, writeFile, rimrafSync, readdirSync, writeFileSync } from 'vs/base/node/pfs';
import { readFileSync, existsSync, mkdirSync } from 'fs';

View File

@@ -138,7 +138,7 @@ suite('WorkspacesMainService', () => {
return service.createUntitledWorkspaceSync(folders.map((folder, index) => ({ uri: URI.file(folder), name: names ? names[index] : undefined } as IWorkspaceFolderCreationData)));
}
const environmentService = new TestEnvironmentService(parseArgs(process.argv, OPTIONS), process.execPath);
const environmentService = new TestEnvironmentService(parseArgs(process.argv, OPTIONS));
const logService = new NullLogService();
let service: WorkspacesMainService;