Skip to content

Commit

Permalink
process: display process tasks in the terminal
Browse files Browse the repository at this point in the history
`process` tasks aren't displayed in the terminal, whereas it is
displayed as such in VS Code.

This commit makes it so `process` tasks are displayed the same way
`shell` tasks are.

Signed-off-by: Paul Maréchal <paul.marechal@ericsson.com>
  • Loading branch information
paul-marechal committed Aug 8, 2019
1 parent 66976d0 commit 7a7cb99
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
15 changes: 10 additions & 5 deletions packages/task/src/browser/task-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,13 @@ export class TaskService implements TaskConfigurationClient {

this.logger.debug(`Task created. Task id: ${taskInfo.taskId}`);

// open terminal widget if the task is based on a terminal process (type: shell)
if (taskInfo.terminalId !== undefined) {
/**
* open terminal widget if the task is based on a terminal process (type: 'shell' or 'process')
*
* @todo Use a different mechanism to determine if the task should be attached?
* Reason: Maybe a new task type wants to also be displayed in a terminal.
*/
if (typeof taskInfo.terminalId === 'number') {
this.attach(taskInfo.terminalId, taskInfo.taskId);
}
}
Expand Down Expand Up @@ -436,7 +441,7 @@ export class TaskService implements TaskConfigurationClient {
terminal.sendText(selectedText);
}

async attach(terminalId: number, taskId: number): Promise<void> {
async attach(processId: number, taskId: number): Promise<void> {
// Get the list of all available running tasks.
const runningTasks: TaskInfo[] = await this.getRunningTasks();
// Get the corresponding task information based on task id if available.
Expand All @@ -446,7 +451,7 @@ export class TaskService implements TaskConfigurationClient {
TERMINAL_WIDGET_FACTORY_ID,
<TerminalWidgetFactoryOptions>{
created: new Date().toString(),
id: 'terminal-' + terminalId,
id: 'task-' + processId,
title: taskInfo
? `Task: ${taskInfo.config.label}`
: `Task: #${taskId}`,
Expand All @@ -455,7 +460,7 @@ export class TaskService implements TaskConfigurationClient {
);
this.shell.addWidget(widget, { area: 'bottom' });
this.shell.activateWidget(widget.id);
widget.start(terminalId);
widget.start(processId);
}

async configure(task: TaskConfiguration): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions packages/task/src/node/process/process-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ export class ProcessTask extends Task {
taskId: this.id,
ctx: this.context,
config: this.options.config,
terminalId: (this.processType === 'shell') ? this.process.id : undefined,
processId: this.processType === 'process' ? this.process.id : undefined
terminalId: this.process.id,
processId: this.process.id,
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/task/src/node/task-server.slow-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ describe('Task server / back-end', function (): void {
const p = new Promise((resolve, reject) => {
const toDispose = taskWatcher.onTaskExit((event: TaskExitedEvent) => {
if (event.taskId === taskInfo.taskId && event.code === 0) {
if (taskInfo.terminalId === undefined) {
if (typeof taskInfo.terminalId === 'number') {
resolve();
} else {
reject(new Error(`terminal id was expected to be undefined, actual: ${taskInfo.terminalId}`));
reject(new Error(`terminal id was expected to be a number, got: ${typeof taskInfo.terminalId}`));
}
toDispose.dispose();
}
Expand Down

0 comments on commit 7a7cb99

Please sign in to comment.