Skip to content

Commit

Permalink
align first add of launch configuration to preferences
Browse files Browse the repository at this point in the history
fix wrong behavior of creating it always hard coded under .theia folder

Signed-off-by: Amiram Wingarten <amiram.wingarten@sap.com>
  • Loading branch information
amiramw committed Jul 9, 2019
1 parent b0a2d87 commit 1b379ff
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions packages/debug/src/browser/debug-configuration-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -35,7 +35,6 @@ import { DebugService } from '../common/debug-service';
import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';
import { DebugConfiguration } from '../common/debug-common';
import { WorkspaceVariableContribution } from '@theia/workspace/lib/browser/workspace-variable-contribution';
import { FileSystem, FileSystemError } from '@theia/filesystem/lib/common';

export interface WillProvideDebugConfiguration extends WaitUntilEvent {
}
Expand All @@ -55,9 +54,6 @@ export class DebugConfigurationManager {
@inject(ContextKeyService)
protected readonly contextKeyService: ContextKeyService;

@inject(FileSystem)
protected readonly filesystem: FileSystem;

@inject(PreferenceService)
protected readonly preferences: PreferenceService;

Expand Down Expand Up @@ -258,18 +254,13 @@ export class DebugConfigurationManager {
});
}
protected async doCreate(model: DebugConfigurationModel): Promise<URI> {
const uri = new URI(model.workspaceFolderUri).resolve('.theia/launch.json');
const debugType = await this.selectDebugType();
const configurations = debugType ? await this.provideDebugConfigurations(debugType, model.workspaceFolderUri) : [];
const content = this.getInitialConfigurationContent(configurations);
try {
await this.filesystem.createFile(uri.toString(), { content });
} catch (e) {
if (!FileSystemError.FileExists.is(e)) {
throw e;
}
}
return uri;
await this.preferences.set('launch', content);
const { configUri } = this.preferences.resolve('launch');
// @ts-ignore
return configUri;
}

protected async provideDebugConfigurations(debugType: string, workspaceFolderUri: string | undefined): Promise<DebugConfiguration[]> {
Expand All @@ -280,14 +271,11 @@ export class DebugConfigurationManager {
await WaitUntilEvent.fire(this.onWillProvideDebugConfigurationEmitter, {});
}

protected getInitialConfigurationContent(initialConfigurations: DebugConfiguration[]): string {
return `{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
"version": "0.2.0",
"configurations": ${JSON.stringify(initialConfigurations, undefined, ' ').split('\n').map(line => ' ' + line).join('\n').trim()}
}
`;
protected getInitialConfigurationContent(initialConfigurations: DebugConfiguration[]): {version: string, configurations: DebugConfiguration[]} {
return {
version: '0.2.0',
configurations: initialConfigurations
};
}

protected async selectDebugType(): Promise<string | undefined> {
Expand Down

0 comments on commit 1b379ff

Please sign in to comment.