microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/extension/debuggingConfiguration/configurationProviders/attachConfigProvider.ts
103lines · 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 { BaseConfigProvider } from "./baseConfigProvider"; |
| 5 | import { MultiStepInput, InputStep } from "../multiStepInput"; |
| 6 | import { ILaunchRequestArgs } from "../../../debugger/debugSessionBase"; |
| 7 | import { |
| 8 | DebugConfigurationState, |
| 9 | platformTypeDirectPickConfig, |
| 10 | DEBUG_TYPES, |
| 11 | DebugScenarioType, |
| 12 | } from "../debugConfigTypesAndConstants"; |
| 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 | } else { |
| 51 | return () => this.configureAddress(input, state.config); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | private async configureDirectPlatform( |
| 56 | input: MultiStepInput<DebugConfigurationState>, |
| 57 | config: Partial<ILaunchRequestArgs>, |
| 58 | ): Promise<InputStep<DebugConfigurationState> | void> { |
| 59 | delete config.platform; |
| 60 | await this.configurationProviderHelper.selectPlatform( |
| 61 | input, |
| 62 | config, |
| 63 | platformTypeDirectPickConfig, |
| 64 | 2, |
| 65 | this.maxStepCount, |
| 66 | ); |
| 67 | |
| 68 | if (!config.platform) { |
| 69 | delete config.platform; |
| 70 | delete config.useHermesEngine; |
| 71 | } else { |
| 72 | config.useHermesEngine = false; |
| 73 | } |
| 74 | |
| 75 | return () => this.configureAddress(input, config); |
| 76 | } |
| 77 | |
| 78 | private async configureAddress( |
| 79 | input: MultiStepInput<DebugConfigurationState>, |
| 80 | config: Partial<ILaunchRequestArgs>, |
| 81 | ): Promise<InputStep<DebugConfigurationState> | void> { |
| 82 | await this.configurationProviderHelper.configureAddress( |
| 83 | input, |
| 84 | config, |
| 85 | config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT ? 3 : 2, |
| 86 | this.maxStepCount, |
| 87 | this.defaultAddress, |
| 88 | ); |
| 89 | return () => this.configurePort(input, config); |
| 90 | } |
| 91 | |
| 92 | private async configurePort( |
| 93 | input: MultiStepInput<DebugConfigurationState>, |
| 94 | config: Partial<ILaunchRequestArgs>, |
| 95 | ): Promise<InputStep<DebugConfigurationState> | void> { |
| 96 | await this.configurationProviderHelper.configurePort( |
| 97 | input, |
| 98 | config, |
| 99 | config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT ? 4 : 3, |
| 100 | this.maxStepCount, |
| 101 | ); |
| 102 | } |
| 103 | } |
| 104 | |