Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rawLog option for OutputChannel to colourise the Ark log #1589

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extensions/jupyter-adapter/src/JupyterKernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export class JupyterKernel extends EventEmitter implements vscode.Disposable {
// Establish a log channel for the kernel we're connecting to, if we
// don't already have one (we will if we're restarting)
if (!this._logChannel) {
this._logChannel = vscode.window.createOutputChannel(`Runtime: ${this._spec.display_name}`);
this._logChannel = positron.window.createRawLogOutputChannel(`Runtime: ${this._spec.display_name}`);
}

// Bind to the Jupyter session
Expand Down
14 changes: 14 additions & 0 deletions src/positron-dts/positron.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,20 @@ declare module 'positron' {
* @return New preview panel.
*/
export function createPreviewPanel(viewType: string, title: string, preserveFocus?: boolean, options?: PreviewOptions): PreviewPanel;

/**
* Create a log output channel from raw data.
*
* Variant of `createOutputChannel()` that creates a "raw log" output channel.
* Compared to a normal `LogOutputChannel`, this doesn't add timestamps or info
* level. It's meant for extensions that create fully formed log lines but still
* want to benefit from the colourised rendering of log output channels.
*
* @param name Human-readable string which will be used to represent the channel in the UI.
*
* @return New log output channel.
*/
export function createRawLogOutputChannel(name: string): vscode.OutputChannel;
}

namespace runtime {
Expand Down
9 changes: 9 additions & 0 deletions src/vs/platform/log/node/spdlogLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ export class SpdLogLogger extends AbstractMessageLogger implements ILogger {
}
}

// --- Start Positron ---
// Override pattern to avoid adding timestamps etc
public setRawLogger() {
this._loggerCreationPromise.then(() => {
this._logger!.setPattern('%v');
});
}
// --- End Positron ---

protected log(level: LogLevel, message: string): void {
if (this._logger) {
log(this._logger, level, message);
Expand Down
34 changes: 34 additions & 0 deletions src/vs/workbench/api/common/extHostOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ class ExtHostOutputChannel extends AbstractMessageLogger implements vscode.LogOu
this._register(logger.onDidChangeLogLevel(level => this.setLevel(level)));
}

// --- Start Positron ---
public setRawLogger() {
let loggerUnchecked = this.logger as any;
if (loggerUnchecked.setRawLogger) {
loggerUnchecked.setRawLogger();
};
}
// --- End Positron ---

get logLevel(): LogLevel {
return this.getLevel();
}
Expand Down Expand Up @@ -161,6 +170,24 @@ export class ExtHostOutputService implements ExtHostOutputServiceShape {
return log ? this.createExtHostLogOutputChannel(name, logLevel ?? this.logService.getLevel(), <Promise<ExtHostOutputChannel>>extHostOutputChannel) : this.createExtHostOutputChannel(name, <Promise<ExtHostOutputChannel>>extHostOutputChannel);
}

// --- Start Positron ---
// Variant of createOutputChannel() that creates a "raw log" output channel.
// Compared to a normal `LogOutputChannel`, this doesn't add timestamps or info
// level. It's meant for extensions that create fully formed log lines but still
// want to benefit from the colourised rendering of log output channels.
createRawLogOutputChannel(name: string, extension: IExtensionDescription): vscode.OutputChannel {
const channel = this.createOutputChannel(name, { log: true }, extension);

// Set our custom raw log
const channelUnchecked = channel as any
if (channelUnchecked.setRawLogger) {
channelUnchecked.setRawLogger();
}

return channel;
}
// --- End Positron ---

private async doCreateOutputChannel(name: string, languageId: string | undefined, extension: IExtensionDescription): Promise<ExtHostOutputChannel> {
if (!this.outputDirectoryPromise) {
this.outputDirectoryPromise = this.extHostFileSystem.value.createDirectory(this.outputsLocation).then(() => this.outputsLocation);
Expand Down Expand Up @@ -216,6 +243,13 @@ export class ExtHostOutputService implements ExtHostOutputServiceShape {
validate();
channelPromise.then(channel => channel.appendLine(value));
},
// --- Start Positron ---
// @ts-ignore
setRawLogger(): void {
validate();
channelPromise.then(channel => channel.setRawLogger());
},
// --- End Positron ---
clear(): void {
validate();
channelPromise.then(channel => channel.clear());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ExtHostContext } from 'vs/workbench/api/common/extHost.protocol';
import { IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';
import { ExtHostWebviews } from 'vs/workbench/api/common/extHostWebview';
import { ExtHostLanguageFeatures } from 'vs/workbench/api/common/extHostLanguageFeatures';
import { ExtHostOutputService } from 'vs/workbench/api/common/extHostOutput';

/**
* Factory interface for creating an instance of the Positron API.
Expand Down Expand Up @@ -45,10 +46,7 @@ export function createPositronApiFactoryAndRegisterActors(accessor: ServicesAcce
// VS Code API can share a single instance of `ExtHostWebViews`, which is
// necessary since the instance effectively needs to be a singleton.
const extHostWebviews: ExtHostWebviews = rpcProtocol.getRaw(ExtHostContext.ExtHostWebviews);
if (!extHostWebviews) {
throw new Error('Could not retrieve ExtHostWebviews from the RPC protocol. ' +
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since getRaw() already throws, I've removed this error and merged the extra message info in the upstream error. This way we don't have too much redundant error handling in all the getRaw() calls.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's nicer, thanks!

' The VS Code API must be created before the Positron API.');
}
const extHostOutputService: ExtHostOutputService = rpcProtocol.getRaw(ExtHostContext.ExtHostOutputService);

// Same deal for the `ExtHostLanguageFeatures` object
const extHostLanguageFeatures: ExtHostLanguageFeatures =
Expand Down Expand Up @@ -87,6 +85,9 @@ export function createPositronApiFactoryAndRegisterActors(accessor: ServicesAcce
const window: typeof positron.window = {
createPreviewPanel(viewType: string, title: string, preserveFocus?: boolean, options?: vscode.WebviewPanelOptions & vscode.WebviewOptions) {
return extHostPreviewPanels.createPreviewPanel(extension, viewType, title, preserveFocus, options);
},
createRawLogOutputChannel(name: string): vscode.OutputChannel {
return extHostOutputService.createRawLogOutputChannel(name, extension);
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/services/extensions/common/rpcProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ export class RPCProtocol extends Disposable implements IRPCProtocol {
*/
public getRaw<T, R extends T>(identifier: ProxyIdentifier<T>): R {
if (!this._locals[identifier.nid]) {
throw new Error(`Missing actor ${identifier.sid}`);
throw new Error(`Missing actor ${identifier.sid}.` +
' The VS Code API must be created before the Positron API.');
}
return this._locals[identifier.nid];
}
Expand Down