microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.8.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/configurationProviderHelper.ts

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