Skip to content

Commit

Permalink
process/task/terminal: refactor escaping/quoting
Browse files Browse the repository at this point in the history
Add utility functions in `@theia/process/lib/common` to escape common
shells' arguments. Refactored terminal processes to not handle shell
escaping anymore, it is the caller's responsability to provide the
escaped spawn options.

Escaping is now done for DAP's `runInTerminal` requests.

Signed-off-by: Paul Maréchal <paul.marechal@ericsson.com>
  • Loading branch information
paul-marechal committed Dec 18, 2019
1 parent eb74d4a commit b9c544a
Show file tree
Hide file tree
Showing 18 changed files with 1,131 additions and 260 deletions.
3 changes: 2 additions & 1 deletion packages/debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"test": "theiaext test"
},
"devDependencies": {
"@theia/ext-scripts": "^0.13.0"
"@theia/ext-scripts": "^0.13.0",
"colors": "^1.4.0"
},
"nyc": {
"extends": "../../configs/nyc.json"
Expand Down
15 changes: 13 additions & 2 deletions packages/debug/src/browser/debug-session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import { DebugConfiguration } from '../common/debug-common';
import { SourceBreakpoint } from './breakpoint/breakpoint-marker';
import { FileSystem } from '@theia/filesystem/lib/common';
import { TerminalWidgetOptions, TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget';
import { prepareCommandLine, CommandLineOptions } from './run-in-terminal';
import { TerminalProcessInfo } from '@theia/terminal/lib/common/base-terminal-protocol';

export enum DebugState {
Inactive,
Expand Down Expand Up @@ -367,10 +369,19 @@ export class DebugSession implements CompositeTreeElement {
return this.connection.onDidCustomEvent;
}

protected async prepareCommandLine(processInfo: TerminalProcessInfo | undefined, options: CommandLineOptions): Promise<string> {
return prepareCommandLine(processInfo, options);
}

protected async runInTerminal({ arguments: { title, cwd, args, env } }: DebugProtocol.RunInTerminalRequest): Promise<DebugProtocol.RunInTerminalResponse['body']> {
const terminal = await this.doCreateTerminal({ title, cwd, env });
terminal.sendText(args.join(' ') + '\n');
return { processId: await terminal.processId };
// TODO: Getting a property shouldn't map to a promise for an RPC call.
// Either change the way the API works or transform the attribute
// into a function.
// Parallelize promise resolution by requesting both now:
const { processId, processInfo } = terminal;
terminal.sendText(this.prepareCommandLine(await processInfo, { cwd, args, env }) + '\n');
return { processId: await processId };
}

protected async doCreateTerminal(options: TerminalWidgetOptions): Promise<TerminalWidget> {
Expand Down
Loading

0 comments on commit b9c544a

Please sign in to comment.