Skip to content

Commit b6e99d8

Browse files
fwcddbaeumer
andauthored
Add MessageType.Debug (#1264)
* 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 <[email protected]>
1 parent c6817d3 commit b6e99d8

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed

client/src/common/client.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ import { InlineCompletionItemFeature } from './inlineCompletion';
113113
* Controls when the output channel is revealed.
114114
*/
115115
export enum RevealOutputChannelOn {
116+
Debug = 0,
116117
Info = 1,
117118
Warn = 2,
118119
Error = 3,
@@ -983,33 +984,29 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
983984
return data.toString();
984985
}
985986

987+
public debug(message: string, data?: any, showNotification: boolean = true): void {
988+
this.logOutputMessage(MessageType.Debug, RevealOutputChannelOn.Debug, 'Debug', message, data, showNotification);
989+
}
990+
986991
public info(message: string, data?: any, showNotification: boolean = true): void {
987-
this.outputChannel.appendLine(`[Info - ${(new Date().toLocaleTimeString())}] ${message}`);
988-
if (data !== null && data !== undefined) {
989-
this.outputChannel.appendLine(this.data2String(data));
990-
}
991-
if (showNotification && this._clientOptions.revealOutputChannelOn <= RevealOutputChannelOn.Info) {
992-
this.showNotificationMessage(MessageType.Info, message);
993-
}
992+
this.logOutputMessage(MessageType.Info, RevealOutputChannelOn.Info, 'Info', message, data, showNotification);
994993
}
995994

996995
public warn(message: string, data?: any, showNotification: boolean = true): void {
997-
this.outputChannel.appendLine(`[Warn - ${(new Date().toLocaleTimeString())}] ${message}`);
998-
if (data !== null && data !== undefined) {
999-
this.outputChannel.appendLine(this.data2String(data));
1000-
}
1001-
if (showNotification && this._clientOptions.revealOutputChannelOn <= RevealOutputChannelOn.Warn) {
1002-
this.showNotificationMessage(MessageType.Warning, message);
1003-
}
996+
this.logOutputMessage(MessageType.Warning, RevealOutputChannelOn.Warn, 'Warn', message, data, showNotification);
1004997
}
1005998

1006999
public error(message: string, data?: any, showNotification: boolean | 'force' = true): void {
1007-
this.outputChannel.appendLine(`[Error - ${(new Date().toLocaleTimeString())}] ${message}`);
1000+
this.logOutputMessage(MessageType.Error, RevealOutputChannelOn.Error, 'Error', message, data, showNotification);
1001+
}
1002+
1003+
private logOutputMessage(type: MessageType, reveal: RevealOutputChannelOn, name: string, message: string, data: any | undefined, showNotification: boolean | 'force'): void {
1004+
this.outputChannel.appendLine(`[${name.padEnd(5)} - ${(new Date().toLocaleTimeString())}] ${message}`);
10081005
if (data !== null && data !== undefined) {
10091006
this.outputChannel.appendLine(this.data2String(data));
10101007
}
1011-
if (showNotification === 'force' || (showNotification && this._clientOptions.revealOutputChannelOn <= RevealOutputChannelOn.Error)) {
1012-
this.showNotificationMessage(MessageType.Error, message);
1008+
if (showNotification === 'force' || (showNotification && this._clientOptions.revealOutputChannelOn <= reveal)) {
1009+
this.showNotificationMessage(type, message);
10131010
}
10141011
}
10151012

@@ -1115,6 +1112,9 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
11151112
case MessageType.Info:
11161113
this.info(message.message, undefined, false);
11171114
break;
1115+
case MessageType.Debug:
1116+
this.debug(message.message, undefined, false);
1117+
break;
11181118
default:
11191119
this.outputChannel.appendLine(message.message);
11201120
}

protocol/metaModel.json

+6
Original file line numberDiff line numberDiff line change
@@ -13470,6 +13470,12 @@
1347013470
"name": "Log",
1347113471
"value": 4,
1347213472
"documentation": "A log message."
13473+
},
13474+
{
13475+
"name": "Debug",
13476+
"value": 5,
13477+
"documentation": "A debug message.\n\n@since 3.18.0",
13478+
"since": "3.18.0"
1347313479
}
1347413480
],
1347513481
"documentation": "The message type"

protocol/src/common/protocol.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1537,9 +1537,15 @@ export namespace MessageType {
15371537
* A log message.
15381538
*/
15391539
export const Log = 4;
1540+
/**
1541+
* A debug message.
1542+
*
1543+
* @since 3.18.0
1544+
*/
1545+
export const Debug = 5;
15401546
}
15411547

1542-
export type MessageType = 1 | 2 | 3 | 4;
1548+
export type MessageType = 1 | 2 | 3 | 4 | 5;
15431549

15441550
/**
15451551
* The parameters of a notification message.

server/src/common/server.ts

+13
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ export interface RemoteConsole extends FeatureBase {
162162
* @param message The message to log.
163163
*/
164164
log(message: string): void;
165+
166+
/**
167+
* Log a debug message.
168+
*
169+
* @param message The message to log.
170+
*
171+
* @since 3.18.0
172+
*/
173+
debug(message: string): void;
165174
}
166175

167176
class RemoteConsoleImpl implements Logger, RemoteConsole, Remote {
@@ -209,6 +218,10 @@ class RemoteConsoleImpl implements Logger, RemoteConsole, Remote {
209218
this.send(MessageType.Log, message);
210219
}
211220

221+
public debug(message: string): void {
222+
this.send(MessageType.Debug, message);
223+
}
224+
212225
private send(type: MessageType, message: string): void {
213226
if (this._rawConnection) {
214227
this._rawConnection.sendNotification(LogMessageNotification.type, { type, message }).catch(() => {

0 commit comments

Comments
 (0)