From 507dd3442ad7bf93b32e60a79e7f7d5eb73ddd8d Mon Sep 17 00:00:00 2001 From: Kenneth Marut Date: Fri, 2 Jul 2021 16:54:31 +0200 Subject: [PATCH] Fall back to lastCwd on frontend when getCwdURI fails Signed-off-by: Kenneth Marut --- packages/task/src/browser/task-terminal-widget-manager.ts | 4 ++++ packages/terminal/src/browser/base/terminal-widget.ts | 3 +++ packages/terminal/src/browser/terminal-widget-impl.ts | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/task/src/browser/task-terminal-widget-manager.ts b/packages/task/src/browser/task-terminal-widget-manager.ts index b7439eb3e372e..72d381e49e121 100644 --- a/packages/task/src/browser/task-terminal-widget-manager.ts +++ b/packages/task/src/browser/task-terminal-widget-manager.ts @@ -23,6 +23,7 @@ import { PanelKind, TaskConfiguration, TaskWatcher, TaskExitedEvent, TaskServer, import { ProcessTaskInfo } from '../common/process/task-protocol'; import { TaskDefinitionRegistry } from './task-definition-registry'; import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service'; +import URI from '@theia/core/lib/common/uri'; export interface TaskTerminalWidget extends TerminalWidget { readonly kind: 'task'; @@ -195,10 +196,13 @@ export class TaskTerminalWidgetManager { } // we are unable to find a terminal widget to run the task, or `taskPresentation === 'new'` + const lastCwd = new URI(taskConfig?.options.cwd); if (!reusableTerminalWidget) { const widget = await this.newTaskTerminal(factoryOptions); + widget.lastCwd = lastCwd; return { isNew: true, widget }; } + reusableTerminalWidget.lastCwd = lastCwd; return { isNew: false, widget: reusableTerminalWidget }; } diff --git a/packages/terminal/src/browser/base/terminal-widget.ts b/packages/terminal/src/browser/base/terminal-widget.ts index a0f95911bcc1c..3f4d50bde9e96 100644 --- a/packages/terminal/src/browser/base/terminal-widget.ts +++ b/packages/terminal/src/browser/base/terminal-widget.ts @@ -45,6 +45,9 @@ export abstract class TerminalWidget extends BaseWidget { abstract readonly dimensions: TerminalDimensions; + /** The last CWD assigned to the terminal, useful when attempting getCwdURI on a task terminal fails */ + lastCwd: URI | undefined; + /** * Start terminal and return terminal id. * @param id - terminal id. diff --git a/packages/terminal/src/browser/terminal-widget-impl.ts b/packages/terminal/src/browser/terminal-widget-impl.ts index 00227599b3864..de9e0fbdb04f6 100644 --- a/packages/terminal/src/browser/terminal-widget-impl.ts +++ b/packages/terminal/src/browser/terminal-widget-impl.ts @@ -61,6 +61,7 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget protected hoverMessage: HTMLDivElement; protected lastTouchEnd: TouchEvent | undefined; protected isAttachedCloseListener: boolean = false; + lastCwd: URI; @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService; @inject(WebSocketConnectionProvider) protected readonly webSocketConnectionProvider: WebSocketConnectionProvider; @@ -298,7 +299,10 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget } if (this.terminalService.getById(this.id)) { return this.shellTerminalServer.getCwdURI(this.terminalId) - .then(cwdUrl => new URI(cwdUrl)); + .then(cwdUrl => { + this.lastCwd = new URI(cwdUrl); + return this.lastCwd; + }).catch(() => this.lastCwd); } return Promise.resolve(new URI()); }