microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/configurationProviders/attachConfigProvider.ts

144lines · 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
77return () => this.configureAddress(input, config);
78}
79
80private async configureAddress(
81input: MultiStepInput<DebugConfigurationState>,
82config: Partial<ILaunchRequestArgs>,
83): Promise<InputStep<DebugConfigurationState> | void> {
84delete config.address;
85let address = await input.showInputBox({
86title: localize("AddressInputTitle", "The address of the host"),
87step: config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT ? 3 : 2,
88totalSteps: this.maxStepCount,
89value: this.defaultAddress,
90prompt: localize("AddressInputPrompt", "Enter the address of the host"),
91validate: value =>
92Promise.resolve(
93value && value.trim().length > 0
94? undefined
95: localize("AddressInputInvalid", "Enter a valid host name or IP address"),
96),
97});
98
99if (address && address.trim() !== this.defaultAddress) {
100config.address = address.trim();
101}
102
103return () => this.configurePort(input, config);
104}
105
106private async configurePort(
107input: MultiStepInput<DebugConfigurationState>,
108config: Partial<ILaunchRequestArgs>,
109): Promise<InputStep<DebugConfigurationState> | void> {
110delete config.port;
111const defaultPort = String(
112config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT && config.platform === PlatformType.iOS
113? IWDPHelper.iOS_WEBKIT_DEBUG_PROXY_DEFAULT_PORT
114: Packager.DEFAULT_PORT,
115);
116const portRegex = /^\d+$/;
117
118let portStr = await input.showInputBox({
119title: localize("PortInputTitle", "The port of the host"),
120step: config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT ? 4 : 3,
121totalSteps: this.maxStepCount,
122value: defaultPort,
123prompt: localize(
124"PortInputPrompt",
125"Enter the port number that the debug server is listening on",
126),
127validate: value =>
128Promise.resolve(
129value && portRegex.test(value.trim())
130? undefined
131: localize("PortInputInvalid", "Enter a valid port number"),
132),
133});
134
135let portNumber: number | undefined;
136if (portStr && portRegex.test(portStr.trim())) {
137portNumber = parseInt(portStr, 10);
138}
139
140if (portNumber && portNumber !== Packager.DEFAULT_PORT) {
141config.port = portNumber;
142}
143}
144}