microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.9.3

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/configurationProviderHelper.ts

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