microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev/v-peq/remove-ios-relative-project-path

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/configurationProviders/attachConfigProvider.ts

102lines · 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
4import { MultiStepInput, InputStep } from "../multiStepInput";
5import { ILaunchRequestArgs } from "../../../debugger/debugSessionBase";
6import {
7 DebugConfigurationState,
8 platformTypeDirectPickConfig,
9 DEBUG_TYPES,
10 DebugScenarioType,
11} from "../debugConfigTypesAndConstants";
12import { BaseConfigProvider } from "./baseConfigProvider";
13
14export 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 }
51 return () => this.configureAddress(input, state.config);
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
67 if (!config.platform) {
68 delete config.platform;
69 delete config.useHermesEngine;
70 } else {
71 config.useHermesEngine = false;
72 }
73
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> {
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 );
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> {
95 await this.configurationProviderHelper.configurePort(
96 input,
97 config,
98 config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT ? 4 : 3,
99 this.maxStepCount,
100 );
101 }
102}
103