microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
78c2aaee56e1edfea55cdebbdccbf5541dff7beb

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/configurationProviderHelper.ts

218lines · 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 {
5 MultiStepInput,
6 IQuickPickParameters,
7} from "../extension/debuggingConfiguration/multiStepInput";
8import { ILaunchRequestArgs } from "../debugger/debugSessionBase";
9import { Packager } from "./packager";
10import { ExpoHostType, PlatformType } from "../extension/launchArgs";
11import {
12 DebugConfigurationState,
13 DebugConfigurationQuickPickItem,
14 appTypePickConfig,
15 expoHostTypePickConfig,
16 shouldUseHermesEngine,
17 DEBUG_TYPES,
18} from "../extension/debuggingConfiguration/debugConfigTypesAndConstants";
19import { IWDPHelper } from "../debugger/direct/IWDPHelper";
20import * as nls from "vscode-nls";
21nls.config({
22 messageFormat: nls.MessageFormat.bundle,
23 bundleFormat: nls.BundleFormat.standalone,
24})();
25const localize = nls.loadMessageBundle();
26
27export class ConfigurationProviderHelper {
28 public async selectPlatform(
29 input: MultiStepInput<DebugConfigurationState>,
30 config: Partial<ILaunchRequestArgs>,
31 platformTypePickConfig: DebugConfigurationQuickPickItem[],
32 step: number,
33 totalSteps: number,
34 ): Promise<Partial<ILaunchRequestArgs>> {
35 let pick = await input.showQuickPick<
36 DebugConfigurationQuickPickItem,
37 IQuickPickParameters<DebugConfigurationQuickPickItem>
38 >({
39 title: localize("PlatformSelectionTitle", "Select platform"),
40 placeholder: localize("PlatformSelectionPrompt", "Platform to run on"),
41 step,
42 totalSteps,
43 items: platformTypePickConfig,
44 activeItem: platformTypePickConfig[0],
45 });
46
47 if (!pick) {
48 throw new Error("Platform is not selected");
49 }
50
51 config.platform = pick.type;
52 return config;
53 }
54
55 public async selectApplicationType(
56 input: MultiStepInput<DebugConfigurationState>,
57 config: Partial<ILaunchRequestArgs>,
58 step: number,
59 totalSteps: number,
60 ): Promise<Partial<ILaunchRequestArgs>> {
61 let pick = await input.showQuickPick<
62 DebugConfigurationQuickPickItem,
63 IQuickPickParameters<DebugConfigurationQuickPickItem>
64 >({
65 title: localize(
66 "ApplicationTypeSelectionTitle",
67 "Select type of React Native application",
68 ),
69 placeholder: localize(
70 "ApplicationTypeSelectionPrompt",
71 "Type of React Native application",
72 ),
73 step,
74 totalSteps,
75 items: appTypePickConfig,
76 activeItem: appTypePickConfig[0],
77 });
78
79 if (!pick) {
80 throw new Error("Application type is not selected");
81 }
82
83 config.type = pick.type;
84 return config;
85 }
86
87 public async shouldUseHermesEngine(
88 input: MultiStepInput<DebugConfigurationState>,
89 config: Partial<ILaunchRequestArgs>,
90 step: number,
91 totalSteps: number,
92 ): Promise<Partial<ILaunchRequestArgs>> {
93 let shouldUseHermes = await input.showQuickPick<
94 DebugConfigurationQuickPickItem,
95 IQuickPickParameters<DebugConfigurationQuickPickItem>
96 >({
97 title: localize("UseHermesEngine", "Use Hermes engine"),
98 placeholder: localize(
99 "UseHermesEnginePrompt",
100 "Use Hermes engine for direct debugging?",
101 ),
102 step,
103 totalSteps,
104 items: shouldUseHermesEngine,
105 activeItem: shouldUseHermesEngine[0],
106 });
107
108 if (!shouldUseHermes) {
109 throw new Error(
110 localize("UseHermesEngineInvalid", "Using Hermes engine is not confirmed"),
111 );
112 }
113
114 config.useHermesEngine = shouldUseHermes.type === "yes";
115
116 return config;
117 }
118
119 public async selectExpoHostType(
120 input: MultiStepInput<DebugConfigurationState>,
121 config: Partial<ILaunchRequestArgs>,
122 step: number,
123 totalSteps: number,
124 ): Promise<Partial<ILaunchRequestArgs>> {
125 let pick = await input.showQuickPick<
126 DebugConfigurationQuickPickItem,
127 IQuickPickParameters<DebugConfigurationQuickPickItem>
128 >({
129 title: localize("ExpoHostTypeSelectionTitle", "Select type of Expo host parameter"),
130 placeholder: localize("ExpoHostTypeSelectionPrompt", "Type of Expo host parameter"),
131 step,
132 totalSteps,
133 items: expoHostTypePickConfig,
134 activeItem: expoHostTypePickConfig[0],
135 });
136
137 if (!pick) {
138 throw new Error("Expo host type is not selected");
139 }
140
141 config.expoHostType = pick.type as ExpoHostType;
142 return config;
143 }
144
145 public async configureAddress(
146 input: MultiStepInput<DebugConfigurationState>,
147 config: Partial<ILaunchRequestArgs>,
148 step: number,
149 totalSteps: number,
150 defaultAddress: string,
151 ): Promise<Partial<ILaunchRequestArgs>> {
152 delete config.address;
153 const address = await input.showInputBox({
154 title: localize("AddressInputTitle", "The address of the host"),
155 step,
156 totalSteps,
157 value: defaultAddress,
158 prompt: localize("AddressInputPrompt", "Enter the address of the host"),
159 validate: value =>
160 Promise.resolve(
161 value && value.trim().length > 0
162 ? undefined
163 : localize("AddressInputInvalid", "Enter a valid host name or IP address"),
164 ),
165 });
166
167 if (address && address.trim() !== defaultAddress) {
168 config.address = address.trim();
169 }
170
171 return config;
172 }
173
174 public async configurePort(
175 input: MultiStepInput<DebugConfigurationState>,
176 config: Partial<ILaunchRequestArgs>,
177 step: number,
178 totalSteps: number,
179 ): Promise<Partial<ILaunchRequestArgs>> {
180 delete config.port;
181 const defaultPort = String(
182 config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT &&
183 config.platform === PlatformType.iOS &&
184 !config.useHermesEngine
185 ? IWDPHelper.iOS_WEBKIT_DEBUG_PROXY_DEFAULT_PORT
186 : Packager.DEFAULT_PORT,
187 );
188 const portRegex = /^\d+$/;
189
190 const portStr = await input.showInputBox({
191 title: localize("PortInputTitle", "The port of the host"),
192 step,
193 totalSteps,
194 value: defaultPort,
195 prompt: localize(
196 "PortInputPrompt",
197 "Enter the port number that the debug server is listening on",
198 ),
199 validate: value =>
200 Promise.resolve(
201 value && portRegex.test(value.trim())
202 ? undefined
203 : localize("PortInputInvalid", "Enter a valid port number"),
204 ),
205 });
206
207 let portNumber: number | undefined;
208 if (portStr && portRegex.test(portStr.trim())) {
209 portNumber = parseInt(portStr, 10);
210 }
211
212 if (portNumber && portNumber !== Packager.DEFAULT_PORT) {
213 config.port = portNumber;
214 }
215
216 return config;
217 }
218}
219