Skip to content

Commit

Permalink
Ensure Blazor prompts only show once per open workspace.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich committed Apr 7, 2021
1 parent bb5ea6c commit 6ee8745
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 26 deletions.
8 changes: 8 additions & 0 deletions src/omnisharp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class OmniSharpServer {
private _launchTarget: LaunchTarget;
private _requestQueue: RequestQueueCollection;
private _serverProcess: ChildProcess;
private _sessionProperties: { [key: string]: any } = {};

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

public get sessionProperties() {
return this._sessionProperties;
}

public isRunning(): boolean {
return this._state === ServerState.Started;
}
Expand Down Expand Up @@ -434,6 +439,9 @@ export class OmniSharpServer {

let cleanupPromise: Promise<void>;

// Clear the session properties when the session ends.
this._sessionProperties = {};

if (this._telemetryIntervalId !== undefined) {
// Stop reporting telemetry
clearInterval(this._telemetryIntervalId);
Expand Down
69 changes: 43 additions & 26 deletions src/omnisharp/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export async function requestProjectInformation(server: OmniSharpServer, request
export async function requestWorkspaceInformation(server: OmniSharpServer) {
const response = await server.makeRequest<protocol.WorkspaceInformationResponse>(protocol.Requests.Projects);
if (response.MsBuild && response.MsBuild.Projects) {
const blazorDetectionEnabled = hasBlazorWebAssemblyDebugPrerequisites();
let blazorWebAssemblyProjectFound = false;

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

project.IsBlazorWebAssemblyHosted = blazorDetectionEnabled && isProjectBlazorWebAssemblyHosted;
project.IsBlazorWebAssemblyStandalone = blazorDetectionEnabled && isProjectBlazorWebAssemblyProject && !project.IsBlazorWebAssemblyHosted;
project.IsBlazorWebAssemblyHosted = isProjectBlazorWebAssemblyHosted;
project.IsBlazorWebAssemblyStandalone = isProjectBlazorWebAssemblyProject && !project.IsBlazorWebAssemblyHosted;

blazorWebAssemblyProjectFound = blazorWebAssemblyProjectFound || isProjectBlazorWebAssemblyProject;
}

const configuration = vscode.workspace.getConfiguration('razor');
const disableBlazorDebugPrompt = configuration.get('disableBlazorDebugPrompt');

if (!blazorDetectionEnabled && blazorWebAssemblyProjectFound && !disableBlazorDebugPrompt) {
if (blazorWebAssemblyProjectFound && !hasBlazorWebAssemblyDebugPrerequisites(server)) {
const configuration = vscode.workspace.getConfiguration('razor');
// There's a Blazor Web Assembly project but VSCode isn't configured to debug the WASM code, show a notification
// to help the user configure their VSCode appropriately.
vscode.window.showInformationMessage('Additional setup is required to debug Blazor WebAssembly applications.', 'Don\'t Ask Again', 'Learn more', 'Close')
.then(async result => {
if (result === 'Learn more') {
const uriToOpen = vscode.Uri.parse('https://aka.ms/blazordebugging#vscode');
await vscode.commands.executeCommand('vscode.open', uriToOpen);
}
if (result === 'Don\'t Ask Again') {
await configuration.update('disableBlazorDebugPrompt', true);
}
});
showBlazorConfigurationRequiredPrompt(server, configuration);
}
}

Expand Down Expand Up @@ -239,17 +227,10 @@ async function isBlazorWebAssemblyProject(project: MSBuildProject): Promise<bool
return false;
}

function hasBlazorWebAssemblyDebugPrerequisites() {
function hasBlazorWebAssemblyDebugPrerequisites(server: OmniSharpServer) {
const companionExtension = vscode.extensions.getExtension('ms-dotnettools.blazorwasm-companion');
if (!companionExtension) {
const msg = 'The Blazor WASM Debugging Extension is required to debug Blazor WASM apps in VS Code.';
vscode.window.showInformationMessage(msg, 'Install Extension', 'Close')
.then(async result => {
if (result === 'Install Extension') {
const uriToOpen = vscode.Uri.parse('vscode:extension/ms-dotnettools.blazorwasm-companion');
await vscode.commands.executeCommand('vscode.open', uriToOpen);
}
});
showBlazorDebuggingExtensionPrompt(server);
return false;
}

Expand Down Expand Up @@ -282,3 +263,39 @@ function isWebProject(project: MSBuildProject): boolean {
// TODO: Have OmniSharp provide the list of SDKs used by a project and check that list instead.
return projectFileText.toLowerCase().indexOf('sdk="microsoft.net.sdk.web"') >= 0;
}

function showBlazorConfigurationRequiredPrompt(server: OmniSharpServer, configuration: vscode.WorkspaceConfiguration) {
const disableBlazorDebugPrompt = configuration.get('disableBlazorDebugPrompt');

const promptShownKey = 'blazor_configuration_required_prompt_shown';
if (!disableBlazorDebugPrompt && !server.sessionProperties[promptShownKey]) {
server.sessionProperties[promptShownKey] = true;

vscode.window.showInformationMessage('Additional setup is required to debug Blazor WebAssembly applications.', 'Don\'t Ask Again', 'Learn more', 'Close')
.then(async result => {
if (result === 'Learn more') {
const uriToOpen = vscode.Uri.parse('https://aka.ms/blazordebugging#vscode');
await vscode.commands.executeCommand('vscode.open', uriToOpen);
}
if (result === 'Don\'t Ask Again') {
await configuration.update('disableBlazorDebugPrompt', true);
}
});
}
}

function showBlazorDebuggingExtensionPrompt(server: OmniSharpServer) {
const promptShownKey = 'blazor_debugging_extension_prompt_shown';
if (!server.sessionProperties[promptShownKey]) {
server.sessionProperties[promptShownKey] = true;

const msg = 'The Blazor WASM Debugging Extension is required to debug Blazor WASM apps in VS Code.';
vscode.window.showInformationMessage(msg, 'Install Extension', 'Close')
.then(async result => {
if (result === 'Install Extension') {
const uriToOpen = vscode.Uri.parse('vscode:extension/ms-dotnettools.blazorwasm-companion');
await vscode.commands.executeCommand('vscode.open', uriToOpen);
}
});
}
}

0 comments on commit 6ee8745

Please sign in to comment.