microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
ffdf159274093d12e32a09aafae6d0de3099bb4a

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/configurationProviders/attachConfigProvider.ts

153lines · modeblame

5471436aRedMickey5 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import { BaseConfigProvider } from "./baseConfigProvider";
5import { MultiStepInput, InputStep } from "../multiStepInput";
6import { ILaunchRequestArgs } from "../../../debugger/debugSessionBase";
7import {
8DebugConfigurationState,
9platformTypeDirectPickConfig,
10DEBUG_TYPES,
11DebugScenarioType,
12} from "../debugConfigTypesAndConstants";
13import { PlatformType } from "../../launchArgs";
14import { IWDPHelper } from "../../../debugger/direct/IWDPHelper";
15import { Packager } from "../../../common/packager";
16import * as nls from "vscode-nls";
17nls.config({
18messageFormat: nls.MessageFormat.bundle,
19bundleFormat: nls.BundleFormat.standalone,
20})();
21const localize = nls.loadMessageBundle();
22
23export class AttachConfigProvider extends BaseConfigProvider {
24private readonly defaultAddress: string;
25
26constructor() {
27super();
28this.defaultAddress = "localhost";
29this.maxStepCount = 3;
30}
31
32public async buildConfiguration(
33input: MultiStepInput<DebugConfigurationState>,
34state: DebugConfigurationState,
35): Promise<InputStep<DebugConfigurationState> | void> {
36this.maxStepCount = 3;
37state.config = {};
38const config: Partial<ILaunchRequestArgs> = {
39name: "Attach to application",
40request: "attach",
41type: DEBUG_TYPES.REACT_NATIVE,
42cwd: "${workspaceFolder}",
43};
44
45state.scenarioType = DebugScenarioType.AttachApp;
46
47await this.configurationProviderHelper.selectApplicationType(
48input,
49config,
501,
51this.maxStepCount,
52);
53
54Object.assign(state.config, config);
55
56if (state.config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT) {
57this.maxStepCount++;
58return () => this.configureDirectPlatform(input, state.config);
59} else {
60return () => this.configureAddress(input, state.config);
61}
62}
63
64private async configureDirectPlatform(
65input: MultiStepInput<DebugConfigurationState>,
66config: Partial<ILaunchRequestArgs>,
67): Promise<InputStep<DebugConfigurationState> | void> {
68delete config.platform;
69await this.configurationProviderHelper.selectPlatform(
70input,
71config,
72platformTypeDirectPickConfig,
732,
74this.maxStepCount,
75);
76
6f9a0779JiglioNero5 years ago77if (!config.platform) {
78delete config.platform;
79delete config.useHermesEngine;
80} else {
81config.useHermesEngine = false;
82}
83
5471436aRedMickey5 years ago84return () => this.configureAddress(input, config);
85}
86
87private async configureAddress(
88input: MultiStepInput<DebugConfigurationState>,
89config: Partial<ILaunchRequestArgs>,
90): Promise<InputStep<DebugConfigurationState> | void> {
91delete config.address;
92let address = await input.showInputBox({
93title: localize("AddressInputTitle", "The address of the host"),
94step: config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT ? 3 : 2,
95totalSteps: this.maxStepCount,
96value: this.defaultAddress,
97prompt: localize("AddressInputPrompt", "Enter the address of the host"),
98validate: value =>
99Promise.resolve(
100value && value.trim().length > 0
101? undefined
102: localize("AddressInputInvalid", "Enter a valid host name or IP address"),
103),
104});
105
106if (address && address.trim() !== this.defaultAddress) {
107config.address = address.trim();
108}
109
110return () => this.configurePort(input, config);
111}
112
113private async configurePort(
114input: MultiStepInput<DebugConfigurationState>,
115config: Partial<ILaunchRequestArgs>,
116): Promise<InputStep<DebugConfigurationState> | void> {
117delete config.port;
118const defaultPort = String(
6f9a0779JiglioNero5 years ago119config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT &&
120config.platform === PlatformType.iOS &&
121!config.useHermesEngine
5471436aRedMickey5 years ago122? IWDPHelper.iOS_WEBKIT_DEBUG_PROXY_DEFAULT_PORT
123: Packager.DEFAULT_PORT,
124);
125const portRegex = /^\d+$/;
126
127let portStr = await input.showInputBox({
128title: localize("PortInputTitle", "The port of the host"),
129step: config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT ? 4 : 3,
130totalSteps: this.maxStepCount,
131value: defaultPort,
132prompt: localize(
133"PortInputPrompt",
134"Enter the port number that the debug server is listening on",
135),
136validate: value =>
137Promise.resolve(
138value && portRegex.test(value.trim())
139? undefined
140: localize("PortInputInvalid", "Enter a valid port number"),
141),
142});
143
144let portNumber: number | undefined;
145if (portStr && portRegex.test(portStr.trim())) {
146portNumber = parseInt(portStr, 10);
147}
148
149if (portNumber && portNumber !== Packager.DEFAULT_PORT) {
150config.port = portNumber;
151}
152}
153}