Skip to content

Commit 6ee8745

Browse files
committed
Ensure Blazor prompts only show once per open workspace.
1 parent bb5ea6c commit 6ee8745

File tree

2 files changed

+51
-26
lines changed

2 files changed

+51
-26
lines changed

src/omnisharp/server.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export class OmniSharpServer {
9393
private _launchTarget: LaunchTarget;
9494
private _requestQueue: RequestQueueCollection;
9595
private _serverProcess: ChildProcess;
96+
private _sessionProperties: { [key: string]: any } = {};
9697

9798
private _omnisharpManager: OmnisharpManager;
9899
private updateProjectDebouncer = new Subject<ObservableEvents.ProjectModified>();
@@ -106,6 +107,10 @@ export class OmniSharpServer {
106107
this.firstUpdateProject = true;
107108
}
108109

110+
public get sessionProperties() {
111+
return this._sessionProperties;
112+
}
113+
109114
public isRunning(): boolean {
110115
return this._state === ServerState.Started;
111116
}
@@ -434,6 +439,9 @@ export class OmniSharpServer {
434439

435440
let cleanupPromise: Promise<void>;
436441

442+
// Clear the session properties when the session ends.
443+
this._sessionProperties = {};
444+
437445
if (this._telemetryIntervalId !== undefined) {
438446
// Stop reporting telemetry
439447
clearInterval(this._telemetryIntervalId);

src/omnisharp/utils.ts

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export async function requestProjectInformation(server: OmniSharpServer, request
7878
export async function requestWorkspaceInformation(server: OmniSharpServer) {
7979
const response = await server.makeRequest<protocol.WorkspaceInformationResponse>(protocol.Requests.Projects);
8080
if (response.MsBuild && response.MsBuild.Projects) {
81-
const blazorDetectionEnabled = hasBlazorWebAssemblyDebugPrerequisites();
8281
let blazorWebAssemblyProjectFound = false;
8382

8483
for (const project of response.MsBuild.Projects) {
@@ -87,28 +86,17 @@ export async function requestWorkspaceInformation(server: OmniSharpServer) {
8786
const isProjectBlazorWebAssemblyProject = await isBlazorWebAssemblyProject(project);
8887
const isProjectBlazorWebAssemblyHosted = isBlazorWebAssemblyHosted(project, isProjectBlazorWebAssemblyProject);
8988

90-
project.IsBlazorWebAssemblyHosted = blazorDetectionEnabled && isProjectBlazorWebAssemblyHosted;
91-
project.IsBlazorWebAssemblyStandalone = blazorDetectionEnabled && isProjectBlazorWebAssemblyProject && !project.IsBlazorWebAssemblyHosted;
89+
project.IsBlazorWebAssemblyHosted = isProjectBlazorWebAssemblyHosted;
90+
project.IsBlazorWebAssemblyStandalone = isProjectBlazorWebAssemblyProject && !project.IsBlazorWebAssemblyHosted;
9291

9392
blazorWebAssemblyProjectFound = blazorWebAssemblyProjectFound || isProjectBlazorWebAssemblyProject;
9493
}
9594

96-
const configuration = vscode.workspace.getConfiguration('razor');
97-
const disableBlazorDebugPrompt = configuration.get('disableBlazorDebugPrompt');
98-
99-
if (!blazorDetectionEnabled && blazorWebAssemblyProjectFound && !disableBlazorDebugPrompt) {
95+
if (blazorWebAssemblyProjectFound && !hasBlazorWebAssemblyDebugPrerequisites(server)) {
96+
const configuration = vscode.workspace.getConfiguration('razor');
10097
// There's a Blazor Web Assembly project but VSCode isn't configured to debug the WASM code, show a notification
10198
// to help the user configure their VSCode appropriately.
102-
vscode.window.showInformationMessage('Additional setup is required to debug Blazor WebAssembly applications.', 'Don\'t Ask Again', 'Learn more', 'Close')
103-
.then(async result => {
104-
if (result === 'Learn more') {
105-
const uriToOpen = vscode.Uri.parse('https://aka.ms/blazordebugging#vscode');
106-
await vscode.commands.executeCommand('vscode.open', uriToOpen);
107-
}
108-
if (result === 'Don\'t Ask Again') {
109-
await configuration.update('disableBlazorDebugPrompt', true);
110-
}
111-
});
99+
showBlazorConfigurationRequiredPrompt(server, configuration);
112100
}
113101
}
114102

@@ -239,17 +227,10 @@ async function isBlazorWebAssemblyProject(project: MSBuildProject): Promise<bool
239227
return false;
240228
}
241229

242-
function hasBlazorWebAssemblyDebugPrerequisites() {
230+
function hasBlazorWebAssemblyDebugPrerequisites(server: OmniSharpServer) {
243231
const companionExtension = vscode.extensions.getExtension('ms-dotnettools.blazorwasm-companion');
244232
if (!companionExtension) {
245-
const msg = 'The Blazor WASM Debugging Extension is required to debug Blazor WASM apps in VS Code.';
246-
vscode.window.showInformationMessage(msg, 'Install Extension', 'Close')
247-
.then(async result => {
248-
if (result === 'Install Extension') {
249-
const uriToOpen = vscode.Uri.parse('vscode:extension/ms-dotnettools.blazorwasm-companion');
250-
await vscode.commands.executeCommand('vscode.open', uriToOpen);
251-
}
252-
});
233+
showBlazorDebuggingExtensionPrompt(server);
253234
return false;
254235
}
255236

@@ -282,3 +263,39 @@ function isWebProject(project: MSBuildProject): boolean {
282263
// TODO: Have OmniSharp provide the list of SDKs used by a project and check that list instead.
283264
return projectFileText.toLowerCase().indexOf('sdk="microsoft.net.sdk.web"') >= 0;
284265
}
266+
267+
function showBlazorConfigurationRequiredPrompt(server: OmniSharpServer, configuration: vscode.WorkspaceConfiguration) {
268+
const disableBlazorDebugPrompt = configuration.get('disableBlazorDebugPrompt');
269+
270+
const promptShownKey = 'blazor_configuration_required_prompt_shown';
271+
if (!disableBlazorDebugPrompt && !server.sessionProperties[promptShownKey]) {
272+
server.sessionProperties[promptShownKey] = true;
273+
274+
vscode.window.showInformationMessage('Additional setup is required to debug Blazor WebAssembly applications.', 'Don\'t Ask Again', 'Learn more', 'Close')
275+
.then(async result => {
276+
if (result === 'Learn more') {
277+
const uriToOpen = vscode.Uri.parse('https://aka.ms/blazordebugging#vscode');
278+
await vscode.commands.executeCommand('vscode.open', uriToOpen);
279+
}
280+
if (result === 'Don\'t Ask Again') {
281+
await configuration.update('disableBlazorDebugPrompt', true);
282+
}
283+
});
284+
}
285+
}
286+
287+
function showBlazorDebuggingExtensionPrompt(server: OmniSharpServer) {
288+
const promptShownKey = 'blazor_debugging_extension_prompt_shown';
289+
if (!server.sessionProperties[promptShownKey]) {
290+
server.sessionProperties[promptShownKey] = true;
291+
292+
const msg = 'The Blazor WASM Debugging Extension is required to debug Blazor WASM apps in VS Code.';
293+
vscode.window.showInformationMessage(msg, 'Install Extension', 'Close')
294+
.then(async result => {
295+
if (result === 'Install Extension') {
296+
const uriToOpen = vscode.Uri.parse('vscode:extension/ms-dotnettools.blazorwasm-companion');
297+
await vscode.commands.executeCommand('vscode.open', uriToOpen);
298+
}
299+
});
300+
}
301+
}

0 commit comments

Comments
 (0)