Skip to content

Commit

Permalink
debug: remove package.json massaging (it now lives in node debug)
Browse files Browse the repository at this point in the history
fixes #9061
  • Loading branch information
isidorn committed Sep 22, 2016
1 parent 4eb352c commit b61917b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/debug/common/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export interface IRawEnvAdapter {
export interface IRawAdapter extends IRawEnvAdapter {
enableBreakpointsFor?: { languageIds: string[] };
configurationAttributes?: any;
initialConfigurations?: any[];
initialConfigurations?: any[] | string;
variables: { [key: string]: string };
aiKey?: string;
win?: IRawEnvAdapter;
Expand Down
24 changes: 22 additions & 2 deletions src/vs/workbench/parts/debug/node/debugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
*--------------------------------------------------------------------------------------------*/

import nls = require('vs/nls');
import {TPromise} from 'vs/base/common/winjs.base';
import objects = require('vs/base/common/objects');
import paths = require('vs/base/common/paths');
import platform = require('vs/base/common/platform');
import debug = require('vs/workbench/parts/debug/common/debug');
import {IExtensionDescription} from 'vs/platform/extensions/common/extensions';
import {IConfigurationResolverService} from 'vs/workbench/services/configurationResolver/common/configurationResolver';
import {ICommandService} from 'vs/platform/commands/common/commands';

export class Adapter {

Expand All @@ -20,12 +22,15 @@ export class Adapter {
public type: string;
private _label: string;
private configurationAttributes: any;
public initialConfigurations: any[];
public initialConfigurations: any[] | string;
public variables: { [key: string]: string };
public enableBreakpointsFor: { languageIds: string[] };
public aiKey: string;

constructor(rawAdapter: debug.IRawAdapter, public extensionDescription: IExtensionDescription, configurationResolverService: IConfigurationResolverService) {
constructor(public rawAdapter: debug.IRawAdapter, public extensionDescription: IExtensionDescription,
@IConfigurationResolverService configurationResolverService: IConfigurationResolverService,
@ICommandService private commandService: ICommandService
) {
if (rawAdapter.windows) {
rawAdapter.win = rawAdapter.windows;
}
Expand Down Expand Up @@ -75,10 +80,25 @@ export class Adapter {
this.aiKey = rawAdapter.aiKey;
}

public getInitialConfigurations(): TPromise<string> {
if (typeof this.initialConfigurations === 'string') {
// Contributed initialConfigurations is a command that needs to be invoked
// Debug adapter will dynamically provide the initial conifguraiton
return this.commandService.executeCommand<string>(<string>this.initialConfigurations)
.then(result => JSON.parse(result));
}

return TPromise.as(this.initialConfigurations);
};

public get label() {
return this._label || this.type;
}

public set label(value: string) {
this._label = value;
}

public getSchemaAttributes(): any[] {
// fill in the default configuration attributes shared by all adapters.
if (this.configurationAttributes) {
Expand Down
55 changes: 11 additions & 44 deletions src/vs/workbench/parts/debug/node/debugConfigurationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import path = require('path');
import nls = require('vs/nls');
import {TPromise} from 'vs/base/common/winjs.base';
import strings = require('vs/base/common/strings');
Expand All @@ -22,12 +21,12 @@ import jsonContributionRegistry = require('vs/platform/jsonschemas/common/jsonCo
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {IFileService} from 'vs/platform/files/common/files';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import debug = require('vs/workbench/parts/debug/common/debug');
import {Adapter} from 'vs/workbench/parts/debug/node/debugAdapter';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import {IConfigurationResolverService} from 'vs/workbench/services/configurationResolver/common/configurationResolver';

// debuggers extension point
Expand Down Expand Up @@ -82,7 +81,7 @@ export const debuggersExtPoint = extensionsRegistry.ExtensionsRegistry.registerE
},
initialConfigurations: {
description: nls.localize('vscode.extension.contributes.debuggers.initialConfigurations', "Configurations for generating the initial \'launch.json\'."),
type: 'array',
type: ['array', 'string'],
},
configurationAttributes: {
description: nls.localize('vscode.extension.contributes.debuggers.configurationAttributes', "JSON schema configurations for validating \'launch.json\'."),
Expand Down Expand Up @@ -180,9 +179,9 @@ export class ConfigurationManager implements debug.IConfigurationManager {
@ITelemetryService private telemetryService: ITelemetryService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IConfigurationService private configurationService: IConfigurationService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IConfigurationResolverService private configurationResolverService: IConfigurationResolverService
@IConfigurationResolverService private configurationResolverService: IConfigurationResolverService,
@IInstantiationService private instantiationService: IInstantiationService
) {
this._onDidConfigurationChange = new Emitter<debug.IConfig>();
this.setConfiguration(configName);
Expand All @@ -196,18 +195,18 @@ export class ConfigurationManager implements debug.IConfigurationManager {

extensions.forEach(extension => {
extension.value.forEach(rawAdapter => {
const adapter = new Adapter(rawAdapter, extension.description, this.configurationResolverService);
const adapter = this.instantiationService.createInstance(Adapter, rawAdapter, extension.description);
const duplicate = this.adapters.filter(a => a.type === adapter.type)[0];
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'."));
}

if (duplicate) {
Object.keys(adapter).forEach(attribute => {
if (adapter[attribute]) {
Object.keys(rawAdapter).forEach(attribute => {
if (rawAdapter[attribute]) {
if (attribute === 'enableBreakpointsFor' && duplicate[attribute]) {
Object.keys(adapter.enableBreakpointsFor).forEach(languageId => duplicate.enableBreakpointsFor[languageId] = true);
} else if (duplicate[attribute] && attribute !== 'type' && attribute !== 'extensionDescription') {
} else if (duplicate[attribute] && attribute !== 'type' && attribute !== 'label') {
// give priority to the later registered extension.
duplicate[attribute] = adapter[attribute];
extension.collector.error(nls.localize('duplicateDebuggerType', "Debug type '{0}' is already registered and has attribute '{1}', ignoring attribute '{1}'.", adapter.type, attribute));
Expand Down Expand Up @@ -345,51 +344,19 @@ export class ConfigurationManager implements debug.IConfigurationManager {
return null;
}

return this.massageInitialConfigurations(adapter).then(() => {
return adapter.getInitialConfigurations().then(configurations => {
let editorConfig = this.configurationService.getConfiguration<any>();
return JSON.stringify(
{
version: '0.2.0',
configurations: adapter.initialConfigurations ? adapter.initialConfigurations : []
configurations: configurations || []
},
null,
editorConfig.editor.insertSpaces ? strings.repeat(' ', editorConfig.editor.tabSize) : '\t');
});
});
}

private massageInitialConfigurations(adapter: Adapter): TPromise<void> {
if (!adapter || !adapter.initialConfigurations || adapter.type !== 'node') {
return TPromise.as(undefined);
}

// check package.json for 'main' or 'scripts' so we generate a more pecise 'program' attribute in launch.json.
const packageJsonUri = uri.file(paths.join(this.contextService.getWorkspace().resource.fsPath, '/package.json'));
return this.fileService.resolveContent(packageJsonUri).then(jsonContent => {
try {
const jsonObject = JSON.parse(jsonContent.value);
if (jsonObject.main) {
return jsonObject.main;
} else if (jsonObject.scripts && typeof jsonObject.scripts.start === 'string') {
return (<string>jsonObject.scripts.start).split(' ').pop();
}

} catch (error) { }

return null;
}, err => null).then((program: string) => {
adapter.initialConfigurations.forEach(config => {
if (program && config.program) {
if (!path.isAbsolute(program)) {
program = paths.join('${workspaceRoot}', program);
}

config.program = program;
}
});
});
}

public canSetBreakpointsIn(model: editor.IModel): boolean {
if (model.uri.scheme === Schemas.inMemory) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ suite('Debug - Adapter', () => {
};

setup(() => {
adapter = new Adapter(rawAdapter, { extensionFolderPath, id: 'adapter', name: 'myAdapter', version: '1.0.0', publisher: 'vscode', isBuiltin: false, engines: null }, null);
adapter = new Adapter(rawAdapter, { extensionFolderPath, id: 'adapter', name: 'myAdapter', version: '1.0.0', publisher: 'vscode', isBuiltin: false, engines: null }, null, null);
});

teardown(() => {
Expand Down

0 comments on commit b61917b

Please sign in to comment.