microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2c19da7f131d11b4265a94fe25139194a565116e

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/direct/directDebugSession.ts

143lines · 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 * as vscode from "vscode";
5import { ProjectVersionHelper } from "../../common/projectVersionHelper";
6import {logger } from "vscode-debugadapter";
7import { TelemetryHelper } from "../../common/telemetryHelper";
8import { DebugProtocol } from "vscode-debugprotocol";
9import { DirectCDPMessageHandler } from "../../cdp-proxy/CDPMessageHandlers/directCDPMessageHandler";
10import { DebugSessionBase, IAttachRequestArgs, ILaunchRequestArgs } from "../debugSessionBase";
11import * as nls from "vscode-nls";
12const localize = nls.loadMessageBundle();
13
14export class DirectDebugSession extends DebugSessionBase {
15
16 /**
17 * @description The Hermes native functions calls mark in call stack
18 * @type {string}
19 */
20 // private static HERMES_NATIVE_FUNCTION_NAME: string = "(native)";
21
22 /**
23 * @description Equals to 0xfffffff - the scriptId returned by Hermes debugger, that means "invalid script ID"
24 * @type {string}
25 */
26 // private static HERMES_NATIVE_FUNCTION_SCRIPT_ID: string = "4294967295";
27
28 constructor(session: vscode.DebugSession) {
29 super(session);
30 }
31
32 protected launchRequest(response: DebugProtocol.LaunchResponse, launchArgs: ILaunchRequestArgs, request?: DebugProtocol.Request): Promise<void> {
33 let extProps = {
34 platform: {
35 value: launchArgs.platform,
36 isPii: false,
37 },
38 isDirect: {
39 value: true,
40 isPii: false,
41 },
42 };
43
44 return new Promise<void>((resolve, reject) => this.initializeSettings(launchArgs)
45 .then(() => {
46 logger.log("Launching the application");
47 logger.verbose(`Launching the application: ${JSON.stringify(launchArgs, null , 2)}`);
48 return ProjectVersionHelper.getReactNativeVersions(launchArgs.cwd, launchArgs.platform === "windows")
49 .then(versions => {
50 extProps = TelemetryHelper.addPropertyToTelemetryProperties(versions.reactNativeVersion, "reactNativeVersion", extProps);
51 if (launchArgs.platform === "windows") {
52 extProps = TelemetryHelper.addPropertyToTelemetryProperties(versions.reactNativeWindowsVersion, "reactNativeWindowsVersion", extProps);
53 }
54 return TelemetryHelper.generate("launch", extProps, (generator) => {
55 return this.appLauncher.launch(launchArgs)
56 .then(() => {
57 return this.appLauncher.getPackagerPort(launchArgs.cwd);
58 })
59 .then((packagerPort: number) => {
60 launchArgs.port = launchArgs.port || packagerPort;
61 this.attachRequest(response, launchArgs).then(() => {
62 resolve();
63 }).catch((e) => reject(e));
64 }).catch((e) => reject(e));
65 })
66 .catch((err) => {
67 logger.error("An error occurred while launching the application. " + err.message || err);
68 reject(err);
69 });
70 });
71 }));
72 }
73
74 protected attachRequest(response: DebugProtocol.AttachResponse, attachArgs: IAttachRequestArgs, request?: DebugProtocol.Request): Promise<void> {
75 let extProps = {
76 platform: {
77 value: attachArgs.platform,
78 isPii: false,
79 },
80 isDirect: {
81 value: true,
82 isPii: false,
83 },
84 };
85
86 this.previousAttachArgs = attachArgs;
87
88 return new Promise<void>((resolve, reject) => this.initializeSettings(attachArgs)
89 .then(() => {
90 logger.log("Attaching to the application");
91 logger.verbose(`Attaching to the application: ${JSON.stringify(attachArgs, null , 2)}`);
92 return ProjectVersionHelper.getReactNativeVersions(attachArgs.cwd, true)
93 .then(versions => {
94 extProps = TelemetryHelper.addPropertyToTelemetryProperties(versions.reactNativeVersion, "reactNativeVersion", extProps);
95 if (!ProjectVersionHelper.isVersionError(versions.reactNativeWindowsVersion)) {
96 extProps = TelemetryHelper.addPropertyToTelemetryProperties(versions.reactNativeWindowsVersion, "reactNativeWindowsVersion", extProps);
97 }
98 return TelemetryHelper.generate("attach", extProps, (generator) => {
99 attachArgs.port = attachArgs.port || this.appLauncher.getPackagerPort(attachArgs.cwd);
100 this.appLauncher.getRnCdpProxy().stopServer();
101 logger.log(`Connecting to ${attachArgs.port} port`);
102 return this.appLauncher.getRnCdpProxy().initializeServer(new DirectCDPMessageHandler(), this.cdpProxyLogLevel)
103 .then(() => {
104 resolve();
105 });
106 })
107 .catch((err) => {
108 logger.error("An error occurred while attaching to the debugger. " + err.message || err);
109 reject(err);
110 });
111 });
112 }));
113 }
114
115 protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments, request?: DebugProtocol.Request): void {
116 // The client is about to disconnect so first we need to stop app worker
117 if (this.appWorker) {
118 this.appWorker.stop();
119 }
120
121 this.appLauncher.getRnCdpProxy().stopServer();
122
123 if (this.previousAttachArgs.platform === "android") {
124 try {
125 this.appLauncher.stopMonitoringLogCat();
126 } catch (err) {
127 logger.warn(localize("CouldNotStopMonitoringLogcat", "Couldn't stop monitoring logcat: {0}", err.message || err));
128 }
129 }
130
131 super.disconnectRequest(response, args, request);
132 }
133
134 /*protected async onPaused(notification: Crdp.Debugger.PausedEvent, expectingStopReason = this._expectingStopReason): Promise<IOnPausedResult> {
135 // Excluding Hermes native function calls from call stack, since VS Code can't process them properly
136 // More info: https://github.com/facebook/hermes/issues/168
137 notification.callFrames = notification.callFrames.filter(callFrame =>
138 callFrame.functionName !== DirectDebugAdapter.HERMES_NATIVE_FUNCTION_NAME &&
139 callFrame.location.scriptId !== DirectDebugAdapter.HERMES_NATIVE_FUNCTION_SCRIPT_ID
140 );
141 return super.onPaused(notification, expectingStopReason);
142 }*/
143}
144