Skip to content

Commit

Permalink
Fix eclipse-theia#2961: Output of short-lived tasks is not shown
Browse files Browse the repository at this point in the history
Signed-off-by: Esther Perelman <[email protected]>
  • Loading branch information
EstherPerelman committed Apr 22, 2021
1 parent df062f6 commit a02ae49
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
3 changes: 1 addition & 2 deletions packages/process/src/node/process-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export class ProcessManager implements BackendApplicationContribution {
register(process: Process): number {
const id = this.id;
this.processes.set(id, process);
process.onExit(() => this.unregister(process));
process.onError(() => this.unregister(process));
this.id++;
return id;
Expand All @@ -54,7 +53,7 @@ export class ProcessManager implements BackendApplicationContribution {
*
* @param process the process to unregister from this process manager.
*/
protected unregister(process: Process): void {
public unregister(process: Process): void {
const processLabel = this.getProcessLabel(process);
this.logger.debug(`Unregistering process. ${processLabel}`);
if (!process.killed) {
Expand Down
7 changes: 6 additions & 1 deletion packages/process/src/node/terminal-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ export class TerminalProcess extends Process {
// signal parameter will hold the signal number and code should
// be ignored.
if (signal === undefined || signal === 0) {
this.emitOnExit(code, undefined);
this.emitOnExit(code, undefined); // check if long task skip this
} else {
this.emitOnExit(undefined, signame(signal));
this.unregisterProcess();
}
process.nextTick(() => {
if (signal === undefined || signal === 0) {
Expand Down Expand Up @@ -168,6 +169,10 @@ export class TerminalProcess extends Process {
}
}

unregisterProcess(): void {
this.processManager.unregister(this);
}

resize(cols: number, rows: number): void {
this.checkTerminal();
this.terminal!.resize(cols, rows);
Expand Down
4 changes: 4 additions & 0 deletions packages/terminal/src/browser/terminal-widget-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
protected async attachTerminal(id: number): Promise<number> {
const terminalId = await this.shellTerminalServer.attach(id);
if (IBaseTerminalServer.validateId(terminalId)) {
const isProcessKilled = await this.shellTerminalServer.isProcessKilled(this.terminalId);
if (isProcessKilled) {
this.shellTerminalServer.unregisterProcess(this.terminalId);
}
return terminalId;
}
this.logger.warn(`Failed attaching to terminal id ${id}, the terminal is most likely gone. Starting up a new terminal instead.`);
Expand Down
4 changes: 3 additions & 1 deletion packages/terminal/src/common/base-terminal-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ export interface IBaseTerminalServer extends JsonRpcServer<IBaseTerminalClient>
getProcessId(id: number): Promise<number>;
getProcessInfo(id: number): Promise<TerminalProcessInfo>;
getCwdURI(id: number): Promise<string>;
isProcessKilled(id: number): Promise<boolean>
resize(id: number, cols: number, rows: number): Promise<void>;
attach(id: number): Promise<number>;
close(id: number): Promise<void>;
unregisterProcess(id: number): Promise<void>;
getDefaultShell(): Promise<string>;

/**
Expand Down Expand Up @@ -171,7 +173,7 @@ export interface MergedEnvironmentVariableCollection {
/**
* Applies this collection to a process environment.
*/
applyToProcessEnvironment(env: { [key: string]: string | null } ): void;
applyToProcessEnvironment(env: { [key: string]: string | null }): void;
}

export interface SerializableExtensionEnvironmentVariableCollection {
Expand Down
16 changes: 16 additions & 0 deletions packages/terminal/src/node/base-terminal-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ export abstract class BaseTerminalServer implements IBaseTerminalServer {
};
}

async isProcessKilled(id: number): Promise<boolean> {
const terminal = this.processManager.get(id);
if (terminal instanceof TerminalProcess) {
return terminal.killed;
}
return false;
}

async getCwdURI(id: number): Promise<string> {
const terminal = this.processManager.get(id);
if (!(terminal instanceof TerminalProcess)) {
Expand All @@ -103,6 +111,14 @@ export abstract class BaseTerminalServer implements IBaseTerminalServer {
}
}

async unregisterProcess(id: number): Promise<void> {
const term = this.processManager.get(id);

if (term instanceof TerminalProcess) {
term.unregisterProcess();
}
}

async getDefaultShell(): Promise<string> {
return ShellProcess.getShellExecutablePath();
}
Expand Down

0 comments on commit a02ae49

Please sign in to comment.