microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.12.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/configurationProviders/debugConfigProvider.ts

130lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import { MultiStepInput, InputStep } from "../multiStepInput";
5import {
6 DebugConfigurationState,
7 platformTypeDebugPickConfig,
8 DEBUG_TYPES,
9 DebugScenarioType,
10} from "../debugConfigTypesAndConstants";
11import { PlatformType } from "../../launchArgs";
12import { ILaunchRequestArgs } from "../../../debugger/debugSessionBase";
13import { BaseConfigProvider } from "./baseConfigProvider";
14
15export class DebugConfigProvider extends BaseConfigProvider {
16 constructor() {
17 super();
18 this.maxStepCount = 2;
19 }
20
21 public async buildConfiguration(
22 input: MultiStepInput<DebugConfigurationState>,
23 state: DebugConfigurationState,
24 ): Promise<InputStep<DebugConfigurationState> | void> {
25 state.config = {};
26 const config: Partial<ILaunchRequestArgs> = {
27 name: "Debug application",
28 request: "launch",
29 type: DEBUG_TYPES.REACT_NATIVE,
30 cwd: "${workspaceFolder}",
31 };
32
33 state.scenarioType = DebugScenarioType.DebugApp;
34
35 await this.configurationProviderHelper.selectPlatform(
36 input,
37 config,
38 platformTypeDebugPickConfig,
39 1,
40 this.maxStepCount,
41 );
42
43 Object.assign(state.config, config);
44
45 if (
46 state.config.platform !== PlatformType.Exponent &&
47 state.config.platform !== PlatformType.ExpoWeb
48 ) {
49 return async () => {
50 await this.configureApplicationType(input, state.config);
51 if (
52 state.config.platform === PlatformType.iOS &&
53 state.config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT
54 ) {
55 this.maxStepCount = 3;
56 await this.configureUseHermesEngine(input, state.config);
57 // Direct iOS debugging using ios-webkit-debug-proxy is supported
58 // only with applications running on the device
59 if (state.config.useHermesEngine === false) {
60 state.config.target = "device";
61 }
62 }
63 };
64 } else if (state.config.platform === PlatformType.Exponent) {
65 return async () => {
66 await this.configureApplicationType(input, state.config);
67 await this.configureExpoHostType(input, state.config);
68 };
69 } else if (state.config.platform === PlatformType.ExpoWeb) {
70 return async () => {
71 await this.configureBrowserTarget(input, state.config);
72 await this.configureApplicationType(input, state.config);
73 state.config.url = "http://localhost:8081";
74 };
75 }
76 return;
77 }
78
79 private async configureApplicationType(
80 input: MultiStepInput<DebugConfigurationState>,
81 config: Partial<ILaunchRequestArgs>,
82 ): Promise<InputStep<DebugConfigurationState> | void> {
83 await this.configurationProviderHelper.selectApplicationType(
84 input,
85 config,
86 2,
87 this.maxStepCount,
88 );
89 }
90
91 private async configureExpoHostType(
92 input: MultiStepInput<DebugConfigurationState>,
93 config: Partial<ILaunchRequestArgs>,
94 ): Promise<InputStep<DebugConfigurationState> | void> {
95 await this.configurationProviderHelper.selectExpoHostType(
96 input,
97 config,
98 2,
99 this.maxStepCount,
100 );
101 }
102
103 private async configureUseHermesEngine(
104 input: MultiStepInput<DebugConfigurationState>,
105 config: Partial<ILaunchRequestArgs>,
106 ): Promise<InputStep<DebugConfigurationState> | void> {
107 delete config.useHermesEngine;
108 await this.configurationProviderHelper.shouldUseHermesEngine(
109 input,
110 config,
111 3,
112 this.maxStepCount,
113 );
114 if (config.useHermesEngine) {
115 delete config.useHermesEngine;
116 }
117 }
118
119 private async configureBrowserTarget(
120 input: MultiStepInput<DebugConfigurationState>,
121 config: Partial<ILaunchRequestArgs>,
122 ): Promise<InputStep<DebugConfigurationState> | void> {
123 await this.configurationProviderHelper.selectBrowserTarget(
124 input,
125 config,
126 4,
127 this.maxStepCount,
128 );
129 }
130}
131