Skip to content

Commit

Permalink
Add determineBrowserType to CSharpExtensionExports (#5911)
Browse files Browse the repository at this point in the history
This PR exports the
BlazorDebugConfigurationProvider.determineBrowserType method that it
could be used in vscode-dotnettools to help determine the browser the
user wants to use.
  • Loading branch information
WardenGnaw authored Jul 11, 2023
1 parent 0b2bf6d commit 2138920
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/csharpExtensionExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export interface CSharpExtensionExports {
initializationFinished: () => Promise<void>;
logDirectory: string;
profferBrokeredServices: (container: GlobalBrokeredServiceContainer) => void;
determineBrowserType: () => Promise<string | undefined>;
}
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import Descriptors from './lsptoolshost/services/descriptors';
import { GlobalBrokeredServiceContainer } from '@microsoft/servicehub-framework';
import { CSharpExtensionExports, OmnisharpExtensionExports } from './csharpExtensionExports';
import { csharpDevkitExtensionId, getCSharpDevKit } from './utils/getCSharpDevKit';
import { BlazorDebugConfigurationProvider } from './razor/src/blazorDebug/blazorDebugConfigurationProvider';

export async function activate(
context: vscode.ExtensionContext
Expand Down Expand Up @@ -288,6 +289,7 @@ export async function activate(
},
profferBrokeredServices: (container) => profferBrokeredServices(context, container),
logDirectory: context.logUri.fsPath,
determineBrowserType: BlazorDebugConfigurationProvider.determineBrowserType,
};
} else {
return {
Expand Down
14 changes: 7 additions & 7 deletions src/razor/src/blazorDebug/blazorDebugConfigurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import showInformationMessage from '../../../shared/observers/utils/showInformat
import showErrorMessage from '../../../observers/utils/showErrorMessage';

export class BlazorDebugConfigurationProvider implements vscode.DebugConfigurationProvider {
private readonly autoDetectUserNotice = `Run and Debug: auto-detection found {0} for a launch browser`;
private readonly edgeBrowserType = 'msedge';
private readonly chromeBrowserType = 'chrome';
private static readonly autoDetectUserNotice = `Run and Debug: auto-detection found {0} for a launch browser`;
private static readonly edgeBrowserType = 'msedge';
private static readonly chromeBrowserType = 'chrome';

constructor(private readonly logger: RazorLogger, private readonly vscodeType: typeof vscode) {}

Expand Down Expand Up @@ -125,10 +125,10 @@ export class BlazorDebugConfigurationProvider implements vscode.DebugConfigurati
const configBrowser = configuration.browser;
const browserType =
configBrowser === 'edge'
? this.edgeBrowserType
? BlazorDebugConfigurationProvider.edgeBrowserType
: configBrowser === 'chrome'
? this.chromeBrowserType
: await this.determineBrowserType();
? BlazorDebugConfigurationProvider.chromeBrowserType
: await BlazorDebugConfigurationProvider.determineBrowserType();
if (!browserType) {
return;
}
Expand Down Expand Up @@ -172,7 +172,7 @@ export class BlazorDebugConfigurationProvider implements vscode.DebugConfigurati
}
}

private async determineBrowserType() {
public static async determineBrowserType() {
// There was no browser specified by the user, so we will do some auto-detection to find a browser,
// favoring chrome if multiple valid options are installed.
const chromeBrowserFinder = new ChromeBrowserFinder(process.env, promises, null);
Expand Down

0 comments on commit 2138920

Please sign in to comment.