microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
improve-configuration

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/configurationProviderHelper.ts

274lines · modeblame

5471436aRedMickey5 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
09f6024fHeniker4 years ago4import * as nls from "vscode-nls";
5471436aRedMickey5 years ago5import {
6MultiStepInput,
7IQuickPickParameters,
8} from "../extension/debuggingConfiguration/multiStepInput";
9import { ILaunchRequestArgs } from "../debugger/debugSessionBase";
7a4506dclexie0111 years ago10import { ExpoHostType, PlatformType, ExpoPlatform } from "../extension/launchArgs";
5471436aRedMickey5 years ago11import {
12DebugConfigurationState,
13DebugConfigurationQuickPickItem,
14appTypePickConfig,
7a4506dclexie0111 years ago15expoPlatform,
5471436aRedMickey5 years ago16expoHostTypePickConfig,
6f9a0779JiglioNero5 years ago17shouldUseHermesEngine,
e7a2c40dRedMickey4 years ago18DEBUG_TYPES,
9f8c460dEzio Li2 years ago19browserTypePickConfig,
20BROWSER_TYPES,
5471436aRedMickey5 years ago21} from "../extension/debuggingConfiguration/debugConfigTypesAndConstants";
e7a2c40dRedMickey4 years ago22import { IWDPHelper } from "../debugger/direct/IWDPHelper";
09f6024fHeniker4 years ago23import { Packager } from "./packager";
24
5471436aRedMickey5 years ago25nls.config({
26messageFormat: nls.MessageFormat.bundle,
27bundleFormat: nls.BundleFormat.standalone,
28})();
29const localize = nls.loadMessageBundle();
30
31export class ConfigurationProviderHelper {
32public async selectPlatform(
33input: MultiStepInput<DebugConfigurationState>,
34config: Partial<ILaunchRequestArgs>,
35platformTypePickConfig: DebugConfigurationQuickPickItem[],
36step: number,
37totalSteps: number,
38): Promise<Partial<ILaunchRequestArgs>> {
09f6024fHeniker4 years ago39const pick = await input.showQuickPick<
5471436aRedMickey5 years ago40DebugConfigurationQuickPickItem,
41IQuickPickParameters<DebugConfigurationQuickPickItem>
42>({
43title: localize("PlatformSelectionTitle", "Select platform"),
44placeholder: localize("PlatformSelectionPrompt", "Platform to run on"),
45step,
46totalSteps,
47items: platformTypePickConfig,
48activeItem: platformTypePickConfig[0],
49});
50
51if (!pick) {
52throw new Error("Platform is not selected");
53}
54
55config.platform = pick.type;
56return config;
57}
58
59public async selectApplicationType(
60input: MultiStepInput<DebugConfigurationState>,
61config: Partial<ILaunchRequestArgs>,
62step: number,
63totalSteps: number,
64): Promise<Partial<ILaunchRequestArgs>> {
09f6024fHeniker4 years ago65const pick = await input.showQuickPick<
5471436aRedMickey5 years ago66DebugConfigurationQuickPickItem,
67IQuickPickParameters<DebugConfigurationQuickPickItem>
68>({
69title: localize(
70"ApplicationTypeSelectionTitle",
71"Select type of React Native application",
72),
73placeholder: localize(
74"ApplicationTypeSelectionPrompt",
75"Type of React Native application",
76),
77step,
78totalSteps,
79items: appTypePickConfig,
80activeItem: appTypePickConfig[0],
81});
82
83if (!pick) {
84throw new Error("Application type is not selected");
85}
86
87config.type = pick.type;
88return config;
89}
90
6f9a0779JiglioNero5 years ago91public async shouldUseHermesEngine(
92input: MultiStepInput<DebugConfigurationState>,
93config: Partial<ILaunchRequestArgs>,
94step: number,
95totalSteps: number,
96): Promise<Partial<ILaunchRequestArgs>> {
09f6024fHeniker4 years ago97const shouldUseHermes = await input.showQuickPick<
6f9a0779JiglioNero5 years ago98DebugConfigurationQuickPickItem,
99IQuickPickParameters<DebugConfigurationQuickPickItem>
100>({
101title: localize("UseHermesEngine", "Use Hermes engine"),
102placeholder: localize(
103"UseHermesEnginePrompt",
104"Use Hermes engine for direct debugging?",
105),
106step,
107totalSteps,
108items: shouldUseHermesEngine,
109activeItem: shouldUseHermesEngine[0],
110});
111
112if (!shouldUseHermes) {
113throw new Error(
114localize("UseHermesEngineInvalid", "Using Hermes engine is not confirmed"),
115);
116}
117
118config.useHermesEngine = shouldUseHermes.type === "yes";
119
120return config;
121}
122
7a4506dclexie0111 years ago123public async selectExpoPlatform(
124input: MultiStepInput<DebugConfigurationState>,
125config: Partial<ILaunchRequestArgs>,
126step: number,
127totalSteps: number,
128): Promise<Partial<ILaunchRequestArgs>> {
129const pick = await input.showQuickPick<
130DebugConfigurationQuickPickItem,
131IQuickPickParameters<DebugConfigurationQuickPickItem>
132>({
133title: localize("ExpoPlatformTypeSelection", "Select platform to run on"),
134placeholder: localize("ExpoPlatformTypeSelectionPrompt", "Type of platform to run on"),
135step,
136totalSteps,
137items: expoPlatform,
138activeItem: expoPlatform[0],
139});
140
141if (!pick) {
142throw new Error("Expo platform is not selected");
143}
144
145config.expoPlatformType = pick.label as ExpoPlatform;
146return config;
147}
148
5471436aRedMickey5 years ago149public async selectExpoHostType(
150input: MultiStepInput<DebugConfigurationState>,
151config: Partial<ILaunchRequestArgs>,
152step: number,
153totalSteps: number,
154): Promise<Partial<ILaunchRequestArgs>> {
09f6024fHeniker4 years ago155const pick = await input.showQuickPick<
5471436aRedMickey5 years ago156DebugConfigurationQuickPickItem,
157IQuickPickParameters<DebugConfigurationQuickPickItem>
158>({
159title: localize("ExpoHostTypeSelectionTitle", "Select type of Expo host parameter"),
160placeholder: localize("ExpoHostTypeSelectionPrompt", "Type of Expo host parameter"),
161step,
162totalSteps,
163items: expoHostTypePickConfig,
164activeItem: expoHostTypePickConfig[0],
165});
166
167if (!pick) {
168throw new Error("Expo host type is not selected");
169}
170
171config.expoHostType = pick.type as ExpoHostType;
172return config;
173}
e7a2c40dRedMickey4 years ago174
9f8c460dEzio Li2 years ago175public async selectBrowserTarget(
176input: MultiStepInput<DebugConfigurationState>,
177config: Partial<ILaunchRequestArgs>,
178step: number,
179totalSteps: number,
180): Promise<Partial<ILaunchRequestArgs>> {
181const pick = await input.showQuickPick<
182DebugConfigurationQuickPickItem,
183IQuickPickParameters<DebugConfigurationQuickPickItem>
184>({
185title: localize("BrowserTypeSelectionTitle", "Select type of browser"),
186placeholder: localize("BrowserTypeSelectionPrompt", "Type of browser"),
187step,
188totalSteps,
189items: browserTypePickConfig,
190activeItem: browserTypePickConfig[0],
191});
192
193if (!pick) {
194throw new Error(localize("NoBrowserTargetSelected", "Browser target is not selected"));
195}
196
197config.browserTarget = pick.type as BROWSER_TYPES;
198return config;
199}
200
e7a2c40dRedMickey4 years ago201public async configureAddress(
202input: MultiStepInput<DebugConfigurationState>,
203config: Partial<ILaunchRequestArgs>,
204step: number,
205totalSteps: number,
206defaultAddress: string,
207): Promise<Partial<ILaunchRequestArgs>> {
208delete config.address;
209const address = await input.showInputBox({
210title: localize("AddressInputTitle", "The address of the host"),
211step,
212totalSteps,
213value: defaultAddress,
214prompt: localize("AddressInputPrompt", "Enter the address of the host"),
215validate: value =>
216Promise.resolve(
217value && value.trim().length > 0
218? undefined
219: localize("AddressInputInvalid", "Enter a valid host name or IP address"),
220),
221});
222
223if (address && address.trim() !== defaultAddress) {
224config.address = address.trim();
225}
226
227return config;
228}
229
230public async configurePort(
231input: MultiStepInput<DebugConfigurationState>,
232config: Partial<ILaunchRequestArgs>,
233step: number,
234totalSteps: number,
235): Promise<Partial<ILaunchRequestArgs>> {
236delete config.port;
237const defaultPort = String(
238config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT &&
239config.platform === PlatformType.iOS &&
240!config.useHermesEngine
241? IWDPHelper.iOS_WEBKIT_DEBUG_PROXY_DEFAULT_PORT
242: Packager.DEFAULT_PORT,
243);
244const portRegex = /^\d+$/;
245
246const portStr = await input.showInputBox({
247title: localize("PortInputTitle", "The port of the host"),
248step,
249totalSteps,
250value: defaultPort,
251prompt: localize(
252"PortInputPrompt",
253"Enter the port number that the debug server is listening on",
254),
255validate: value =>
256Promise.resolve(
257value && portRegex.test(value.trim())
258? undefined
259: localize("PortInputInvalid", "Enter a valid port number"),
260),
261});
262
263let portNumber: number | undefined;
264if (portStr && portRegex.test(portStr.trim())) {
265portNumber = parseInt(portStr, 10);
266}
267
268if (portNumber && portNumber !== Packager.DEFAULT_PORT) {
269config.port = portNumber;
270}
271
272return config;
273}
5471436aRedMickey5 years ago274}