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/debugger/direct/directDebugSession.ts

276lines · modeblame

2c19da7fRedMickey6 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 * as vscode from "vscode";
5import { ProjectVersionHelper } from "../../common/projectVersionHelper";
984ca036RedMickey6 years ago6import { logger } from "vscode-debugadapter";
2c19da7fRedMickey6 years ago7import { TelemetryHelper } from "../../common/telemetryHelper";
8import { DebugProtocol } from "vscode-debugprotocol";
259c018fYuri Skorokhodov5 years ago9import { HermesCDPMessageHandler } from "../../cdp-proxy/CDPMessageHandlers/hermesCDPMessageHandler";
2c19da7fRedMickey6 years ago10import { DebugSessionBase, IAttachRequestArgs, ILaunchRequestArgs } from "../debugSessionBase";
1bdccb66RedMickey6 years ago11import { JsDebugConfigAdapter } from "../jsDebugConfigAdapter";
984ca036RedMickey6 years ago12import { DebuggerEndpointHelper } from "../../cdp-proxy/debuggerEndpointHelper";
5514e287RedMickey6 years ago13import { ErrorHelper } from "../../common/error/errorHelper";
14import { InternalErrorCode } from "../../common/error/internalErrorCode";
2c19da7fRedMickey6 years ago15import * as nls from "vscode-nls";
259c018fYuri Skorokhodov5 years ago16import { IOSDirectCDPMessageHandler } from "../../cdp-proxy/CDPMessageHandlers/iOSDirectCDPMessageHandler";
17import { PlatformType } from "../../extension/launchArgs";
18import { IWDPHelper } from "./IWDPHelper";
19
34472878RedMickey5 years ago20nls.config({
21messageFormat: nls.MessageFormat.bundle,
22bundleFormat: nls.BundleFormat.standalone,
23})();
2c19da7fRedMickey6 years ago24const localize = nls.loadMessageBundle();
25
26export class DirectDebugSession extends DebugSessionBase {
984ca036RedMickey6 years ago27private debuggerEndpointHelper: DebuggerEndpointHelper;
ebbd64f1RedMickey6 years ago28private onDidTerminateDebugSessionHandler: vscode.Disposable;
259c018fYuri Skorokhodov5 years ago29private iOSWKDebugProxyHelper: IWDPHelper;
984ca036RedMickey6 years ago30
2c19da7fRedMickey6 years ago31constructor(session: vscode.DebugSession) {
32super(session);
984ca036RedMickey6 years ago33this.debuggerEndpointHelper = new DebuggerEndpointHelper();
259c018fYuri Skorokhodov5 years ago34this.iOSWKDebugProxyHelper = new IWDPHelper();
ebbd64f1RedMickey6 years ago35
36this.onDidTerminateDebugSessionHandler = vscode.debug.onDidTerminateDebugSession(
34472878RedMickey5 years ago37this.handleTerminateDebugSession.bind(this),
ebbd64f1RedMickey6 years ago38);
2c19da7fRedMickey6 years ago39}
40
34472878RedMickey5 years ago41protected async launchRequest(
42response: DebugProtocol.LaunchResponse,
43launchArgs: ILaunchRequestArgs,
44// eslint-disable-next-line @typescript-eslint/no-unused-vars
45request?: DebugProtocol.Request,
46): Promise<void> {
2c19da7fRedMickey6 years ago47let extProps = {
48platform: {
49value: launchArgs.platform,
50isPii: false,
51},
52isDirect: {
53value: true,
54isPii: false,
55},
56};
57
34472878RedMickey5 years ago58return new Promise<void>((resolve, reject) =>
59this.initializeSettings(launchArgs)
60.then(() => {
61logger.log("Launching the application");
62logger.verbose(
63`Launching the application: ${JSON.stringify(launchArgs, null, 2)}`,
64);
341dba36Yuri Skorokhodov5 years ago65
34472878RedMickey5 years ago66return ProjectVersionHelper.getReactNativeVersions(
67launchArgs.cwd,
68ProjectVersionHelper.generateAdditionalPackagesToCheckByPlatform(
69launchArgs,
70),
71);
72})
73.then(versions => {
74extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(
75launchArgs,
76versions,
77extProps,
78);
341dba36Yuri Skorokhodov5 years ago79
34472878RedMickey5 years ago80// eslint-disable-next-line @typescript-eslint/no-unused-vars
81return TelemetryHelper.generate("launch", extProps, generator => {
82return this.appLauncher.launch(launchArgs).then(() => {
5514e287RedMickey6 years ago83if (launchArgs.enableDebug) {
34472878RedMickey5 years ago84launchArgs.port =
85launchArgs.port ||
86this.appLauncher.getPackagerPort(launchArgs.cwd);
87this.attachRequest(response, launchArgs)
88.then(() => {
89resolve();
90})
91.catch(e => reject(e));
5514e287RedMickey6 years ago92} else {
93this.sendResponse(response);
94resolve();
95}
2c19da7fRedMickey6 years ago96});
34472878RedMickey5 years ago97});
98})
99.catch(err => {
100reject(
101ErrorHelper.getInternalError(
102InternalErrorCode.ApplicationLaunchFailed,
103err.message || err,
104),
105);
106}),
107).catch(err => this.showError(err, response));
2c19da7fRedMickey6 years ago108}
109
34472878RedMickey5 years ago110protected async attachRequest(
111response: DebugProtocol.AttachResponse,
112attachArgs: IAttachRequestArgs,
113// eslint-disable-next-line @typescript-eslint/no-unused-vars
114request?: DebugProtocol.Request,
115): Promise<void> {
2c19da7fRedMickey6 years ago116let extProps = {
117platform: {
118value: attachArgs.platform,
119isPii: false,
120},
121isDirect: {
122value: true,
123isPii: false,
124},
125};
126
259c018fYuri Skorokhodov5 years ago127attachArgs.webkitRangeMin = attachArgs.webkitRangeMin || 9223;
128attachArgs.webkitRangeMax = attachArgs.webkitRangeMax || 9322;
129
2c19da7fRedMickey6 years ago130this.previousAttachArgs = attachArgs;
131
34472878RedMickey5 years ago132return new Promise<void>((resolve, reject) =>
133this.initializeSettings(attachArgs)
134.then(() => {
135logger.log("Attaching to the application");
136logger.verbose(
137`Attaching to the application: ${JSON.stringify(attachArgs, null, 2)}`,
138);
139return ProjectVersionHelper.getReactNativeVersions(
140attachArgs.cwd,
141ProjectVersionHelper.generateAdditionalPackagesToCheckByPlatform(
142attachArgs,
143),
144);
145})
146.then(versions => {
147extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(
148attachArgs,
149versions,
150extProps,
151);
152
153// eslint-disable-next-line @typescript-eslint/no-unused-vars
154return TelemetryHelper.generate("attach", extProps, generator => {
155attachArgs.port =
156attachArgs.platform === PlatformType.iOS
157? attachArgs.port || IWDPHelper.iOS_WEBKIT_DEBUG_PROXY_DEFAULT_PORT
158: attachArgs.port ||
159this.appLauncher.getPackagerPort(attachArgs.cwd);
160logger.log(`Connecting to ${attachArgs.port} port`);
161return this.appLauncher
162.getRnCdpProxy()
163.stopServer()
164.then(() =>
165this.appLauncher
166.getRnCdpProxy()
167.initializeServer(
168attachArgs.platform === PlatformType.iOS
169? new IOSDirectCDPMessageHandler()
170: new HermesCDPMessageHandler(),
171this.cdpProxyLogLevel,
172),
173)
174.then(() => {
175if (attachArgs.platform === PlatformType.iOS) {
176return this.iOSWKDebugProxyHelper
177.startiOSWebkitDebugProxy(
178attachArgs.port,
179attachArgs.webkitRangeMin,
180attachArgs.webkitRangeMax,
181)
182.then(() =>
183this.iOSWKDebugProxyHelper.getSimulatorProxyPort(
184attachArgs,
185),
186)
187.then(results => {
188attachArgs.port = results.targetPort;
189});
190} else {
191return Promise.resolve();
192}
193})
194.then(() => this.appLauncher.getPackager().start())
195.then(() =>
196this.debuggerEndpointHelper.retryGetWSEndpoint(
197`http://localhost:${attachArgs.port}`,
19890,
199this.cancellationTokenSource.token,
200),
201)
202.then(browserInspectUri => {
203this.appLauncher
204.getRnCdpProxy()
205.setBrowserInspectUri(browserInspectUri);
206this.establishDebugSession(attachArgs, resolve);
207})
208.catch(e => reject(e));
209});
210})
211.catch(err => {
212reject(
213ErrorHelper.getInternalError(
214InternalErrorCode.CouldNotAttachToDebugger,
215err.message || err,
216),
217);
218}),
219).catch(err => this.showError(err, response));
2c19da7fRedMickey6 years ago220}
221
34472878RedMickey5 years ago222protected async disconnectRequest(
223response: DebugProtocol.DisconnectResponse,
224args: DebugProtocol.DisconnectArguments,
225request?: DebugProtocol.Request,
226): Promise<void> {
259c018fYuri Skorokhodov5 years ago227this.iOSWKDebugProxyHelper.cleanUp();
ebbd64f1RedMickey6 years ago228this.onDidTerminateDebugSessionHandler.dispose();
2c19da7fRedMickey6 years ago229super.disconnectRequest(response, args, request);
230}
231
34472878RedMickey5 years ago232protected establishDebugSession(
233attachArgs: IAttachRequestArgs,
234resolve?: (value?: void | PromiseLike<void> | undefined) => void,
235): void {
1bdccb66RedMickey6 years ago236const attachConfiguration = JsDebugConfigAdapter.createDebuggingConfigForRNHermes(
237attachArgs,
238this.appLauncher.getCdpProxyPort(),
34472878RedMickey5 years ago239this.session.id,
1bdccb66RedMickey6 years ago240);
b7451aefRedMickey6 years ago241
34472878RedMickey5 years ago242vscode.debug
243.startDebugging(this.appLauncher.getWorkspaceFolder(), attachConfiguration, {
ebbd64f1RedMickey6 years ago244parentSession: this.session,
245consoleMode: vscode.DebugConsoleMode.MergeWithParent,
34472878RedMickey5 years ago246})
247.then(
248(childDebugSessionStarted: boolean) => {
249if (childDebugSessionStarted) {
250if (resolve) {
251resolve();
252}
253} else {
254throw new Error(
255localize(
256"CouldNotStartChildDebugSession",
257"Couldn't start child debug session",
258),
259);
259c018fYuri Skorokhodov5 years ago260}
34472878RedMickey5 years ago261},
259c018fYuri Skorokhodov5 years ago262err => {
263throw err;
34472878RedMickey5 years ago264},
265);
b7451aefRedMickey6 years ago266}
ebbd64f1RedMickey6 years ago267
268private handleTerminateDebugSession(debugSession: vscode.DebugSession) {
269if (
34472878RedMickey5 years ago270debugSession.configuration.rnDebugSessionId === this.session.id &&
271debugSession.type === this.pwaNodeSessionName
ebbd64f1RedMickey6 years ago272) {
a2ddbba5RedMickey5 years ago273vscode.commands.executeCommand(this.stopCommand, this.session);
ebbd64f1RedMickey6 years ago274}
275}
2c19da7fRedMickey6 years ago276}