microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/debuggingConfiguration/configurationProviders/debugConfigProvider.ts
109lines · 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 | platformTypeDebugPickConfig, | |
| 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 DebugConfigProvider 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: "Debug application", | |
| 28 | request: "launch", | |
| 29 | type: DEBUG_TYPES.REACT_NATIVE, | |
| 30 | cwd: "${workspaceFolder}", | |
| 31 | }; | |
| 32 | | |
| 33 | state.scenarioType = DebugScenarioType.DebugApp; | |
| 34 | | |
| 35 | await this.configurationProviderHelper.selectPlatform( | |
| 36 | input, | |
| 37 | config, | |
| 38 | platformTypeDebugPickConfig, | |
| 39 | 1, | |
| 40 | this.maxStepCount, | |
| 41 | ); | |
| 42 | | |
| 43 | Object.assign(state.config, config); | |
| 44 | | |
008d88e5RedMickey4 years ago | 45 | if (state.config.platform !== PlatformType.Exponent) { |
0d77292aJiglioNero4 years ago | 46 | return async () => { |
| 47 | await this.configureApplicationType(input, state.config); | |
| 48 | if ( | |
| 49 | state.config.platform === PlatformType.iOS && | |
| 50 | state.config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT | |
| 51 | ) { | |
| 52 | this.maxStepCount = 3; | |
| 53 | await this.configureUseHermesEngine(input, state.config); | |
| 54 | // Direct iOS debugging using ios-webkit-debug-proxy is supported | |
| 55 | // only with applications running on the device | |
| 56 | if (state.config.useHermesEngine === false) { | |
| 57 | state.config.target = "device"; | |
6f9a0779JiglioNero5 years ago | 58 | } |
0d77292aJiglioNero4 years ago | 59 | } |
| 60 | }; | |
5471436aRedMickey5 years ago | 61 | } else if (state.config.platform === PlatformType.Exponent) { |
9888ce28Ezio Li3 years ago | 62 | return async () => { |
| 63 | await this.configureApplicationType(input, state.config); | |
| 64 | await this.configureExpoHostType(input, state.config); | |
| 65 | }; | |
5471436aRedMickey5 years ago | 66 | } |
09f6024fHeniker4 years ago | 67 | return; |
5471436aRedMickey5 years ago | 68 | } |
| 69 | | |
| 70 | private async configureApplicationType( | |
| 71 | input: MultiStepInput<DebugConfigurationState>, | |
| 72 | config: Partial<ILaunchRequestArgs>, | |
| 73 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
| 74 | await this.configurationProviderHelper.selectApplicationType( | |
| 75 | input, | |
| 76 | config, | |
| 77 | 2, | |
| 78 | this.maxStepCount, | |
| 79 | ); | |
| 80 | } | |
| 81 | | |
| 82 | private async configureExpoHostType( | |
| 83 | input: MultiStepInput<DebugConfigurationState>, | |
| 84 | config: Partial<ILaunchRequestArgs>, | |
| 85 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
| 86 | await this.configurationProviderHelper.selectExpoHostType( | |
| 87 | input, | |
| 88 | config, | |
| 89 | 2, | |
| 90 | this.maxStepCount, | |
| 91 | ); | |
| 92 | } | |
6f9a0779JiglioNero5 years ago | 93 | |
| 94 | private async configureUseHermesEngine( | |
| 95 | input: MultiStepInput<DebugConfigurationState>, | |
| 96 | config: Partial<ILaunchRequestArgs>, | |
| 97 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
| 98 | delete config.useHermesEngine; | |
| 99 | await this.configurationProviderHelper.shouldUseHermesEngine( | |
| 100 | input, | |
| 101 | config, | |
| 102 | 3, | |
| 103 | this.maxStepCount, | |
| 104 | ); | |
| 105 | if (config.useHermesEngine) { | |
| 106 | delete config.useHermesEngine; | |
| 107 | } | |
| 108 | } | |
5471436aRedMickey5 years ago | 109 | } |