Merge VS Code 1.23.1 (#1520)

This commit is contained in:
Matt Irvine
2018-06-05 11:24:51 -07:00
committed by GitHub
parent e3baf5c443
commit 0c58f09e59
3651 changed files with 74249 additions and 48599 deletions

View File

@@ -5,11 +5,9 @@
import * as nls from 'vs/nls';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import Event, { Emitter } from 'vs/base/common/event';
import { Event, Emitter } from 'vs/base/common/event';
import { TPromise } from 'vs/base/common/winjs.base';
import * as strings from 'vs/base/common/strings';
import { first } from 'vs/base/common/arrays';
import { isLinux, isMacintosh, isWindows } from 'vs/base/common/platform';
import * as objects from 'vs/base/common/objects';
import uri from 'vs/base/common/uri';
import * as paths from 'vs/base/common/paths';
@@ -27,17 +25,18 @@ import { IFileService } from 'vs/platform/files/common/files';
import { IWorkspaceContextService, IWorkspaceFolder, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IDebugConfigurationProvider, IRawAdapter, ICompound, IDebugConfiguration, IConfig, IEnvConfig, IGlobalConfig, IConfigurationManager, ILaunch, IAdapterExecutable } from 'vs/workbench/parts/debug/common/debug';
import { Adapter } from 'vs/workbench/parts/debug/node/debugAdapter';
import { IDebugConfigurationProvider, IDebuggerContribution, ICompound, IDebugConfiguration, IConfig, IGlobalConfig, IConfigurationManager, ILaunch, IAdapterExecutable, IDebugAdapterProvider, IDebugAdapter, ITerminalSettings, ITerminalLauncher } from 'vs/workbench/parts/debug/common/debug';
import { Debugger } from 'vs/workbench/parts/debug/node/debugger';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
import { isCodeEditor } from 'vs/editor/browser/editorBrowser';
import { launchSchemaId } from 'vs/workbench/services/configuration/common/configuration';
import { IPreferencesService } from 'vs/workbench/parts/preferences/common/preferences';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { TerminalLauncher } from 'vs/workbench/parts/debug/electron-browser/terminalSupport';
// debuggers extension point
export const debuggersExtPoint = extensionsRegistry.ExtensionsRegistry.registerExtensionPoint<IRawAdapter[]>('debuggers', [], {
export const debuggersExtPoint = extensionsRegistry.ExtensionsRegistry.registerExtensionPoint<IDebuggerContribution[]>('debuggers', [], {
description: nls.localize('vscode.extension.contributes.debuggers', 'Contributes debug adapters.'),
type: 'array',
defaultSnippets: [{ body: [{ type: '', extensions: [] }] }],
@@ -216,13 +215,13 @@ const schema: IJSONSchema = {
}
};
const jsonRegistry = <IJSONContributionRegistry>Registry.as(JSONExtensions.JSONContribution);
const jsonRegistry = Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
jsonRegistry.registerSchema(launchSchemaId, schema);
const DEBUG_SELECTED_CONFIG_NAME_KEY = 'debug.selectedconfigname';
const DEBUG_SELECTED_ROOT = 'debug.selectedroot';
export class ConfigurationManager implements IConfigurationManager {
private adapters: Adapter[];
private debuggers: Debugger[];
private breakpointModeIdsSet = new Set<string>();
private launches: ILaunch[];
private selectedName: string;
@@ -230,6 +229,9 @@ export class ConfigurationManager implements IConfigurationManager {
private toDispose: IDisposable[];
private _onDidSelectConfigurationName = new Emitter<void>();
private providers: IDebugConfigurationProvider[];
private debugAdapterProviders: Map<string, IDebugAdapterProvider>;
private terminalLauncher: ITerminalLauncher;
constructor(
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@@ -240,16 +242,20 @@ export class ConfigurationManager implements IConfigurationManager {
@ICommandService private commandService: ICommandService,
@IStorageService private storageService: IStorageService,
@ILifecycleService lifecycleService: ILifecycleService,
@IExtensionService private extensionService: IExtensionService
@IExtensionService private extensionService: IExtensionService,
@IConfigurationResolverService private configurationResolverService: IConfigurationResolverService
) {
this.providers = [];
this.adapters = [];
this.debuggers = [];
this.toDispose = [];
this.registerListeners(lifecycleService);
this.initLaunches();
const previousSelectedRoot = this.storageService.get(DEBUG_SELECTED_ROOT, StorageScope.WORKSPACE);
const filtered = this.launches.filter(l => l.uri.toString() === previousSelectedRoot);
this.selectConfiguration(filtered.length ? filtered[0] : undefined, this.storageService.get(DEBUG_SELECTED_CONFIG_NAME_KEY, StorageScope.WORKSPACE));
const previousSelectedLaunch = this.launches.filter(l => l.uri.toString() === previousSelectedRoot).pop();
if (previousSelectedLaunch) {
this.selectConfiguration(previousSelectedLaunch, this.storageService.get(DEBUG_SELECTED_CONFIG_NAME_KEY, StorageScope.WORKSPACE));
}
this.debugAdapterProviders = new Map<string, IDebugAdapterProvider>();
}
public registerDebugConfigurationProvider(handle: number, debugConfigurationProvider: IDebugConfigurationProvider): void {
@@ -260,10 +266,10 @@ export class ConfigurationManager implements IConfigurationManager {
debugConfigurationProvider.handle = handle;
this.providers = this.providers.filter(p => p.handle !== handle);
this.providers.push(debugConfigurationProvider);
const adapter = this.getAdapter(debugConfigurationProvider.type);
const dbg = this.getDebugger(debugConfigurationProvider.type);
// Check if the provider contributes provideDebugConfigurations method
if (adapter && debugConfigurationProvider.provideDebugConfigurations) {
adapter.hasConfigurationProvider = true;
if (dbg && debugConfigurationProvider.provideDebugConfigurations) {
dbg.hasConfigurationProvider = true;
}
}
@@ -272,19 +278,21 @@ export class ConfigurationManager implements IConfigurationManager {
}
public resolveConfigurationByProviders(folderUri: uri | undefined, type: string | undefined, debugConfiguration: IConfig): TPromise<IConfig> {
// pipe the config through the promises sequentially. append at the end the '*' types
const providers = this.providers.filter(p => p.type === type && p.resolveDebugConfiguration)
.concat(this.providers.filter(p => p.type === '*' && p.resolveDebugConfiguration));
return this.extensionService.activateByEvent(`onDebugResolve:${type}`).then(() => {
// pipe the config through the promises sequentially. append at the end the '*' types
const providers = this.providers.filter(p => p.type === type && p.resolveDebugConfiguration)
.concat(this.providers.filter(p => p.type === '*' && p.resolveDebugConfiguration));
return providers.reduce((promise, provider) => {
return promise.then(config => {
if (config) {
return provider.resolveDebugConfiguration(folderUri, config);
} else {
return Promise.resolve(config);
}
});
}, TPromise.as(debugConfiguration));
return providers.reduce((promise, provider) => {
return promise.then(config => {
if (config) {
return provider.resolveDebugConfiguration(folderUri, config);
} else {
return Promise.resolve(config);
}
});
}, TPromise.as(debugConfiguration));
});
}
public provideDebugConfigurations(folderUri: uri | undefined, type: string): TPromise<any[]> {
@@ -300,12 +308,53 @@ export class ConfigurationManager implements IConfigurationManager {
return TPromise.as(undefined);
}
public registerDebugAdapterProvider(debugTypes: string[], debugAdapterLauncher: IDebugAdapterProvider): IDisposable {
debugTypes.forEach(debugType => this.debugAdapterProviders.set(debugType, debugAdapterLauncher));
return {
dispose: () => {
debugTypes.forEach(debugType => this.debugAdapterProviders.delete(debugType));
}
};
}
private getDebugAdapterProvider(type: string): IDebugAdapterProvider | undefined {
return this.debugAdapterProviders.get(type);
}
public createDebugAdapter(debugType: string, adapterExecutable: IAdapterExecutable): IDebugAdapter | undefined {
let dap = this.getDebugAdapterProvider(debugType);
if (dap) {
return dap.createDebugAdapter(debugType, adapterExecutable);
}
return undefined;
}
public substituteVariables(debugType: string, folder: IWorkspaceFolder, config: IConfig): TPromise<IConfig> {
let dap = this.getDebugAdapterProvider(debugType);
if (dap) {
return dap.substituteVariables(folder, config);
}
return TPromise.as(config);
}
public runInTerminal(debugType: string, args: DebugProtocol.RunInTerminalRequestArguments, config: ITerminalSettings): TPromise<void> {
let tl: ITerminalLauncher = this.getDebugAdapterProvider(debugType);
if (!tl) {
if (!this.terminalLauncher) {
this.terminalLauncher = this.instantiationService.createInstance(TerminalLauncher);
}
tl = this.terminalLauncher;
}
return tl.runInTerminal(args, config);
}
private registerListeners(lifecycleService: ILifecycleService): void {
debuggersExtPoint.setHandler((extensions) => {
extensions.forEach(extension => {
extension.value.forEach(rawAdapter => {
if (!rawAdapter.type || (typeof rawAdapter.type !== 'string')) {
extension.collector.error(nls.localize('debugNoType', "Debug adapter 'type' can not be omitted and must be of type 'string'."));
extension.collector.error(nls.localize('debugNoType', "Debugger 'type' can not be omitted and must be of type 'string'."));
}
if (rawAdapter.enableBreakpointsFor) {
rawAdapter.enableBreakpointsFor.languageIds.forEach(modeId => {
@@ -313,17 +362,17 @@ export class ConfigurationManager implements IConfigurationManager {
});
}
const duplicate = this.adapters.filter(a => a.type === rawAdapter.type).pop();
const duplicate = this.getDebugger(rawAdapter.type);
if (duplicate) {
duplicate.merge(rawAdapter, extension.description);
} else {
this.adapters.push(new Adapter(this, rawAdapter, extension.description, this.configurationService, this.commandService));
this.debuggers.push(new Debugger(this, rawAdapter, extension.description, this.configurationService, this.commandService, this.configurationResolverService));
}
});
});
// update the schema to include all attributes, snippets and types from extensions.
this.adapters.forEach(adapter => {
this.debuggers.forEach(adapter => {
const items = (<IJSONSchema>schema.properties['configurations'].items);
const schemaAttributes = adapter.getSchemaAttributes();
if (schemaAttributes) {
@@ -348,12 +397,12 @@ export class ConfigurationManager implements IConfigurationManager {
this.toDispose.push(this.contextService.onDidChangeWorkspaceFolders(() => {
this.initLaunches();
this.selectConfiguration();
this.selectConfiguration(this.selectedLaunch);
this.setCompoundSchemaValues();
}));
this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('launch')) {
this.selectConfiguration();
this.selectConfiguration(this.selectedLaunch);
this.setCompoundSchemaValues();
}
}));
@@ -417,14 +466,10 @@ export class ConfigurationManager implements IConfigurationManager {
return undefined;
}
public selectConfiguration(launch?: ILaunch, name?: string, debugStarted?: boolean): void {
public selectConfiguration(launch: ILaunch, name?: string): void {
const previousLaunch = this.selectedLaunch;
const previousName = this.selectedName;
if (!launch) {
launch = this.selectedLaunch && this.selectedLaunch.getConfigurationNames().length ? this.selectedLaunch : first(this.launches, l => !!l.getConfigurationNames().length, this.launches.length ? this.launches[0] : undefined);
}
this.selectedLaunch = launch;
const names = launch ? launch.getConfigurationNames() : [];
if (name && names.indexOf(name) >= 0) {
@@ -452,25 +497,26 @@ export class ConfigurationManager implements IConfigurationManager {
return this.breakpointModeIdsSet.has(modeId);
}
public getAdapter(type: string): Adapter {
return this.adapters.filter(adapter => strings.equalsIgnoreCase(adapter.type, type)).pop();
public getDebugger(type: string): Debugger {
return this.debuggers.filter(dbg => strings.equalsIgnoreCase(dbg.type, type)).pop();
}
public guessAdapter(type?: string): TPromise<Adapter> {
return this.extensionService.activateByEvent('onDebugInitialConfigurations').then(() => this.extensionService.activateByEvent('onDebug').then(() => {
public guessDebugger(type?: string): TPromise<Debugger> {
return this.activateDebuggers().then(() => {
if (type) {
const adapter = this.getAdapter(type);
const adapter = this.getDebugger(type);
return TPromise.as(adapter);
}
const editor = this.editorService.getActiveEditor();
let candidates: Adapter[];
let candidates: Debugger[];
if (editor) {
const codeEditor = editor.getControl();
if (isCodeEditor(codeEditor)) {
const model = codeEditor.getModel();
const language = model ? model.getLanguageIdentifier().language : undefined;
const adapters = this.adapters.filter(a => a.languages && a.languages.indexOf(language) >= 0);
const adapters = this.debuggers.filter(a => a.languages && a.languages.indexOf(language) >= 0);
if (adapters.length === 1) {
return TPromise.as(adapters[0]);
}
@@ -481,11 +527,11 @@ export class ConfigurationManager implements IConfigurationManager {
}
if (!candidates) {
candidates = this.adapters.filter(a => a.hasInitialConfiguration() || a.hasConfigurationProvider);
candidates = this.debuggers.filter(a => a.hasInitialConfiguration() || a.hasConfigurationProvider);
}
return this.quickOpenService.pick([...candidates, { label: 'More...', separator: { border: true } }], { placeHolder: nls.localize('selectDebug', "Select Environment") })
.then(picked => {
if (picked instanceof Adapter) {
if (picked instanceof Debugger) {
return picked;
}
if (picked) {
@@ -493,7 +539,11 @@ export class ConfigurationManager implements IConfigurationManager {
}
return undefined;
});
}));
});
}
public activateDebuggers(): TPromise<void> {
return this.extensionService.activateByEvent('onDebugInitialConfigurations').then(() => this.extensionService.activateByEvent('onDebug'));
}
private store(): void {
@@ -516,8 +566,7 @@ class Launch implements ILaunch {
@IFileService private fileService: IFileService,
@IWorkbenchEditorService protected editorService: IWorkbenchEditorService,
@IConfigurationService protected configurationService: IConfigurationService,
@IConfigurationResolverService private configurationResolverService: IConfigurationResolverService,
@IWorkspaceContextService protected contextService: IWorkspaceContextService
@IWorkspaceContextService protected contextService: IWorkspaceContextService,
) {
// noop
}
@@ -574,93 +623,60 @@ class Launch implements ILaunch {
return config.configurations.filter(config => config && config.name === name).shift();
}
protected getWorkspaceForResolving(): IWorkspaceFolder {
if (this.workspace) {
return this.workspace;
}
if (this.contextService.getWorkspace().folders.length === 1) {
return this.contextService.getWorkspace().folders[0];
}
return undefined;
}
public resolveConfiguration(config: IConfig): TPromise<IConfig> {
const result = objects.deepClone(config) as IConfig;
// Set operating system specific properties #1873
const setOSProperties = (flag: boolean, osConfig: IEnvConfig) => {
if (flag && osConfig) {
Object.keys(osConfig).forEach(key => {
result[key] = osConfig[key];
});
}
};
setOSProperties(isWindows, result.windows);
setOSProperties(isMacintosh, result.osx);
setOSProperties(isLinux, result.linux);
// massage configuration attributes - append workspace path to relatvie paths, substitute variables in paths.
Object.keys(result).forEach(key => {
result[key] = this.configurationResolverService.resolveAny(this.getWorkspaceForResolving(), result[key]);
});
const adapter = this.configurationManager.getAdapter(result.type);
return this.configurationResolverService.resolveInteractiveVariables(result, adapter ? adapter.variables : null);
}
public openConfigFile(sideBySide: boolean, type?: string): TPromise<IEditor> {
const resource = this.uri;
let pinned = false;
return this.configurationManager.activateDebuggers().then(() => {
const resource = this.uri;
let pinned = false;
return this.fileService.resolveContent(resource).then(content => content.value, err => {
return this.fileService.resolveContent(resource).then(content => content.value, err => {
// launch.json not found: create one by collecting launch configs from debugConfigProviders
// launch.json not found: create one by collecting launch configs from debugConfigProviders
return this.configurationManager.guessAdapter(type).then(adapter => {
if (adapter) {
return this.configurationManager.provideDebugConfigurations(this.workspace.uri, adapter.type).then(initialConfigs => {
return adapter.getInitialConfigurationContent(initialConfigs);
return this.configurationManager.guessDebugger(type).then(adapter => {
if (adapter) {
return this.configurationManager.provideDebugConfigurations(this.workspace.uri, adapter.type).then(initialConfigs => {
return adapter.getInitialConfigurationContent(initialConfigs);
});
} else {
return undefined;
}
}).then(content => {
if (!content) {
return undefined;
}
pinned = true; // pin only if config file is created #8727
return this.fileService.updateContent(resource, content).then(() => {
// convert string into IContent; see #32135
return content;
});
} else {
return undefined;
}
});
}).then(content => {
if (!content) {
return undefined;
}
pinned = true; // pin only if config file is created #8727
return this.fileService.updateContent(resource, content).then(() => {
// convert string into IContent; see #32135
return content;
});
});
}).then(content => {
if (!content) {
return undefined;
}
const index = content.indexOf(`"${this.configurationManager.selectedConfiguration.name}"`);
let startLineNumber = 1;
for (let i = 0; i < index; i++) {
if (content.charAt(i) === '\n') {
startLineNumber++;
const index = content.indexOf(`"${this.configurationManager.selectedConfiguration.name}"`);
let startLineNumber = 1;
for (let i = 0; i < index; i++) {
if (content.charAt(i) === '\n') {
startLineNumber++;
}
}
}
const selection = startLineNumber > 1 ? { startLineNumber, startColumn: 4 } : undefined;
const selection = startLineNumber > 1 ? { startLineNumber, startColumn: 4 } : undefined;
return this.editorService.openEditor({
resource: resource,
options: {
forceOpen: true,
selection,
pinned,
revealIfVisible: true
},
}, sideBySide);
}, (error) => {
throw new Error(nls.localize('DebugConfig.failed', "Unable to create 'launch.json' file inside the '.vscode' folder ({0}).", error));
return this.editorService.openEditor({
resource: resource,
options: {
forceOpen: true,
selection,
pinned,
revealIfVisible: true
},
}, sideBySide);
}, (error) => {
throw new Error(nls.localize('DebugConfig.failed', "Unable to create 'launch.json' file inside the '.vscode' folder ({0}).", error));
});
});
}
}
@@ -673,9 +689,9 @@ class WorkspaceLaunch extends Launch implements ILaunch {
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IConfigurationService configurationService: IConfigurationService,
@IConfigurationResolverService configurationResolverService: IConfigurationResolverService,
@IWorkspaceContextService contextService: IWorkspaceContextService
@IWorkspaceContextService contextService: IWorkspaceContextService,
) {
super(configurationManager, undefined, fileService, editorService, configurationService, configurationResolverService, contextService);
super(configurationManager, undefined, fileService, editorService, configurationService, contextService);
}
get uri(): uri {
@@ -706,7 +722,7 @@ class UserLaunch extends Launch implements ILaunch {
@IPreferencesService private preferencesService: IPreferencesService,
@IWorkspaceContextService contextService: IWorkspaceContextService
) {
super(configurationManager, undefined, fileService, editorService, configurationService, configurationResolverService, contextService);
super(configurationManager, undefined, fileService, editorService, configurationService, contextService);
}
get uri(): uri {