microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.9.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/reactNativeDebugDynamicConfigProvider.ts

176lines · 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) {
72delete debugConfigurationsToShow[
73DEBUG_CONFIGURATION_NAMES.DEBUG_ANDROID_HERMES_EXPERIMENTAL
74];
75delete debugConfigurationsToShow[
76DEBUG_CONFIGURATION_NAMES.RUN_ANDROID_HERMES_EXPERIMENTAL
77];
78}
79
80if (!iOSHermesEnabled) {
81delete debugConfigurationsToShow[
82DEBUG_CONFIGURATION_NAMES.DEBUG_IOS_HERMES_EXPERIMENTAL
83];
84delete debugConfigurationsToShow[
85DEBUG_CONFIGURATION_NAMES.RUN_IOS_HERMES_EXPERIMENTAL
86];
87}
88
89if (
90!androidHermesEnabled &&
91!iOSHermesEnabled &&
92!macOSHermesEnabled &&
93!windowsHermesEnabled
94) {
95delete debugConfigurationsToShow[
96DEBUG_CONFIGURATION_NAMES.ATTACH_TO_HERMES_APPLICATION_EXPERIMENTAL
97];
98}
99}
100
101const debugConfigurationsToShowList = Object.values(debugConfigurationsToShow);
102debugConfigurationsToShowList.forEach(config => {
103config.isDynamic = true;
104});
105
106return debugConfigurationsToShowList;
107}
108
109public async resolveDebugConfiguration(
110folder: vscode.WorkspaceFolder | undefined,
111config: vscode.DebugConfiguration,
112token?: vscode.CancellationToken,
113): Promise<vscode.ProviderResult<vscode.DebugConfiguration>> {
114if (config.isDynamic) {
115const chosenConfigsEvent = TelemetryHelper.createTelemetryEvent(
116"chosenDynamicDebugConfiguration",
117{
118selectedConfiguration: config.name,
119},
120);
121Telemetry.send(chosenConfigsEvent);
122if (config.request === "attach") {
123await this.configureAttachScenario(folder, config, token);
124}
125if (config.platform === PlatformType.Exponent) {
126await this.configureExpoScenario(folder, config, token);
127}
128}
129
130return config;
131}
132
133private async configureExpoScenario(
134folder: vscode.WorkspaceFolder | undefined,
135config: vscode.DebugConfiguration,
136token?: vscode.CancellationToken,
137): Promise<vscode.DebugConfiguration> {
138const state = { config, scenarioType: DebugScenarioType.DebugApp, folder, token };
139const picker = new MultiStepInput<DebugConfigurationState>();
140const configurationProviderHelper = new ConfigurationProviderHelper();
141await picker.run(async (input, s) => {
142await configurationProviderHelper.selectExpoHostType(input, s.config, 1, 1);
143}, state);
144
145return config;
146}
147
148private async configureAttachScenario(
149folder: vscode.WorkspaceFolder | undefined,
150config: vscode.DebugConfiguration,
151token?: vscode.CancellationToken,
152): Promise<vscode.DebugConfiguration> {
153const state = { config, scenarioType: DebugScenarioType.AttachApp, folder, token };
154const picker = new MultiStepInput<DebugConfigurationState>();
155const configurationProviderHelper = new ConfigurationProviderHelper();
156
157const configurePort = async (
158input: MultiStepInput<DebugConfigurationState>,
159config: Partial<ILaunchRequestArgs>,
160): Promise<InputStep<DebugConfigurationState> | void> => {
161await configurationProviderHelper.configurePort(input, config, 2, 2);
162};
163
164const configureAddress = async (
165input: MultiStepInput<DebugConfigurationState>,
166config: Partial<ILaunchRequestArgs>,
167): Promise<InputStep<DebugConfigurationState> | void> => {
168await configurationProviderHelper.configureAddress(input, config, 1, 2, "localhost");
169return () => configurePort(input, config);
170};
171
172await picker.run((input, s) => configureAddress(input, s.config), state);
173
174return config;
175}
176}