microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
fix-ts-error1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/reactNativeDebugDynamicConfigProvider.ts

162lines · 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];
8363a9dcEzio Li11 months ago45delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.DEBUG_WINDOWS_HERMES];
e7a2c40dRedMickey4 years ago46} else {
47windowsHermesEnabled = ReactNativeProjectHelper.isWindowsHermesEnabled(rootPath);
48if (!windowsHermesEnabled) {
49delete debugConfigurationsToShow[
8363a9dcEzio Li11 months ago50DEBUG_CONFIGURATION_NAMES.DEBUG_WINDOWS_HERMES
e7a2c40dRedMickey4 years ago51];
52}
53}
54
55if (ProjectVersionHelper.isVersionError(versions.reactNativeMacOSVersion)) {
56delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.DEBUG_MACOS];
8363a9dcEzio Li11 months ago57delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.DEBUG_MACOS_HERMES];
e7a2c40dRedMickey4 years ago58} else {
59macOSHermesEnabled = ReactNativeProjectHelper.isMacOSHermesEnabled(rootPath);
60if (!macOSHermesEnabled) {
8363a9dcEzio Li11 months ago61delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.DEBUG_MACOS_HERMES];
e7a2c40dRedMickey4 years ago62}
63}
64
65if (!androidHermesEnabled) {
c6ca8545Ezio Li3 years ago66delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.DEBUG_ANDROID_HERMES];
67delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.RUN_ANDROID_HERMES];
e7a2c40dRedMickey4 years ago68}
69
70if (!iOSHermesEnabled) {
c6ca8545Ezio Li3 years ago71delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.DEBUG_IOS_HERMES];
72delete debugConfigurationsToShow[DEBUG_CONFIGURATION_NAMES.RUN_IOS_HERMES];
e7a2c40dRedMickey4 years ago73}
74
75if (
76!androidHermesEnabled &&
77!iOSHermesEnabled &&
78!macOSHermesEnabled &&
79!windowsHermesEnabled
80) {
81delete debugConfigurationsToShow[
c6ca8545Ezio Li3 years ago82DEBUG_CONFIGURATION_NAMES.ATTACH_TO_HERMES_APPLICATION
e7a2c40dRedMickey4 years ago83];
84}
85}
86
87const debugConfigurationsToShowList = Object.values(debugConfigurationsToShow);
88debugConfigurationsToShowList.forEach(config => {
89config.isDynamic = true;
90});
91
92return debugConfigurationsToShowList;
93}
94
95public async resolveDebugConfiguration(
96folder: vscode.WorkspaceFolder | undefined,
97config: vscode.DebugConfiguration,
98token?: vscode.CancellationToken,
99): Promise<vscode.ProviderResult<vscode.DebugConfiguration>> {
100if (config.isDynamic) {
101const chosenConfigsEvent = TelemetryHelper.createTelemetryEvent(
102"chosenDynamicDebugConfiguration",
103{
104selectedConfiguration: config.name,
105},
106);
107Telemetry.send(chosenConfigsEvent);
108if (config.request === "attach") {
109await this.configureAttachScenario(folder, config, token);
110}
111if (config.platform === PlatformType.Exponent) {
112await this.configureExpoScenario(folder, config, token);
113}
114}
115
116return config;
117}
118
119private async configureExpoScenario(
120folder: vscode.WorkspaceFolder | undefined,
121config: vscode.DebugConfiguration,
122token?: vscode.CancellationToken,
123): Promise<vscode.DebugConfiguration> {
124const state = { config, scenarioType: DebugScenarioType.DebugApp, folder, token };
125const picker = new MultiStepInput<DebugConfigurationState>();
126const configurationProviderHelper = new ConfigurationProviderHelper();
127await picker.run(async (input, s) => {
128await configurationProviderHelper.selectExpoHostType(input, s.config, 1, 1);
129}, state);
130
131return config;
132}
133
134private async configureAttachScenario(
135folder: vscode.WorkspaceFolder | undefined,
136config: vscode.DebugConfiguration,
137token?: vscode.CancellationToken,
138): Promise<vscode.DebugConfiguration> {
139const state = { config, scenarioType: DebugScenarioType.AttachApp, folder, token };
140const picker = new MultiStepInput<DebugConfigurationState>();
141const configurationProviderHelper = new ConfigurationProviderHelper();
142
143const configurePort = async (
144input: MultiStepInput<DebugConfigurationState>,
145config: Partial<ILaunchRequestArgs>,
146): Promise<InputStep<DebugConfigurationState> | void> => {
147await configurationProviderHelper.configurePort(input, config, 2, 2);
148};
149
150const configureAddress = async (
151input: MultiStepInput<DebugConfigurationState>,
152config: Partial<ILaunchRequestArgs>,
153): Promise<InputStep<DebugConfigurationState> | void> => {
154await configurationProviderHelper.configureAddress(input, config, 1, 2, "localhost");
155return () => configurePort(input, config);
156};
157
158await picker.run((input, s) => configureAddress(input, s.config), state);
159
160return config;
161}
162}