microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/debuggingConfiguration/configurationProviders/runConfigProvider.ts
94lines · modeblame
5471436aRedMickey5 years ago | 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 { MultiStepInput, InputStep } from "../multiStepInput"; | |
| 5 | import { | |
| 6 | DebugConfigurationState, | |
| 7 | platformTypeRunPickConfig, | |
| 8 | DEBUG_TYPES, | |
| 9 | DebugScenarioType, | |
| 10 | } from "../debugConfigTypesAndConstants"; | |
| 11 | import { PlatformType } from "../../launchArgs"; | |
| 12 | import { ILaunchRequestArgs } from "../../../debugger/debugSessionBase"; | |
09f6024fHeniker4 years ago | 13 | import { BaseConfigProvider } from "./baseConfigProvider"; |
5471436aRedMickey5 years ago | 14 | |
| 15 | export class RunConfigProvider extends BaseConfigProvider { | |
| 16 | constructor() { | |
| 17 | super(); | |
| 18 | this.maxStepCount = 2; | |
| 19 | } | |
| 20 | | |
| 21 | public async buildConfiguration( | |
| 22 | input: MultiStepInput<DebugConfigurationState>, | |
| 23 | state: DebugConfigurationState, | |
| 24 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
| 25 | state.config = {}; | |
| 26 | const config: Partial<ILaunchRequestArgs> = { | |
| 27 | name: "Run application", | |
| 28 | request: "launch", | |
| 29 | type: DEBUG_TYPES.REACT_NATIVE, | |
| 30 | cwd: "${workspaceFolder}", | |
| 31 | enableDebug: false, | |
| 32 | }; | |
| 33 | | |
| 34 | state.scenarioType = DebugScenarioType.RunApp; | |
| 35 | | |
| 36 | await this.configurationProviderHelper.selectPlatform( | |
| 37 | input, | |
| 38 | config, | |
| 39 | platformTypeRunPickConfig, | |
| 40 | 1, | |
| 41 | this.maxStepCount, | |
| 42 | ); | |
| 43 | | |
| 44 | Object.assign(state.config, config); | |
| 45 | | |
008d88e5RedMickey4 years ago | 46 | if (state.config.platform !== PlatformType.Exponent) { |
0d77292aJiglioNero4 years ago | 47 | return async () => { |
| 48 | await this.configureApplicationType(input, state.config); | |
| 49 | if ( | |
| 50 | state.config.platform === PlatformType.iOS && | |
| 51 | state.config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT | |
| 52 | ) { | |
| 53 | this.maxStepCount = 3; | |
| 54 | await this.configureUseHermesEngine(input, state.config); | |
| 55 | // Direct iOS debugging using ios-webkit-debug-proxy is supported | |
| 56 | // only with applications running on the device | |
| 57 | if (state.config.useHermesEngine === false) { | |
| 58 | state.config.target = "device"; | |
6f9a0779JiglioNero5 years ago | 59 | } |
0d77292aJiglioNero4 years ago | 60 | } |
| 61 | }; | |
5471436aRedMickey5 years ago | 62 | } |
09f6024fHeniker4 years ago | 63 | |
| 64 | return; | |
5471436aRedMickey5 years ago | 65 | } |
| 66 | | |
| 67 | private async configureApplicationType( | |
| 68 | input: MultiStepInput<DebugConfigurationState>, | |
| 69 | config: Partial<ILaunchRequestArgs>, | |
| 70 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
| 71 | await this.configurationProviderHelper.selectApplicationType( | |
| 72 | input, | |
| 73 | config, | |
| 74 | 2, | |
| 75 | this.maxStepCount, | |
| 76 | ); | |
| 77 | } | |
6f9a0779JiglioNero5 years ago | 78 | |
| 79 | private async configureUseHermesEngine( | |
| 80 | input: MultiStepInput<DebugConfigurationState>, | |
| 81 | config: Partial<ILaunchRequestArgs>, | |
| 82 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
| 83 | delete config.useHermesEngine; | |
| 84 | await this.configurationProviderHelper.shouldUseHermesEngine( | |
| 85 | input, | |
| 86 | config, | |
| 87 | 3, | |
| 88 | this.maxStepCount, | |
| 89 | ); | |
| 90 | if (config.useHermesEngine) { | |
| 91 | delete config.useHermesEngine; | |
| 92 | } | |
| 93 | } | |
5471436aRedMickey5 years ago | 94 | } |