diff --git a/src/vs/workbench/contrib/terminal/browser/terminalService.ts b/src/vs/workbench/contrib/terminal/browser/terminalService.ts index 802883f5f937ae09069e44ab8d1f343f807ec36b..cb0c8c2fca0213559f2ef4c524655e4caa701b9e 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalService.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalService.ts @@ -25,9 +25,6 @@ import { FindReplaceState } from 'vs/editor/contrib/find/findState'; import { escapeNonWindowsPath } from 'vs/workbench/contrib/terminal/common/terminalEnvironment'; import { isWindows, isMacintosh, OperatingSystem } from 'vs/base/common/platform'; import { basename } from 'vs/base/common/path'; -// TODO@daniel code layering -// eslint-disable-next-line code-layering, code-import-patterns -import { INativeOpenFileRequest } from 'vs/platform/windows/node/window'; import { find } from 'vs/base/common/arrays'; import { timeout } from 'vs/base/common/async'; import { IViewsService, ViewContainerLocation, IViewDescriptorService } from 'vs/workbench/common/views'; @@ -109,6 +106,8 @@ export class TerminalService implements ITerminalService { @IConfigurationService private _configurationService: IConfigurationService, @IViewsService private _viewsService: IViewsService, @IViewDescriptorService private readonly _viewDescriptorService: IViewDescriptorService, + // HACK: Ideally TerminalNativeService would depend on TerminalService and inject the + // additional native functionality into it. @optional(ITerminalNativeService) terminalNativeService: ITerminalNativeService ) { // @optional could give undefined and properly typing it breaks service registration @@ -120,7 +119,14 @@ export class TerminalService implements ITerminalService { lifecycleService.onBeforeShutdown(async event => event.veto(this._onBeforeShutdown())); lifecycleService.onShutdown(() => this._onShutdown()); if (this._terminalNativeService) { - this._terminalNativeService.onOpenFileRequest(e => this._onOpenFileRequest(e)); + this._terminalNativeService.onRequestFocusActiveInstance(() => { + if (this.terminalInstances.length > 0) { + const terminal = this.getActiveInstance(); + if (terminal) { + terminal.focus(); + } + } + }); this._terminalNativeService.onOsResume(() => this._onOsResume()); } this._terminalFocusContextKey = KEYBINDING_CONTEXT_TERMINAL_FOCUS.bindTo(this._contextKeyService); @@ -220,22 +226,6 @@ export class TerminalService implements ITerminalService { this.terminalInstances.forEach(instance => instance.dispose(true)); } - private async _onOpenFileRequest(request: INativeOpenFileRequest): Promise { - // if the request to open files is coming in from the integrated terminal (identified though - // the termProgram variable) and we are instructed to wait for editors close, wait for the - // marker file to get deleted and then focus back to the integrated terminal. - if (request.termProgram === 'vscode' && request.filesToWait && this._terminalNativeService) { - const waitMarkerFileUri = URI.revive(request.filesToWait.waitMarkerFileUri); - await this._terminalNativeService.whenFileDeleted(waitMarkerFileUri); - if (this.terminalInstances.length > 0) { - const terminal = this.getActiveInstance(); - if (terminal) { - terminal.focus(); - } - } - } - } - private _onOsResume(): void { const activeTab = this.getActiveTab(); if (!activeTab) { diff --git a/src/vs/workbench/contrib/terminal/common/terminal.ts b/src/vs/workbench/contrib/terminal/common/terminal.ts index 7a7639f627fa60351d621c6cb73632535d1f21f3..e0d0fb53029e40d192325e304b38e4aa1c4aecac 100644 --- a/src/vs/workbench/contrib/terminal/common/terminal.ts +++ b/src/vs/workbench/contrib/terminal/common/terminal.ts @@ -10,7 +10,6 @@ import { RawContextKey } from 'vs/platform/contextkey/common/contextkey'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { URI } from 'vs/base/common/uri'; import { OperatingSystem } from 'vs/base/common/platform'; -import { IOpenFileRequest } from 'vs/platform/windows/common/windows'; import { IEnvironmentVariableInfo } from 'vs/workbench/contrib/terminal/common/environmentVariable'; import { IExtensionPointDescriptor } from 'vs/workbench/services/extensions/common/extensionsRegistry'; @@ -238,7 +237,7 @@ export interface ITerminalNativeService { readonly linuxDistro: LinuxDistro; - readonly onOpenFileRequest: Event; + readonly onRequestFocusActiveInstance: Event; readonly onOsResume: Event; getWindowsBuildNumber(): number; diff --git a/src/vs/workbench/contrib/terminal/electron-browser/terminalNativeService.ts b/src/vs/workbench/contrib/terminal/electron-browser/terminalNativeService.ts index 9ea3808d5ee1f36c4e85c387aa9c34d1033be64d..84030ff44a7ef523c37f24e960bfee1222490006 100644 --- a/src/vs/workbench/contrib/terminal/electron-browser/terminalNativeService.ts +++ b/src/vs/workbench/contrib/terminal/electron-browser/terminalNativeService.ts @@ -17,14 +17,15 @@ import { registerRemoteContributions } from 'vs/workbench/contrib/terminal/elect import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; import { IElectronService } from 'vs/platform/electron/electron-sandbox/electron'; import { Disposable } from 'vs/base/common/lifecycle'; +import { INativeOpenFileRequest } from 'vs/platform/windows/node/window'; export class TerminalNativeService extends Disposable implements ITerminalNativeService { public _serviceBrand: undefined; public get linuxDistro(): LinuxDistro { return linuxDistro; } - private readonly _onOpenFileRequest = this._register(new Emitter()); - public get onOpenFileRequest(): Event { return this._onOpenFileRequest.event; } + private readonly _onRequestFocusActiveInstance = this._register(new Emitter()); + public get onRequestFocusActiveInstance(): Event { return this._onRequestFocusActiveInstance.event; } private readonly _onOsResume = this._register(new Emitter()); public get onOsResume(): Event { return this._onOsResume.event; } @@ -36,7 +37,7 @@ export class TerminalNativeService extends Disposable implements ITerminalNative ) { super(); - ipcRenderer.on('vscode:openFiles', (event: unknown, request: IOpenFileRequest) => this._onOpenFileRequest.fire(request)); + ipcRenderer.on('vscode:openFiles', (event: unknown, request: IOpenFileRequest) => this._onOpenFileRequest(request)); this._register(electronService.onOSResume(() => this._onOsResume.fire())); const connection = remoteAgentService.getConnection(); @@ -45,6 +46,17 @@ export class TerminalNativeService extends Disposable implements ITerminalNative } } + private async _onOpenFileRequest(request: INativeOpenFileRequest): Promise { + // if the request to open files is coming in from the integrated terminal (identified though + // the termProgram variable) and we are instructed to wait for editors close, wait for the + // marker file to get deleted and then focus back to the integrated terminal. + if (request.termProgram === 'vscode' && request.filesToWait) { + const waitMarkerFileUri = URI.revive(request.filesToWait.waitMarkerFileUri); + await this.whenFileDeleted(waitMarkerFileUri); + this._onRequestFocusActiveInstance.fire(); + } + } + public whenFileDeleted(path: URI): Promise { // Complete when wait marker file is deleted return new Promise(resolve => {