Skip to content

Commit 6d28b76

Browse files
Decouple the log levels for our two output windows
Prior to moving things to LogOutputChannels, we implicitly controlled the log level of the LSP traces by the log level of our main output channel: as long as that was debug or trace, we'd also output the LSP traces. Now each channel behaves independently, with the requirement that if you want LSP tracing, you must set the trace channel to 'trace' level. The other settings don't do anything.
1 parent 0276139 commit 6d28b76

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

src/lsptoolshost/server/roslynLanguageServer.ts

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ export class RoslynLanguageServer {
127127
private _context: vscode.ExtensionContext,
128128
private _telemetryReporter: TelemetryReporter,
129129
private _languageServerEvents: RoslynLanguageServerEvents,
130-
private _channel: vscode.LogOutputChannel
130+
private _channel: vscode.LogOutputChannel,
131+
private _traceChannel: vscode.LogOutputChannel
131132
) {
132-
this.registerSetTrace();
133+
this.registerOutputChannelsChangeHandlers();
133134
this.registerSendOpenSolution();
134135
this.registerProjectInitialization();
135136
this.registerServerStateChanged();
@@ -164,29 +165,41 @@ export class RoslynLanguageServer {
164165
return RoslynLanguageServer._processId;
165166
}
166167

167-
private registerSetTrace() {
168-
// Set the language client trace level based on the log level option.
169-
// setTrace only works after the client is already running.
168+
private registerOutputChannelsChangeHandlers() {
170169
this._languageClient.onDidChangeState(async (state) => {
171170
if (state.newState === State.Running) {
172-
await this.updateLogLevel();
171+
await this.updateOutputChannelLogLevel();
172+
await this.updateTraceChannelLogLevel();
173173
}
174174
});
175175
// Register for changes to the log level.
176176
this._channel.onDidChangeLogLevel(async () => {
177-
await this.updateLogLevel();
177+
await this.updateOutputChannelLogLevel();
178+
});
179+
this._traceChannel.onDidChangeLogLevel(async () => {
180+
// The LSP client also responds to didChangeLogLevel and sets its own logic; we want to override that so do a small delay
181+
setTimeout(async () => {
182+
await this.updateTraceChannelLogLevel();
183+
}, 1);
178184
});
179185
}
180186

181-
private async updateLogLevel(): Promise<void> {
187+
private async updateOutputChannelLogLevel(): Promise<void> {
182188
if (this._languageClient.state === State.Running) {
183-
const languageClientTraceLevel = RoslynLanguageServer.GetTraceLevel(this._channel.logLevel);
184189
// Update the server's log level.
185190
await this.sendNotification('roslyn/updateLogLevel', {
186191
logLevel: RoslynLanguageServer.GetServerLogLevel(this._channel.logLevel),
187192
});
188-
// Update the trace level that the client uses to log trace messages.
189-
await this._languageClient.setTrace(languageClientTraceLevel);
193+
}
194+
}
195+
196+
private async updateTraceChannelLogLevel(): Promise<void> {
197+
if (this._languageClient.state === State.Running) {
198+
await this._languageClient.setTrace(
199+
// If the logLevel is set to trace, we want to have verbose tracing. All tracing from the LSP client is done at 'trace' level,
200+
// so we can't show tracing at any other output window levels, since it just gets filtered away.
201+
this._traceChannel.logLevel == vscode.LogLevel.Trace ? Trace.Verbose : Trace.Off
202+
);
190203
}
191204
}
192205

@@ -329,7 +342,8 @@ export class RoslynLanguageServer {
329342
context,
330343
telemetryReporter,
331344
languageServerEvents,
332-
channel
345+
channel,
346+
traceChannel
333347
);
334348

335349
client.registerFeature(server._onAutoInsertFeature);
@@ -1102,25 +1116,6 @@ export class RoslynLanguageServer {
11021116
}
11031117
}
11041118

1105-
private static GetTraceLevel(logLevel: vscode.LogLevel): Trace {
1106-
switch (logLevel) {
1107-
case vscode.LogLevel.Trace:
1108-
return Trace.Verbose;
1109-
case vscode.LogLevel.Debug:
1110-
return Trace.Messages;
1111-
case vscode.LogLevel.Info:
1112-
return Trace.Off;
1113-
case vscode.LogLevel.Warning:
1114-
return Trace.Off;
1115-
case vscode.LogLevel.Error:
1116-
return Trace.Off;
1117-
case vscode.LogLevel.Off:
1118-
return Trace.Off;
1119-
default:
1120-
throw new Error(`Invalid log level ${logLevel}`);
1121-
}
1122-
}
1123-
11241119
public async getBuildOnlyDiagnosticIds(token: vscode.CancellationToken): Promise<string[]> {
11251120
// If the server isn't running, no build diagnostics to get
11261121
if (!this.isRunning()) {

0 commit comments

Comments
 (0)