Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support integrated terminal #6508

Merged
merged 1 commit into from
Nov 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions packages/debug/src/browser/debug-session.tsx
Original file line number Diff line number Diff line change
@@ -36,7 +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';
import { TerminalWidgetOptions, TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget';

export enum DebugState {
Inactive,
@@ -368,14 +368,19 @@ export class DebugSession implements CompositeTreeElement {
}

protected async runInTerminal({ arguments: { title, cwd, args, env } }: DebugProtocol.RunInTerminalRequest): Promise<DebugProtocol.RunInTerminalResponse['body']> {
return this.doRunInTerminal({ title, cwd, shellPath: args[0], shellArgs: args.slice(1), env });
const terminal = await this.doCreateTerminal({ title, cwd, env });
terminal.sendText(args.join(' ') + '\n');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akosyakov This part is causing us issues, but it is also a bad thing to do to send un-escaped commands to a shell like this. IIUC, the idea is that we want to reuse a shell widget to display the output. But in this case it seems like we try to reuse actual shell processes, instead of reusing widgets.

Since this is broken for us, I will start trying to look at what is required to reuse shell widgets, do you have any opinions and/or pointers for me?

cc @marcdumais-work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to open an issue, will do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@paul-marechal paul-marechal Dec 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this, but it may indeed be the easiest solution here. Why would we convert a nice array of arguments into one big escaped string though? We can spawn processes directly from a command + arguments. Do debug adapters expect that their clients will provide variable-expansion or other shell-specific behaviors?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking more into it, we do want to use shells. Things like running node without specifying a full path wouldn't work otherwise. Not sure we want to try to always reuse the same shell process though. In VS Code they check before reusing a shell that it doesn't have child processes running, this seems sketchy. I would rather make sure the shell dies when the command is executed, and reuse the widget if process is dead. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't get it. Here is a solution, which we can copy and fix the issue, and then focus on something else instead of spending time reinventing our solution. Plus it makes it easier to catch up later if there are some bug fixes.

Not sure we want to try to always reuse the same shell process though. In VS Code they check before reusing a shell that it doesn't have child processes running, this seems sketchy. I would rather make sure the shell dies when the command is executed, and reuse the widget if process is dead. WDYT?

Sorry, I don't know how it is related to escaping. We start a new terminal each time for now. Please file a new issue if there is a mismatch from user perspective with steps how to reproduce in Theia and VS Code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terminals are reused when handling runInTerminal requests:

theia-vscode-python-ext

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But apparently VS Code has the same issue when running the same command, user can pollute the shell that the extension tries to send commands to... Ok.

return { processId: await terminal.processId };
}

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 };
protected async doCreateTerminal(options: TerminalWidgetOptions): Promise<TerminalWidget> {
let terminal = this.terminalServer.all.find(t => t.title.label === options.title);
if (!terminal) {
terminal = await this.terminalServer.newTerminal(options);
await terminal.start();
}
this.terminalServer.open(terminal);
return terminal;
}

protected clearThreads(): void {
Original file line number Diff line number Diff line change
@@ -27,8 +27,7 @@ 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 { TerminalWidgetOptions, TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget';
import { TerminalOptionsExt } from '../../../common/plugin-api-rpc';

export class PluginDebugSession extends DebugSession {
@@ -46,9 +45,9 @@ export class PluginDebugSession extends DebugSession {
super(id, options, connection, terminalServer, editorManager, breakpoints, labelProvider, messages, fileSystem);
}

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