Skip to content

Commit

Permalink
Always include "Show Logs" button for window messages (#600)
Browse files Browse the repository at this point in the history
## Summary

This PR includes a "Show Logs" button for all window messages from Ruff.
This might be useful to reduce the friction for the users in figuring
out where the logs are. This is something I saw when looking at
koxudaxi/ruff-pycharm-plugin#463 description.

## Test Plan

<img width="472" alt="Screenshot 2024-09-06 at 10 15 55"
src="https://github.com/user-attachments/assets/783259ed-ce68-411c-93cd-3e7e094c8172">
  • Loading branch information
dhruvmanila authored Sep 6, 2024
1 parent f3ee65b commit 287f94f
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/common/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fsapi from "fs-extra";
import * as vscode from "vscode";
import { platform } from "os";
import { Disposable, l10n, LanguageStatusSeverity, LogOutputChannel } from "vscode";
import { State } from "vscode-languageclient";
import { State, ShowMessageNotification, MessageType } from "vscode-languageclient";
import {
LanguageClient,
LanguageClientOptions,
Expand Down Expand Up @@ -439,6 +439,14 @@ export async function startServer(
},
);
traceInfo(`Server: Start requested.`);
try {
await newLSClient.start();
} catch (ex) {
updateStatus(l10n.t("Server failed to start."), LanguageStatusSeverity.Error);
traceError(`Server: Start failed: ${ex}`);
return undefined;
}

_disposables.push(
newLSClient.onDidChangeState((e) => {
switch (e.newState) {
Expand All @@ -454,14 +462,20 @@ export async function startServer(
break;
}
}),
newLSClient.onNotification(ShowMessageNotification.type, (params) => {
const showMessageMethod =
params.type === MessageType.Error
? vscode.window.showErrorMessage
: params.type === MessageType.Warning
? vscode.window.showWarningMessage
: vscode.window.showInformationMessage;
showMessageMethod(params.message, "Show Logs").then((selection) => {
if (selection) {
outputChannel.show();
}
});
}),
);
try {
await newLSClient.start();
} catch (ex) {
updateStatus(l10n.t("Server failed to start."), LanguageStatusSeverity.Error);
traceError(`Server: Start failed: ${ex}`);
return undefined;
}

return newLSClient;
}
Expand Down

0 comments on commit 287f94f

Please sign in to comment.