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

Avoid awaiting VS Code popup notifications #557

Merged
merged 1 commit into from
Jul 24, 2024
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
31 changes: 16 additions & 15 deletions src/common/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async function findRuffBinaryPath(
const stdout = await executeFile(settings.interpreter[0], [FIND_RUFF_BINARY_SCRIPT_PATH]);
ruffBinaryPath = stdout.trim();
} catch (err) {
await vscode.window
vscode.window
.showErrorMessage(
"Unexpected error while trying to find the Ruff binary. See the logs for more details.",
"Show Logs",
Expand Down Expand Up @@ -168,7 +168,7 @@ async function createNativeServer(
MINIMUM_NATIVE_SERVER_VERSION,
)}, but found ${versionToString(ruffVersion)} at ${ruffBinaryPath} instead`;
traceError(message);
await vscode.window.showErrorMessage(message);
vscode.window.showErrorMessage(message);
return Promise.reject();
}

Expand Down Expand Up @@ -246,15 +246,16 @@ async function createLegacyServer(
return new LanguageClient(serverId, serverName, serverOptions, clientOptions);
}

async function showWarningMessageWithLogs(message: string, outputChannel: LogOutputChannel) {
const selection = await vscode.window.showWarningMessage(message, "Show Logs");
if (selection) {
outputChannel.show();
}
function showWarningMessageWithLogs(message: string, outputChannel: LogOutputChannel) {
vscode.window.showWarningMessage(message, "Show Logs").then((selection) => {
if (selection) {
outputChannel.show();
}
});
Comment on lines +250 to +254
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Maybe add an error handler that logs a message if showing the message box fails for whatever reason

Suggested change
vscode.window.showWarningMessage(message, "Show Logs").then((selection) => {
if (selection) {
outputChannel.show();
}
});
vscode.window.showWarningMessage(message, "Show Logs").then((selection) => {
if (selection) {
outputChannel.show();
}
}).catch(ex => logError("Failed to show warning message: {ex}"));

Copy link
Member Author

Choose a reason for hiding this comment

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

We could do it but there are multiple instances of these calls 🤷‍♂️

}

async function legacyServerSettingsWarning(settings: string[], outputChannel: LogOutputChannel) {
await showWarningMessageWithLogs(
function legacyServerSettingsWarning(settings: string[], outputChannel: LogOutputChannel) {
showWarningMessageWithLogs(
"Unsupported settings used with the native server. Refer to the logs for more details.",
outputChannel,
);
Expand All @@ -263,12 +264,12 @@ async function legacyServerSettingsWarning(settings: string[], outputChannel: Lo
);
}

async function nativeServerSettingsWarning(
function nativeServerSettingsWarning(
settings: string[],
outputChannel: LogOutputChannel,
suggestion?: string,
) {
await showWarningMessageWithLogs(
showWarningMessageWithLogs(
"Unsupported settings used with the legacy server (ruff-lsp). Refer to the logs for more details.",
outputChannel,
);
Expand Down Expand Up @@ -301,22 +302,22 @@ async function resolveNativeServerSetting(
case true:
const legacyServerSettings = getUserSetLegacyServerSettings(serverId, workspace);
if (legacyServerSettings.length > 0) {
await legacyServerSettingsWarning(legacyServerSettings, outputChannel);
legacyServerSettingsWarning(legacyServerSettings, outputChannel);
}
return { useNativeServer: true, executable };
case "off":
case false:
if (!vscode.workspace.isTrusted) {
const message =
"Cannot use the legacy server (ruff-lsp) in an untrusted workspace; switching to the native server using the bundled executable.";
await vscode.window.showWarningMessage(message);
vscode.window.showWarningMessage(message);
traceWarn(message);
return { useNativeServer: true, executable };
}

let nativeServerSettings = getUserSetNativeServerSettings(serverId, workspace);
if (nativeServerSettings.length > 0) {
await nativeServerSettingsWarning(nativeServerSettings, outputChannel);
nativeServerSettingsWarning(nativeServerSettings, outputChannel);
}
return { useNativeServer: false, executable };
case "auto":
Expand Down Expand Up @@ -346,7 +347,7 @@ async function resolveNativeServerSetting(
);
let nativeServerSettings = getUserSetNativeServerSettings(serverId, workspace);
if (nativeServerSettings.length > 0) {
await nativeServerSettingsWarning(
nativeServerSettingsWarning(
nativeServerSettings,
outputChannel,
"Please remove these settings or set 'nativeServer' to 'on' to use the native server",
Expand Down
8 changes: 4 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
};

await lsClient.sendRequest(ExecuteCommandRequest.type, params).then(undefined, async () => {
await vscode.window.showErrorMessage(
vscode.window.showErrorMessage(
"Failed to apply Ruff fixes to the document. Please consider opening an issue with steps to reproduce.",
);
});
Expand All @@ -206,7 +206,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
};

await lsClient.sendRequest(ExecuteCommandRequest.type, params).then(undefined, async () => {
await vscode.window.showErrorMessage(
vscode.window.showErrorMessage(
"Failed to apply Ruff formatting to the document. Please consider opening an issue with steps to reproduce.",
);
});
Expand All @@ -231,7 +231,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
};

await lsClient.sendRequest(ExecuteCommandRequest.type, params).then(undefined, async () => {
await vscode.window.showErrorMessage(
vscode.window.showErrorMessage(
`Failed to apply Ruff fixes to the document. Please consider opening an issue at ${issueTracker} with steps to reproduce.`,
);
});
Expand All @@ -247,7 +247,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
};

await lsClient.sendRequest(ExecuteCommandRequest.type, params).then(undefined, async () => {
await vscode.window.showErrorMessage("Failed to print debug information.");
vscode.window.showErrorMessage("Failed to print debug information.");
});
}),
registerLanguageStatusItem(serverId, serverName, `${serverId}.showLogs`),
Expand Down