microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/debuggingConfiguration/configurationProviders/attachConfigProvider.ts
102lines · 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 { ILaunchRequestArgs } from "../../../debugger/debugSessionBase"; | |
| 6 | import { | |
| 7 | DebugConfigurationState, | |
| 8 | platformTypeDirectPickConfig, | |
| 9 | DEBUG_TYPES, | |
| 10 | DebugScenarioType, | |
| 11 | } from "../debugConfigTypesAndConstants"; | |
09f6024fHeniker4 years ago | 12 | import { BaseConfigProvider } from "./baseConfigProvider"; |
5471436aRedMickey5 years ago | 13 | |
| 14 | export class AttachConfigProvider extends BaseConfigProvider { | |
| 15 | private readonly defaultAddress: string; | |
| 16 | | |
| 17 | constructor() { | |
| 18 | super(); | |
| 19 | this.defaultAddress = "localhost"; | |
| 20 | this.maxStepCount = 3; | |
| 21 | } | |
| 22 | | |
| 23 | public async buildConfiguration( | |
| 24 | input: MultiStepInput<DebugConfigurationState>, | |
| 25 | state: DebugConfigurationState, | |
| 26 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
| 27 | this.maxStepCount = 3; | |
| 28 | state.config = {}; | |
| 29 | const config: Partial<ILaunchRequestArgs> = { | |
| 30 | name: "Attach to application", | |
| 31 | request: "attach", | |
| 32 | type: DEBUG_TYPES.REACT_NATIVE, | |
| 33 | cwd: "${workspaceFolder}", | |
| 34 | }; | |
| 35 | | |
| 36 | state.scenarioType = DebugScenarioType.AttachApp; | |
| 37 | | |
| 38 | await this.configurationProviderHelper.selectApplicationType( | |
| 39 | input, | |
| 40 | config, | |
| 41 | 1, | |
| 42 | this.maxStepCount, | |
| 43 | ); | |
| 44 | | |
| 45 | Object.assign(state.config, config); | |
| 46 | | |
| 47 | if (state.config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT) { | |
| 48 | this.maxStepCount++; | |
| 49 | return () => this.configureDirectPlatform(input, state.config); | |
| 50 | } | |
09f6024fHeniker4 years ago | 51 | return () => this.configureAddress(input, state.config); |
5471436aRedMickey5 years ago | 52 | } |
| 53 | | |
| 54 | private async configureDirectPlatform( | |
| 55 | input: MultiStepInput<DebugConfigurationState>, | |
| 56 | config: Partial<ILaunchRequestArgs>, | |
| 57 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
| 58 | delete config.platform; | |
| 59 | await this.configurationProviderHelper.selectPlatform( | |
| 60 | input, | |
| 61 | config, | |
| 62 | platformTypeDirectPickConfig, | |
| 63 | 2, | |
| 64 | this.maxStepCount, | |
| 65 | ); | |
| 66 | | |
6f9a0779JiglioNero5 years ago | 67 | if (!config.platform) { |
| 68 | delete config.platform; | |
| 69 | delete config.useHermesEngine; | |
| 70 | } else { | |
| 71 | config.useHermesEngine = false; | |
| 72 | } | |
| 73 | | |
5471436aRedMickey5 years ago | 74 | return () => this.configureAddress(input, config); |
| 75 | } | |
| 76 | | |
| 77 | private async configureAddress( | |
| 78 | input: MultiStepInput<DebugConfigurationState>, | |
| 79 | config: Partial<ILaunchRequestArgs>, | |
| 80 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
e7a2c40dRedMickey4 years ago | 81 | await this.configurationProviderHelper.configureAddress( |
| 82 | input, | |
| 83 | config, | |
| 84 | config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT ? 3 : 2, | |
| 85 | this.maxStepCount, | |
| 86 | this.defaultAddress, | |
| 87 | ); | |
5471436aRedMickey5 years ago | 88 | return () => this.configurePort(input, config); |
| 89 | } | |
| 90 | | |
| 91 | private async configurePort( | |
| 92 | input: MultiStepInput<DebugConfigurationState>, | |
| 93 | config: Partial<ILaunchRequestArgs>, | |
| 94 | ): Promise<InputStep<DebugConfigurationState> | void> { | |
e7a2c40dRedMickey4 years ago | 95 | await this.configurationProviderHelper.configurePort( |
| 96 | input, | |
| 97 | config, | |
| 98 | config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT ? 4 : 3, | |
| 99 | this.maxStepCount, | |
5471436aRedMickey5 years ago | 100 | ); |
| 101 | } | |
| 102 | } |