From 0e470e093db54132463f250c9eb6918f28d7b631 Mon Sep 17 00:00:00 2001 From: isidor Date: Tue, 11 Oct 2016 17:59:46 +0200 Subject: [PATCH] debug: allow adapters to provide full launch.json content --- .../parts/debug/node/debugAdapter.ts | 27 ++++++++++--- .../debug/node/debugConfigurationManager.ts | 38 +++++-------------- .../debug/test/node/debugAdapter.test.ts | 2 +- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/vs/workbench/parts/debug/node/debugAdapter.ts b/src/vs/workbench/parts/debug/node/debugAdapter.ts index 0e73607a82a..041d5605317 100644 --- a/src/vs/workbench/parts/debug/node/debugAdapter.ts +++ b/src/vs/workbench/parts/debug/node/debugAdapter.ts @@ -5,12 +5,14 @@ import nls = require('vs/nls'); import { TPromise } from 'vs/base/common/winjs.base'; +import strings = require('vs/base/common/strings'); 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 { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { ICommandService } from 'vs/platform/commands/common/commands'; export class Adapter { @@ -29,6 +31,7 @@ export class Adapter { constructor(public rawAdapter: debug.IRawAdapter, public extensionDescription: IExtensionDescription, @IConfigurationResolverService configurationResolverService: IConfigurationResolverService, + @IConfigurationService private configurationService: IConfigurationService, @ICommandService private commandService: ICommandService ) { if (rawAdapter.windows) { @@ -80,15 +83,29 @@ export class Adapter { this.aiKey = rawAdapter.aiKey; } - public getInitialConfigurations(): TPromise { + public getInitialConfigFileContent(): TPromise { + const editorConfig = this.configurationService.getConfiguration(); 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(this.initialConfigurations) - .then(result => JSON.parse(result)); + // Debug adapter will dynamically provide the full launch.json + return this.commandService.executeCommand(this.initialConfigurations).then(content => { + // Debug adapter returned the full content of the launch.json - return it after format + if (editorConfig.editor.insertSpaces) { + content = content.replace(new RegExp('\t', 'g'), strings.repeat(' ', editorConfig.editor.tabSize)); + } + + return content; + }); } - return TPromise.as(this.initialConfigurations); + return TPromise.as(JSON.stringify( + { + version: '0.2.0', + configurations: this.initialConfigurations || [] + }, + null, + editorConfig.editor.insertSpaces ? strings.repeat(' ', editorConfig.editor.tabSize) : '\t' + )); }; public get label() { diff --git a/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts b/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts index c5215fee2b9..5ed72479188 100644 --- a/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts +++ b/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts @@ -311,15 +311,17 @@ export class ConfigurationManager implements debug.IConfigurationManager { let configFileCreated = false; return this.fileService.resolveContent(resource).then(content => true, err => - this.getInitialConfigFileContent().then(content => { - if (!content) { - return false; - } + this.quickOpenService.pick(this.adapters, { placeHolder: nls.localize('selectDebug', "Select Environment") }) + .then(adapter => adapter ? adapter.getInitialConfigFileContent() : null) + .then(content => { + if (!content) { + return false; + } - configFileCreated = true; - return this.fileService.updateContent(resource, content).then(() => true); - } - )).then(errorFree => { + configFileCreated = true; + return this.fileService.updateContent(resource, content).then(() => true); + })) + .then(errorFree => { if (!errorFree) { return false; } @@ -337,26 +339,6 @@ export class ConfigurationManager implements debug.IConfigurationManager { }); } - private getInitialConfigFileContent(): TPromise { - return this.quickOpenService.pick(this.adapters, { placeHolder: nls.localize('selectDebug', "Select Environment") }) - .then(adapter => { - if (!adapter) { - return null; - } - - return adapter.getInitialConfigurations().then(configurations => { - let editorConfig = this.configurationService.getConfiguration(); - return JSON.stringify( - { - version: '0.2.0', - configurations: configurations || [] - }, - null, - editorConfig.editor.insertSpaces ? strings.repeat(' ', editorConfig.editor.tabSize) : '\t'); - }); - }); - } - public canSetBreakpointsIn(model: editor.IModel): boolean { if (model.uri.scheme === Schemas.inMemory) { return false; diff --git a/src/vs/workbench/parts/debug/test/node/debugAdapter.test.ts b/src/vs/workbench/parts/debug/test/node/debugAdapter.test.ts index d4e4adfd090..426a1052499 100644 --- a/src/vs/workbench/parts/debug/test/node/debugAdapter.test.ts +++ b/src/vs/workbench/parts/debug/test/node/debugAdapter.test.ts @@ -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, null); + adapter = new Adapter(rawAdapter, { extensionFolderPath, id: 'adapter', name: 'myAdapter', version: '1.0.0', publisher: 'vscode', isBuiltin: false, engines: null }, null, null, null); }); teardown(() => { -- GitLab