Skip to content

Commit

Permalink
Merge pull request microsoft#152202 from microsoft/tyriar/151159
Browse files Browse the repository at this point in the history
Setup local and remote pty host output channels
  • Loading branch information
Tyriar authored Jun 15, 2022
2 parents 14d6d81 + d649a6b commit 6d379ac
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/vs/platform/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export const enum TerminalSettingId {
ShellIntegrationCommandHistory = 'terminal.integrated.shellIntegration.history'
}

export const enum TerminalLogConstants {
FileName = 'ptyhost'
}

export const enum PosixShellType {
PowerShell = 'pwsh',
Bash = 'bash',
Expand Down
22 changes: 17 additions & 5 deletions src/vs/platform/terminal/node/ptyHostMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { join } from 'vs/base/common/path';
import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc';
import { Server } from 'vs/base/parts/ipc/node/ipc.cp';
import { ConsoleLogger, LogService } from 'vs/platform/log/common/log';
import { OPTIONS, parseArgs } from 'vs/platform/environment/node/argv';
import { NativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { ConsoleLogger, getLogLevel, LogService, MultiplexLogService } from 'vs/platform/log/common/log';
import { LogLevelChannel } from 'vs/platform/log/common/logIpc';
import { IReconnectConstants, TerminalIpcChannels } from 'vs/platform/terminal/common/terminal';
import { SpdLogLogger } from 'vs/platform/log/node/spdlogLog';
import product from 'vs/platform/product/common/product';
import { IProductService } from 'vs/platform/product/common/productService';
import { IReconnectConstants, TerminalIpcChannels, TerminalLogConstants } from 'vs/platform/terminal/common/terminal';
import { HeartbeatService } from 'vs/platform/terminal/node/heartbeatService';
import { PtyService } from 'vs/platform/terminal/node/ptyService';

Expand All @@ -16,9 +22,15 @@ const server = new Server('ptyHost');
const lastPtyId = parseInt(process.env.VSCODE_LAST_PTY_ID || '0');
delete process.env.VSCODE_LAST_PTY_ID;

const logService = new LogService(new ConsoleLogger());
const logChannel = new LogLevelChannel(logService);
server.registerChannel(TerminalIpcChannels.Log, logChannel);
// Logging
const productService: IProductService = { _serviceBrand: undefined, ...product };
const environmentService = new NativeEnvironmentService(parseArgs(process.argv, OPTIONS), productService);
const logService = new LogService(new MultiplexLogService([
new ConsoleLogger(),
new SpdLogLogger(TerminalLogConstants.FileName, join(environmentService.logsPath, `${TerminalLogConstants.FileName}.log`), true, false, getLogLevel(environmentService))
]));
const logLevelChannel = new LogLevelChannel(logService);
server.registerChannel(TerminalIpcChannels.Log, logLevelChannel);

const heartbeatService = new HeartbeatService();
server.registerChannel(TerminalIpcChannels.Heartbeat, ProxyChannel.fromService(heartbeatService));
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/terminal/node/ptyHostService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class PtyHostService extends Disposable implements IPtyService {
private _startPtyHost(): [Client, IPtyService] {
const opts: IIPCOptions = {
serverName: 'Pty Host',
args: ['--type=ptyHost'],
args: ['--type=ptyHost', '--logsPath', this._environmentService.logsPath],
env: {
VSCODE_LAST_PTY_ID: lastPtyId,
VSCODE_AMD_ENTRYPOINT: 'vs/platform/terminal/node/ptyHostMain',
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/contrib/remote/common/remote.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { getRemoteName } from 'vs/platform/remote/common/remoteHosts';
import { IDownloadService } from 'vs/platform/download/common/download';
import { DownloadServiceChannel } from 'vs/platform/download/common/downloadIpc';
import { timeout } from 'vs/base/common/async';
import { TerminalLogConstants } from 'vs/platform/terminal/common/terminal';

export class LabelContribution implements IWorkbenchContribution {
constructor(
Expand Down Expand Up @@ -99,6 +100,7 @@ class RemoteLogOutputChannels implements IWorkbenchContribution {
if (remoteEnv) {
const outputChannelRegistry = Registry.as<IOutputChannelRegistry>(OutputExt.OutputChannels);
outputChannelRegistry.registerChannel({ id: 'remoteExtensionLog', label: localize('remoteExtensionLog', "Remote Server"), file: joinPath(remoteEnv.logsPath, `${RemoteExtensionLogFileName}.log`), log: true });
outputChannelRegistry.registerChannel({ id: 'remotePtyHostLog', label: localize('remotePtyHostLog', "Remote Pty Host"), file: joinPath(remoteEnv.logsPath, `${TerminalLogConstants.FileName}.log`), log: true });
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,40 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { URI } from 'vs/base/common/uri';
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { localize } from 'vs/nls';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IFileService } from 'vs/platform/files/common/files';
import { ILabelService } from 'vs/platform/label/common/label';
import { ILogService } from 'vs/platform/log/common/log';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { ITerminalEditorService, ITerminalGroupService, ITerminalService, terminalEditorId } from 'vs/workbench/contrib/terminal/browser/terminal';
import { terminalStrings } from 'vs/workbench/contrib/terminal/common/terminalStrings';
import { IEditorResolverService, RegisteredEditorPriority } from 'vs/workbench/services/editor/common/editorResolverService';
import { registerLogChannel } from 'vs/workbench/services/output/common/output';
import { join } from 'vs/base/common/path';
import { TerminalLogConstants } from 'vs/platform/terminal/common/terminal';

/**
* The main contribution for the terminal contrib. This contains calls to other components necessary
* to set up the terminal but don't need to be tracked in the long term (where TerminalService would
* be more relevant).
*/
export class TerminalMainContribution implements IWorkbenchContribution {
export class TerminalMainContribution extends Disposable implements IWorkbenchContribution {
constructor(
@IEditorResolverService editorResolverService: IEditorResolverService,
@IEnvironmentService environmentService: IEnvironmentService,
@IFileService private readonly _fileService: IFileService,
@ILabelService labelService: ILabelService,
@ILogService private readonly _logService: ILogService,
@ITerminalService terminalService: ITerminalService,
@ITerminalEditorService terminalEditorService: ITerminalEditorService,
@ITerminalGroupService terminalGroupService: ITerminalGroupService
) {
super();

// Register terminal editors
editorResolverService.registerEditor(
`${Schemas.vscodeTerminal}:/**`,
Expand Down Expand Up @@ -66,5 +80,13 @@ export class TerminalMainContribution implements IWorkbenchContribution {
separator: ''
}
});

// Register log channel
this._registerLogChannel('ptyHostLog', localize('ptyHost', "Pty Host"), URI.file(join(environmentService.logsPath, `${TerminalLogConstants.FileName}.log`)));
}

private _registerLogChannel(id: string, label: string, file: URI): void {
const promise = registerLogChannel(id, label, file, this._fileService, this._logService);
this._register(toDisposable(() => promise.cancel()));
}
}

0 comments on commit 6d379ac

Please sign in to comment.