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 authored and akosyakov committed Jul 12, 2019
1 parent b2fbe6e commit bd204fe
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 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 @@ -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 {
}
Expand All @@ -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;

Expand Down Expand Up @@ -258,12 +262,23 @@ export class DebugConfigurationManager {
});
}
protected async doCreate(model: DebugConfigurationModel): Promise<URI> {
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;
Expand Down

0 comments on commit bd204fe

Please sign in to comment.