Skip to content

Commit

Permalink
Proceed runInTermianl request in a sidecar container
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoliy Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Mar 19, 2019
1 parent a7e50c0 commit 8968ac2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
7 changes: 6 additions & 1 deletion packages/debug/src/browser/debug-session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { DebugSessionOptions, InternalDebugSessionOptions } from './debug-sessio
import { DebugConfiguration } from '../common/debug-common';
import { SourceBreakpoint } from './breakpoint/breakpoint-marker';
import { FileSystem } from '@theia/filesystem/lib/common';
import { TerminalWidgetOptions } from '@theia/terminal/lib/browser/base/terminal-widget';

export enum DebugState {
Inactive,
Expand Down Expand Up @@ -367,7 +368,11 @@ export class DebugSession implements CompositeTreeElement {
}

protected async runInTerminal({ arguments: { title, cwd, args, env } }: DebugProtocol.RunInTerminalRequest): Promise<DebugProtocol.RunInTerminalResponse['body']> {
const terminal = await this.terminalServer.newTerminal({ title, cwd, shellPath: args[0], shellArgs: args.slice(1), env });
return this.doRunInTerminal({ title, cwd, shellPath: args[0], shellArgs: args.slice(1), env });
}

protected async doRunInTerminal(options: TerminalWidgetOptions): Promise<DebugProtocol.RunInTerminalResponse['body']> {
const terminal = await this.terminalServer.newTerminal(options);
this.terminalServer.activateTerminal(terminal);
const processId = await terminal.start();
return { processId };
Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-ext/src/api/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,13 @@ export interface PreferenceChangeExt {
preferenceName: string,
newValue: any
}

export interface TerminalOptionsExt {
attributes?: {
[key: string]: string;
}
}

export interface PreferenceRegistryExt {
$acceptConfigurationChanged(data: { [key: string]: any }, eventData: PreferenceChangeExt): void;
}
Expand Down Expand Up @@ -983,6 +990,7 @@ export interface DebugExt {
$getConfigurationSnippets(debugType: string): Promise<IJSONSchemaSnippet[]>;
$createDebugSession(debugConfiguration: theia.DebugConfiguration): Promise<string>;
$terminateDebugSession(sessionId: string): Promise<void>;
$getTerminalCreationOptions(debugType: string): Promise<TerminalOptionsExt | undefined>;
}

export interface DebugMain {
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-ext/src/main/browser/debug/debug-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class DebugMainImpl implements DebugMain {
async $registerDebuggerContribution(description: DebuggerDescription): Promise<void> {
const disposable = new DisposableCollection();
this.toDispose.set(description.type, disposable);
const terminalOptionsExt = await this.debugExt.$getTerminalCreationOptions(description.type);

const debugSessionFactory = new PluginDebugSessionFactory(
this.terminalService,
Expand All @@ -128,7 +129,8 @@ export class DebugMainImpl implements DebugMain {
const connection = await this.connectionMain.ensureConnection(sessionId);
return new PluginWebSocketChannel(connection);
},
this.fileSystem
this.fileSystem,
terminalOptionsExt
);

disposable.pushAll([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ import { DebugSession } from '@theia/debug/lib/browser/debug-session';
import { DebugSessionConnection } from '@theia/debug/lib/browser/debug-session-connection';
import { IWebSocket } from 'vscode-ws-jsonrpc/lib/socket/socket';
import { FileSystem } from '@theia/filesystem/lib/common';
import { DebugProtocol } from 'vscode-debugprotocol';
import { TerminalWidgetOptions } from '@theia/terminal/lib/browser/base/terminal-widget';
import { TerminalOptionsExt } from '../../../api/plugin-api';

export class PluginDebugSession extends DebugSession {
constructor(
readonly id: string,
readonly options: DebugSessionOptions,
protected readonly connection: DebugSessionConnection,
protected readonly terminalServer: TerminalService,
protected readonly editorManager: EditorManager,
protected readonly breakpoints: BreakpointManager,
protected readonly labelProvider: LabelProvider,
protected readonly messages: MessageClient,
protected readonly fileSystem: FileSystem,
protected readonly terminalOptionsExt: TerminalOptionsExt | undefined) {
super(id, options, connection, terminalServer, editorManager, breakpoints, labelProvider, messages, fileSystem);
}

protected async doRunInTerminal(terminalWidgetOptions: TerminalWidgetOptions): Promise<DebugProtocol.RunInTerminalResponse['body']> {
terminalWidgetOptions = Object.assign({}, terminalWidgetOptions, this.terminalOptionsExt);
return super.doRunInTerminal(terminalWidgetOptions);
}
}

/**
* Session factory for a client debug session that communicates with debug adapter contributed as plugin.
Expand All @@ -42,7 +66,8 @@ export class PluginDebugSessionFactory extends DefaultDebugSessionFactory {
protected readonly outputChannelManager: OutputChannelManager,
protected readonly debugPreferences: DebugPreferences,
protected readonly connectionFactory: (sessionId: string) => Promise<IWebSocket>,
protected readonly fileSystem: FileSystem
protected readonly fileSystem: FileSystem,
protected readonly terminalOptionsExt: TerminalOptionsExt | undefined
) {
super();
}
Expand All @@ -53,7 +78,7 @@ export class PluginDebugSessionFactory extends DefaultDebugSessionFactory {
this.connectionFactory,
this.getTraceOutputChannel());

return new DebugSession(
return new PluginDebugSession(
sessionId,
options,
connection,
Expand All @@ -62,6 +87,7 @@ export class PluginDebugSessionFactory extends DefaultDebugSessionFactory {
this.breakpoints,
this.labelProvider,
this.messages,
this.fileSystem);
this.fileSystem,
this.terminalOptionsExt);
}
}
11 changes: 10 additions & 1 deletion packages/plugin-ext/src/plugin/node/debug/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { RPCProtocol } from '../../../api/rpc-protocol';
import {
PLUGIN_RPC_CONTEXT as Ext,
DebugMain,
DebugExt
DebugExt,
TerminalOptionsExt
} from '../../../api/plugin-api';
import * as theia from '@theia/plugin';
import uuid = require('uuid');
Expand Down Expand Up @@ -227,6 +228,14 @@ export class DebugExtImpl implements DebugExt {
return contribution && contribution.configurationSnippets || [];
}

async $getTerminalCreationOptions(debugType: string): Promise<TerminalOptionsExt | undefined> {
return this.doGetTerminalCreationOptions(debugType);
}

async doGetTerminalCreationOptions(debugType: string): Promise<TerminalOptionsExt | undefined> {
return undefined;
}

async $provideDebugConfigurations(debugType: string, workspaceFolderUri: string | undefined): Promise<theia.DebugConfiguration[]> {
let result: theia.DebugConfiguration[] = [];

Expand Down

0 comments on commit 8968ac2

Please sign in to comment.