microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/common/configurationProviderHelper.ts
141lines · 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 | |
| 4 | import { |
| 5 | MultiStepInput, |
| 6 | IQuickPickParameters, |
| 7 | } from "../extension/debuggingConfiguration/multiStepInput"; |
| 8 | import { ILaunchRequestArgs } from "../debugger/debugSessionBase"; |
| 9 | import { ExpoHostType } from "../extension/launchArgs"; |
| 10 | import { |
| 11 | DebugConfigurationState, |
| 12 | DebugConfigurationQuickPickItem, |
| 13 | appTypePickConfig, |
| 14 | expoHostTypePickConfig, |
| 15 | shouldUseHermesEngine, |
| 16 | } from "../extension/debuggingConfiguration/debugConfigTypesAndConstants"; |
| 17 | import * as nls from "vscode-nls"; |
| 18 | nls.config({ |
| 19 | messageFormat: nls.MessageFormat.bundle, |
| 20 | bundleFormat: nls.BundleFormat.standalone, |
| 21 | })(); |
| 22 | const localize = nls.loadMessageBundle(); |
| 23 | |
| 24 | export class ConfigurationProviderHelper { |
| 25 | public async selectPlatform( |
| 26 | input: MultiStepInput<DebugConfigurationState>, |
| 27 | config: Partial<ILaunchRequestArgs>, |
| 28 | platformTypePickConfig: DebugConfigurationQuickPickItem[], |
| 29 | step: number, |
| 30 | totalSteps: number, |
| 31 | ): Promise<Partial<ILaunchRequestArgs>> { |
| 32 | let pick = await input.showQuickPick< |
| 33 | DebugConfigurationQuickPickItem, |
| 34 | IQuickPickParameters<DebugConfigurationQuickPickItem> |
| 35 | >({ |
| 36 | title: localize("PlatformSelectionTitle", "Select platform"), |
| 37 | placeholder: localize("PlatformSelectionPrompt", "Platform to run on"), |
| 38 | step, |
| 39 | totalSteps, |
| 40 | items: platformTypePickConfig, |
| 41 | activeItem: platformTypePickConfig[0], |
| 42 | }); |
| 43 | |
| 44 | if (!pick) { |
| 45 | throw new Error("Platform is not selected"); |
| 46 | } |
| 47 | |
| 48 | config.platform = pick.type; |
| 49 | return config; |
| 50 | } |
| 51 | |
| 52 | public async selectApplicationType( |
| 53 | input: MultiStepInput<DebugConfigurationState>, |
| 54 | config: Partial<ILaunchRequestArgs>, |
| 55 | step: number, |
| 56 | totalSteps: number, |
| 57 | ): Promise<Partial<ILaunchRequestArgs>> { |
| 58 | let pick = await input.showQuickPick< |
| 59 | DebugConfigurationQuickPickItem, |
| 60 | IQuickPickParameters<DebugConfigurationQuickPickItem> |
| 61 | >({ |
| 62 | title: localize( |
| 63 | "ApplicationTypeSelectionTitle", |
| 64 | "Select type of React Native application", |
| 65 | ), |
| 66 | placeholder: localize( |
| 67 | "ApplicationTypeSelectionPrompt", |
| 68 | "Type of React Native application", |
| 69 | ), |
| 70 | step, |
| 71 | totalSteps, |
| 72 | items: appTypePickConfig, |
| 73 | activeItem: appTypePickConfig[0], |
| 74 | }); |
| 75 | |
| 76 | if (!pick) { |
| 77 | throw new Error("Application type is not selected"); |
| 78 | } |
| 79 | |
| 80 | config.type = pick.type; |
| 81 | return config; |
| 82 | } |
| 83 | |
| 84 | public async shouldUseHermesEngine( |
| 85 | input: MultiStepInput<DebugConfigurationState>, |
| 86 | config: Partial<ILaunchRequestArgs>, |
| 87 | step: number, |
| 88 | totalSteps: number, |
| 89 | ): Promise<Partial<ILaunchRequestArgs>> { |
| 90 | let shouldUseHermes = await input.showQuickPick< |
| 91 | DebugConfigurationQuickPickItem, |
| 92 | IQuickPickParameters<DebugConfigurationQuickPickItem> |
| 93 | >({ |
| 94 | title: localize("UseHermesEngine", "Use Hermes engine"), |
| 95 | placeholder: localize( |
| 96 | "UseHermesEnginePrompt", |
| 97 | "Use Hermes engine for direct debugging?", |
| 98 | ), |
| 99 | step, |
| 100 | totalSteps, |
| 101 | items: shouldUseHermesEngine, |
| 102 | activeItem: shouldUseHermesEngine[0], |
| 103 | }); |
| 104 | |
| 105 | if (!shouldUseHermes) { |
| 106 | throw new Error( |
| 107 | localize("UseHermesEngineInvalid", "Using Hermes engine is not confirmed"), |
| 108 | ); |
| 109 | } |
| 110 | |
| 111 | config.useHermesEngine = shouldUseHermes.type === "yes"; |
| 112 | |
| 113 | return config; |
| 114 | } |
| 115 | |
| 116 | public async selectExpoHostType( |
| 117 | input: MultiStepInput<DebugConfigurationState>, |
| 118 | config: Partial<ILaunchRequestArgs>, |
| 119 | step: number, |
| 120 | totalSteps: number, |
| 121 | ): Promise<Partial<ILaunchRequestArgs>> { |
| 122 | let pick = await input.showQuickPick< |
| 123 | DebugConfigurationQuickPickItem, |
| 124 | IQuickPickParameters<DebugConfigurationQuickPickItem> |
| 125 | >({ |
| 126 | title: localize("ExpoHostTypeSelectionTitle", "Select type of Expo host parameter"), |
| 127 | placeholder: localize("ExpoHostTypeSelectionPrompt", "Type of Expo host parameter"), |
| 128 | step, |
| 129 | totalSteps, |
| 130 | items: expoHostTypePickConfig, |
| 131 | activeItem: expoHostTypePickConfig[0], |
| 132 | }); |
| 133 | |
| 134 | if (!pick) { |
| 135 | throw new Error("Expo host type is not selected"); |
| 136 | } |
| 137 | |
| 138 | config.expoHostType = pick.type as ExpoHostType; |
| 139 | return config; |
| 140 | } |
| 141 | } |
| 142 | |