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/common/configurationProviderHelper.ts

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