Skip to content

Commit

Permalink
Add MessageType.Debug (#1264)
Browse files Browse the repository at this point in the history
* Add MessageType.Debug

* Factor out log implementation into helper method

* Add missing @SInCE annotations

* Add @SInCE tag to meta model

---------

Co-authored-by: Dirk Bäumer <dirkb@microsoft.com>
  • Loading branch information
fwcd and dbaeumer authored Sep 13, 2023
1 parent c6817d3 commit b6e99d8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
34 changes: 17 additions & 17 deletions client/src/common/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import { InlineCompletionItemFeature } from './inlineCompletion';
* Controls when the output channel is revealed.
*/
export enum RevealOutputChannelOn {
Debug = 0,
Info = 1,
Warn = 2,
Error = 3,
Expand Down Expand Up @@ -983,33 +984,29 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
return data.toString();
}

public debug(message: string, data?: any, showNotification: boolean = true): void {
this.logOutputMessage(MessageType.Debug, RevealOutputChannelOn.Debug, 'Debug', message, data, showNotification);
}

public info(message: string, data?: any, showNotification: boolean = true): void {
this.outputChannel.appendLine(`[Info - ${(new Date().toLocaleTimeString())}] ${message}`);
if (data !== null && data !== undefined) {
this.outputChannel.appendLine(this.data2String(data));
}
if (showNotification && this._clientOptions.revealOutputChannelOn <= RevealOutputChannelOn.Info) {
this.showNotificationMessage(MessageType.Info, message);
}
this.logOutputMessage(MessageType.Info, RevealOutputChannelOn.Info, 'Info', message, data, showNotification);
}

public warn(message: string, data?: any, showNotification: boolean = true): void {
this.outputChannel.appendLine(`[Warn - ${(new Date().toLocaleTimeString())}] ${message}`);
if (data !== null && data !== undefined) {
this.outputChannel.appendLine(this.data2String(data));
}
if (showNotification && this._clientOptions.revealOutputChannelOn <= RevealOutputChannelOn.Warn) {
this.showNotificationMessage(MessageType.Warning, message);
}
this.logOutputMessage(MessageType.Warning, RevealOutputChannelOn.Warn, 'Warn', message, data, showNotification);
}

public error(message: string, data?: any, showNotification: boolean | 'force' = true): void {
this.outputChannel.appendLine(`[Error - ${(new Date().toLocaleTimeString())}] ${message}`);
this.logOutputMessage(MessageType.Error, RevealOutputChannelOn.Error, 'Error', message, data, showNotification);
}

private logOutputMessage(type: MessageType, reveal: RevealOutputChannelOn, name: string, message: string, data: any | undefined, showNotification: boolean | 'force'): void {
this.outputChannel.appendLine(`[${name.padEnd(5)} - ${(new Date().toLocaleTimeString())}] ${message}`);
if (data !== null && data !== undefined) {
this.outputChannel.appendLine(this.data2String(data));
}
if (showNotification === 'force' || (showNotification && this._clientOptions.revealOutputChannelOn <= RevealOutputChannelOn.Error)) {
this.showNotificationMessage(MessageType.Error, message);
if (showNotification === 'force' || (showNotification && this._clientOptions.revealOutputChannelOn <= reveal)) {
this.showNotificationMessage(type, message);
}
}

Expand Down Expand Up @@ -1115,6 +1112,9 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
case MessageType.Info:
this.info(message.message, undefined, false);
break;
case MessageType.Debug:
this.debug(message.message, undefined, false);
break;
default:
this.outputChannel.appendLine(message.message);
}
Expand Down
6 changes: 6 additions & 0 deletions protocol/metaModel.json
Original file line number Diff line number Diff line change
Expand Up @@ -13470,6 +13470,12 @@
"name": "Log",
"value": 4,
"documentation": "A log message."
},
{
"name": "Debug",
"value": 5,
"documentation": "A debug message.\n\n@since 3.18.0",
"since": "3.18.0"
}
],
"documentation": "The message type"
Expand Down
8 changes: 7 additions & 1 deletion protocol/src/common/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1537,9 +1537,15 @@ export namespace MessageType {
* A log message.
*/
export const Log = 4;
/**
* A debug message.
*
* @since 3.18.0
*/
export const Debug = 5;
}

export type MessageType = 1 | 2 | 3 | 4;
export type MessageType = 1 | 2 | 3 | 4 | 5;

/**
* The parameters of a notification message.
Expand Down
13 changes: 13 additions & 0 deletions server/src/common/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ export interface RemoteConsole extends FeatureBase {
* @param message The message to log.
*/
log(message: string): void;

/**
* Log a debug message.
*
* @param message The message to log.
*
* @since 3.18.0
*/
debug(message: string): void;
}

class RemoteConsoleImpl implements Logger, RemoteConsole, Remote {
Expand Down Expand Up @@ -209,6 +218,10 @@ class RemoteConsoleImpl implements Logger, RemoteConsole, Remote {
this.send(MessageType.Log, message);
}

public debug(message: string): void {
this.send(MessageType.Debug, message);
}

private send(type: MessageType, message: string): void {
if (this._rawConnection) {
this._rawConnection.sendNotification(LogMessageNotification.type, { type, message }).catch(() => {
Expand Down

0 comments on commit b6e99d8

Please sign in to comment.