microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
test-microbuild1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/reactNativeDebugDynamicConfigProvider.ts

168lines · modeblame

e7a2c40dRedMickey4 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as vscode from "vscode";
5import { SettingsHelper } from "../settingsHelper";
6import { TelemetryHelper } from "../../common/telemetryHelper";
7import { Telemetry } from "../../common/telemetry";
8import { ProjectVersionHelper } from "../../common/projectVersionHelper";
9import { ReactNativeProjectHelper } from "../../common/reactNativeProjectHelper";
10import { PlatformType } from "../launchArgs";
11import { ILaunchRequestArgs } from "../../debugger/debugSessionBase";
12import { ConfigurationProviderHelper } from "../../common/configurationProviderHelper";
09f6024fHeniker4 years ago13import { MultiStepInput, InputStep } from "./multiStepInput";
14import {
15debugConfigurations,
16DEBUG_CONFIGURATION_NAMES,
17DebugScenarioType,
18DebugConfigurationState,
19} from "./debugConfigTypesAndConstants";
e7a2c40dRedMickey4 years ago20
21export class ReactNativeDebugDynamicConfigProvider implements vscode.DebugConfigurationProvider {
22public async provideDebugConfigurations(
23folder: vscode.WorkspaceFolder | undefined,
24token?: vscode.CancellationToken, // eslint-disable-line @typescript-eslint/no-unused-vars
25): Promise<vscode.DebugConfiguration[]> {
09f6024fHeniker4 years ago26const debugConfigurationsToShow = Object.assign({}, debugConfigurations);
e7a2c40dRedMickey4 years ago27
28if (folder) {
09f6024fHeniker4 years ago29const rootPath = folder.uri.fsPath;
30const projectRootPath = SettingsHelper.getReactNativeProjectRoot(rootPath);
31const versions =
32await ProjectVersionHelper.tryToGetRNSemverValidVersionsFromProjectPackage(
33projectRootPath,
34ProjectVersionHelper.generateAllAdditionalPackages(),
35projectRootPath,
36);
e7a2c40dRedMickey4 years ago37
38let macOSHermesEnabled = false;
39let windowsHermesEnabled = false;
09f6024fHeniker4 years ago40const androidHermesEnabled = ReactNativeProjectHelper.isAndroidHermesEnabled(rootPath);
41const iOSHermesEnabled = ReactNativeProjectHelper.isIOSHermesEnabled(rootPath);
e7a2c40dRedMickey4 years ago42
43if (ProjectVersionHelper.isVersionError(versions.reactNativeWindowsVersion)) {
44delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.DEBUG_WINDOWS];
45delete debugConfigurationsToShow[
46DEBUG_CONFIGURATION_NAMES.DEBUG_WINDOWS_HERMES_EXPERIMENTAL
47];
48} else {
49windowsHermesEnabled = ReactNativeProjectHelper.isWindowsHermesEnabled(rootPath);
50if (!windowsHermesEnabled) {
51delete debugConfigurationsToShow[
52DEBUG_CONFIGURATION_NAMES.DEBUG_WINDOWS_HERMES_EXPERIMENTAL
53];
54}
55}
56
57if (ProjectVersionHelper.isVersionError(versions.reactNativeMacOSVersion)) {
58delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.DEBUG_MACOS];
59delete debugConfigurationsToShow[
60DEBUG_CONFIGURATION_NAMES.DEBUG_MACOS_HERMES_EXPERIMENTAL
61];
62} else {
63macOSHermesEnabled = ReactNativeProjectHelper.isMacOSHermesEnabled(rootPath);
64if (!macOSHermesEnabled) {
65delete debugConfigurationsToShow[
66DEBUG_CONFIGURATION_NAMES.DEBUG_MACOS_HERMES_EXPERIMENTAL
67];
68}
69}
70
71if (!androidHermesEnabled) {
c6ca8545Ezio Li3 years ago72delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.DEBUG_ANDROID_HERMES];
73delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.RUN_ANDROID_HERMES];
e7a2c40dRedMickey4 years ago74}
75
76if (!iOSHermesEnabled) {
c6ca8545Ezio Li3 years ago77delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.DEBUG_IOS_HERMES];
78delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.RUN_IOS_HERMES];
e7a2c40dRedMickey4 years ago79}
80
81if (
82!androidHermesEnabled &&
83!iOSHermesEnabled &&
84!macOSHermesEnabled &&
85!windowsHermesEnabled
86) {
87delete debugConfigurationsToShow[
c6ca8545Ezio Li3 years ago88DEBUG_CONFIGURATION_NAMES.ATTACH_TO_HERMES_APPLICATION
e7a2c40dRedMickey4 years ago89];
90}
91}
92
93const debugConfigurationsToShowList = Object.values(debugConfigurationsToShow);
94debugConfigurationsToShowList.forEach(config => {
95config.isDynamic = true;
96});
97
98return debugConfigurationsToShowList;
99}
100
101public async resolveDebugConfiguration(
102folder: vscode.WorkspaceFolder | undefined,
103config: vscode.DebugConfiguration,
104token?: vscode.CancellationToken,
105): Promise<vscode.ProviderResult<vscode.DebugConfiguration>> {
106if (config.isDynamic) {
107const chosenConfigsEvent = TelemetryHelper.createTelemetryEvent(
108"chosenDynamicDebugConfiguration",
109{
110selectedConfiguration: config.name,
111},
112);
113Telemetry.send(chosenConfigsEvent);
114if (config.request === "attach") {
115await this.configureAttachScenario(folder, config, token);
116}
117if (config.platform === PlatformType.Exponent) {
118await this.configureExpoScenario(folder, config, token);
119}
120}
121
122return config;
123}
124
125private async configureExpoScenario(
126folder: vscode.WorkspaceFolder | undefined,
127config: vscode.DebugConfiguration,
128token?: vscode.CancellationToken,
129): Promise<vscode.DebugConfiguration> {
130const state = { config, scenarioType: DebugScenarioType.DebugApp, folder, token };
131const picker = new MultiStepInput<DebugConfigurationState>();
132const configurationProviderHelper = new ConfigurationProviderHelper();
133await picker.run(async (input, s) => {
134await configurationProviderHelper.selectExpoHostType(input, s.config, 1, 1);
135}, state);
136
137return config;
138}
139
140private async configureAttachScenario(
141folder: vscode.WorkspaceFolder | undefined,
142config: vscode.DebugConfiguration,
143token?: vscode.CancellationToken,
144): Promise<vscode.DebugConfiguration> {
145const state = { config, scenarioType: DebugScenarioType.AttachApp, folder, token };
146const picker = new MultiStepInput<DebugConfigurationState>();
147const configurationProviderHelper = new ConfigurationProviderHelper();
148
149const configurePort = async (
150input: MultiStepInput<DebugConfigurationState>,
151config: Partial<ILaunchRequestArgs>,
152): Promise<InputStep<DebugConfigurationState> | void> => {
153await configurationProviderHelper.configurePort(input, config, 2, 2);
154};
155
156const configureAddress = async (
157input: MultiStepInput<DebugConfigurationState>,
158config: Partial<ILaunchRequestArgs>,
159): Promise<InputStep<DebugConfigurationState> | void> => {
160await configurationProviderHelper.configureAddress(input, config, 1, 2, "localhost");
161return () => configurePort(input, config);
162};
163
164await picker.run((input, s) => configureAddress(input, s.config), state);
165
166return config;
167}
168}