From 7adbb9a8ebf367fc5a96a4cdce0aea4a6a409675 Mon Sep 17 00:00:00 2001 From: Amiram Wingarten Date: Tue, 9 Jul 2019 23:09:47 +0300 Subject: [PATCH] align first add of launch configuration to preferences fix wrong behavior of creating it always hard coded under .theia folder Signed-off-by: Amiram Wingarten --- .../browser/debug-configuration-manager.ts | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/debug/src/browser/debug-configuration-manager.ts b/packages/debug/src/browser/debug-configuration-manager.ts index 125dd2a1a85b9..bcbaeca4548e6 100644 --- a/packages/debug/src/browser/debug-configuration-manager.ts +++ b/packages/debug/src/browser/debug-configuration-manager.ts @@ -21,12 +21,12 @@ import debounce = require('p-debounce'); import { visit } from 'jsonc-parser'; -import { injectable, inject, postConstruct } from 'inversify'; +import { inject, injectable, postConstruct } from 'inversify'; import URI from '@theia/core/lib/common/uri'; -import { Event, Emitter, WaitUntilEvent } from '@theia/core/lib/common/event'; +import { Emitter, Event, WaitUntilEvent } from '@theia/core/lib/common/event'; import { EditorManager, EditorWidget } from '@theia/editor/lib/browser'; import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor'; -import { StorageService, PreferenceService } from '@theia/core/lib/browser'; +import { PreferenceService, StorageService } from '@theia/core/lib/browser'; import { QuickPickService } from '@theia/core/lib/common/quick-pick-service'; import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service'; import { DebugConfigurationModel } from './debug-configuration-model'; @@ -36,6 +36,7 @@ import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-k import { DebugConfiguration } from '../common/debug-common'; import { WorkspaceVariableContribution } from '@theia/workspace/lib/browser/workspace-variable-contribution'; import { FileSystem, FileSystemError } from '@theia/filesystem/lib/common'; +import { PreferenceConfigurations } from '@theia/core/lib/browser/preferences/preference-configurations'; export interface WillProvideDebugConfiguration extends WaitUntilEvent { } @@ -61,6 +62,9 @@ export class DebugConfigurationManager { @inject(PreferenceService) protected readonly preferences: PreferenceService; + @inject(PreferenceConfigurations) + protected readonly preferenceConfigurations: PreferenceConfigurations; + @inject(WorkspaceVariableContribution) protected readonly workspaceVariables: WorkspaceVariableContribution; @@ -258,12 +262,23 @@ export class DebugConfigurationManager { }); } protected async doCreate(model: DebugConfigurationModel): Promise { - const uri = new URI(model.workspaceFolderUri).resolve('.theia/launch.json'); + await this.preferences.set('launch', {}); // create dummy launch.json in the correct place + const { configUri } = this.preferences.resolve('launch'); // get uri to write content to it + let uri: URI; + if (configUri && configUri.path.base === 'launch.json') { + uri = configUri; + } else { // fallback + uri = new URI(model.workspaceFolderUri).resolve(`${this.preferenceConfigurations.getPaths()[0]}/launch.json`); + } const debugType = await this.selectDebugType(); const configurations = debugType ? await this.provideDebugConfigurations(debugType, model.workspaceFolderUri) : []; const content = this.getInitialConfigurationContent(configurations); + const fileStat = await this.filesystem.getFileStat(uri.toString()); + if (!fileStat) { + throw new Error(`file not found: ${uri.toString()}`); + } try { - await this.filesystem.createFile(uri.toString(), { content }); + await this.filesystem.setContent(fileStat, content); } catch (e) { if (!FileSystemError.FileExists.is(e)) { throw e;