microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/debuggingConfiguration/configurationProviders/debugConfigProvider.ts
135lines · 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 | | |
9f8c460dEzio Li2 years ago | 45 | if ( |
| 46 | state.config.platform !== PlatformType.Exponent && | |
| 47 | state.config.platform !== PlatformType.ExpoWeb | |
| 48 | ) { | |
0d77292aJiglioNero4 years ago | 49 | return async () => { |
| 50 | await this.configureApplicationType(input, state.config); | |
| 51 | if ( | |
| 52 | state.config.platform === PlatformType.iOS && | |
| 53 | state.config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT | |
| 54 | ) { | |
| 55 | this.maxStepCount = 3; | |
| 56 | await this.configureUseHermesEngine(input, state.config); | |
| 57 | // Direct iOS debugging using ios-webkit-debug-proxy is supported | |
| 58 | // only with applications running on the device | |
| 59 | if (state.config.useHermesEngine === false) { | |
| 60 | state.config.target = "device"; | |
6f9a0779JiglioNero5 years ago | 61 | } |
0d77292aJiglioNero4 years ago | 62 | } |
| 63 | }; | |
5471436aRedMickey5 years ago | 64 | } else if (state.config.platform === PlatformType.Exponent) { |
9888ce28Ezio Li3 years ago | 65 | return async () => { |
| 66 | await this.configureApplicationType(input, state.config); | |
7a4506dclexie0111 years ago | 67 | if (state.config.type === "reactnativedirect") { |
| 68 | await this.configureExpoPlatform(input, state.config); | |
| 69 | } | |
9888ce28Ezio Li3 years ago | 70 | await this.configureExpoHostType(input, state.config); |
| 71 | }; | |
9f8c460dEzio Li2 years ago | 72 | } else if (state.config.platform === PlatformType.ExpoWeb) { |
| 73 | return async () => { | |
| 74 | await this.configureBrowserTarget(input, state.config); | |
| 75 | await this.configureApplicationType(input, state.config); | |
a1824f64Ezio Li2 years ago | 76 | state.config.url = "http://localhost:8081"; |
9f8c460dEzio Li2 years ago | 77 | }; |
5471436aRedMickey5 years ago | 78 | } |
09f6024fHeniker4 years ago | 79 | return; |
5471436aRedMickey5 years ago | 80 | } |
| 81 | | |
| 82 | private async configureApplicationType( | |
| 83 | input: MultiStepInput<DebugConfigurationState>, | |
| 84 | config: Partial<ILaunchRequestArgs>, | |
| 85 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
| 86 | await this.configurationProviderHelper.selectApplicationType( | |
| 87 | input, | |
| 88 | config, | |
| 89 | 2, | |
| 90 | this.maxStepCount, | |
| 91 | ); | |
| 92 | } | |
| 93 | | |
| 94 | private async configureExpoHostType( | |
| 95 | input: MultiStepInput<DebugConfigurationState>, | |
| 96 | config: Partial<ILaunchRequestArgs>, | |
| 97 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
7a4506dclexie0111 years ago | 98 | await this.configurationProviderHelper.selectExpoHostType(input, config, 4, 4); |
| 99 | } | |
| 100 | | |
| 101 | private async configureExpoPlatform( | |
| 102 | input: MultiStepInput<DebugConfigurationState>, | |
| 103 | config: Partial<ILaunchRequestArgs>, | |
| 104 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
| 105 | await this.configurationProviderHelper.selectExpoPlatform(input, config, 3, 4); | |
5471436aRedMickey5 years ago | 106 | } |
6f9a0779JiglioNero5 years ago | 107 | |
| 108 | private async configureUseHermesEngine( | |
| 109 | input: MultiStepInput<DebugConfigurationState>, | |
| 110 | config: Partial<ILaunchRequestArgs>, | |
| 111 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
| 112 | delete config.useHermesEngine; | |
| 113 | await this.configurationProviderHelper.shouldUseHermesEngine( | |
| 114 | input, | |
| 115 | config, | |
| 116 | 3, | |
| 117 | this.maxStepCount, | |
| 118 | ); | |
| 119 | if (config.useHermesEngine) { | |
| 120 | delete config.useHermesEngine; | |
| 121 | } | |
| 122 | } | |
9f8c460dEzio Li2 years ago | 123 | |
| 124 | private async configureBrowserTarget( | |
| 125 | input: MultiStepInput<DebugConfigurationState>, | |
| 126 | config: Partial<ILaunchRequestArgs>, | |
| 127 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
| 128 | await this.configurationProviderHelper.selectBrowserTarget( | |
| 129 | input, | |
| 130 | config, | |
| 131 | 4, | |
| 132 | this.maxStepCount, | |
| 133 | ); | |
| 134 | } | |
5471436aRedMickey5 years ago | 135 | } |