Skip to content

Commit

Permalink
Suppress 'Report an issue' on .NET acquisition failure (#5871)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-c-martin authored Feb 4, 2022
1 parent 1faac71 commit 87b0b9e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/vscode-bicep/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export async function activate(
extension.register(createLogger(context, outputChannel));
registerUIExtensionVariables({ context, outputChannel });

await activateWithTelemetryAndErrorHandling(async () => {
await activateWithTelemetryAndErrorHandling(async (actionContext) => {
const languageClient = await launchLanguageServiceWithProgressReport(
actionContext,
context,
outputChannel
);
Expand Down
16 changes: 12 additions & 4 deletions src/vscode-bicep/src/language/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const packagedServerPath = "bicepLanguageServer/Bicep.LangServer.dll";
const extensionId = "ms-azuretools.vscode-bicep";

export async function launchLanguageServiceWithProgressReport(
actionContext: IActionContext,
context: vscode.ExtensionContext,
outputChannel: vscode.OutputChannel
): Promise<lsp.LanguageClient> {
Expand All @@ -30,7 +31,8 @@ export async function launchLanguageServiceWithProgressReport(
title: "Launching Bicep language service...",
location: vscode.ProgressLocation.Notification,
},
async () => await launchLanguageService(context, outputChannel)
async () =>
await launchLanguageService(actionContext, context, outputChannel)
);
}

Expand Down Expand Up @@ -81,12 +83,13 @@ function getServerStartupOptions(
}

async function launchLanguageService(
actionContext: IActionContext,
context: vscode.ExtensionContext,
outputChannel: vscode.OutputChannel
): Promise<lsp.LanguageClient> {
getLogger().info("Launching Bicep language service...");

const dotnetCommandPath = await ensureDotnetRuntimeInstalled();
const dotnetCommandPath = await ensureDotnetRuntimeInstalled(actionContext);
getLogger().debug(`Found dotnet command at '${dotnetCommandPath}'.`);

const languageServerPath = ensureLanguageServerExists(context);
Expand Down Expand Up @@ -158,7 +161,9 @@ async function launchLanguageService(
return client;
}

async function ensureDotnetRuntimeInstalled(): Promise<string> {
async function ensureDotnetRuntimeInstalled(
actionContext: IActionContext
): Promise<string> {
getLogger().info("Acquiring dotnet runtime...");

const result = await vscode.commands.executeCommand<{ dotnetPath: string }>(
Expand All @@ -170,7 +175,10 @@ async function ensureDotnetRuntimeInstalled(): Promise<string> {
);

if (!result) {
const errorMessage = `Failed to install .NET runtime v${dotnetRuntimeVersion}.`;
// Suppress the 'Report Issue' button - we want people to use the dialog displayed by the .NET installer extension.
// It captures much more detail about the problem, and directs people to the correct repo (https://github.com/dotnet/vscode-dotnet-runtime).
actionContext.errorHandling.suppressReportIssue = true;
const errorMessage = `Failed to install .NET runtime v${dotnetRuntimeVersion}. Please see the .NET install tool error dialog for more detailed information, or to report an issue.`;

getLogger().error(errorMessage);
throw new Error(errorMessage);
Expand Down
10 changes: 5 additions & 5 deletions src/vscode-bicep/src/utils/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import {
import { getLogger } from "./logger";

export async function activateWithTelemetryAndErrorHandling(
activateCallback: () => Promise<void>
activateCallback: (actionContext: IActionContext) => Promise<void>
): Promise<void> {
await callWithTelemetryAndErrorHandling(
"bicep.activate",
async (activateContext: IActionContext) => {
async (actionContext: IActionContext) => {
const startTime = Date.now();
activateContext.telemetry.properties.isActivationEvent = "true";
actionContext.telemetry.properties.isActivationEvent = "true";

try {
await activateCallback();
await activateCallback(actionContext);
} catch (e) {
getLogger().error(e.message ?? e);
throw e;
}

activateContext.telemetry.measurements.extensionLoad =
actionContext.telemetry.measurements.extensionLoad =
(Date.now() - startTime) / 1000;
}
);
Expand Down

0 comments on commit 87b0b9e

Please sign in to comment.