microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
c036b0d343245c82886cd5906e37ff50b8b30d34

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/cdp-proxy/CDPMessageHandlers/rnCDPMessageHandler.ts

58lines · 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 { IProtocolCommand } from "vscode-cdp-proxy";
5import { ICDPMessageHandler, ProcessedCDPMessage } from "./ICDPMessageHandler";
6import { CDP_API_NAMES } from "./CDPAPINames";
7
8export class RnCDPMessageHandler implements ICDPMessageHandler {
9 private firstStop: boolean;
10
11 constructor() {
12 this.firstStop = true;
13 }
14
15 public processDebuggerCDPMessage(event: any): ProcessedCDPMessage {
16 let sendBack = false;
17 if (event.method === CDP_API_NAMES.CLOSE) {
18 this.handleDebuggerDisconnect();
19 }
20
21 return {
22 event,
23 sendBack,
24 };
25 }
26
27 public processApplicationCDPMessage(event: any): ProcessedCDPMessage {
28 let sendBack = false;
29 if (event.method === CDP_API_NAMES.DEBUGGER_PAUSED && this.firstStop) {
30 event.params = this.handleAppBundleFirstPauseEvent(event);
31 }
32
33 return {
34 event,
35 sendBack,
36 };
37 }
38
39 /** Since the bundle runs inside the Node.js VM in `debuggerWorker.js` in runtime
40 * Node debug adapter need time to parse new added code source maps
41 * So we added `debugger;` statement at the start of the bundle code
42 * and wait for the adapter to receive a signal to stop on that statement
43 * and then change pause reason to `Break on start` so js-debug can process all breakpoints in the bundle and
44 * continue the code execution using `continueOnAttach` flag
45 */
46 private handleAppBundleFirstPauseEvent(event: IProtocolCommand): any {
47 let params: any = event.params;
48 if (params.reason && params.reason === "other") {
49 this.firstStop = false;
50 params.reason = "Break on start";
51 }
52 return params;
53 }
54
55 private handleDebuggerDisconnect() {
56 this.firstStop = true;
57 }
58}
59