microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
70cfd5650973cc6872aaae01ea2db7a924e6b67b

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/direct/reactNativeDirectDebugEntryPoint.ts

63lines · 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 { TelemetryHelper } from "../../common/telemetryHelper";
5import { EntryPointHandler, ProcessType } from "../../common/entryPointHandler";
6import { getExtensionVersion } from "../../common/extensionHelper";
7import { ErrorHelper } from "../../common/error/errorHelper";
8import { InternalErrorCode } from "../../common/error/internalErrorCode";
9import { NullTelemetryReporter, ReassignableTelemetryReporter } from "../../common/telemetryReporters";
10import { DirectDebugAdapter } from "./directDebugAdapter";
11import { makeDirectSession } from "./directSessionWrapper";
12import { ChromeDebugSession } from "vscode-chrome-debug-core";
13import { DebugSession, OutputEvent, TerminatedEvent } from "vscode-debugadapter";
14import * as nls from "vscode-nls";
15const localize = nls.loadMessageBundle();
16
17const version = getExtensionVersion();
18const extensionName = "react-native-tools";
19const telemetryReporter = new ReassignableTelemetryReporter(new NullTelemetryReporter());
20
21function bailOut(reason: string): void {
22 // Things have gone wrong in initialization: Report the error to telemetry and exit
23 TelemetryHelper.sendDirect(reason);
24 process.exit(1);
25}
26
27function codeToRun() {
28 try {
29
30 let session: typeof ChromeDebugSession;
31
32 try {
33 session = makeDirectSession({
34 adapter: DirectDebugAdapter,
35 extensionName: extensionName },
36 telemetryReporter);
37
38 ChromeDebugSession.run(session);
39 } catch (e) {
40 const debugSession = new DebugSession();
41 // Start session before sending any events otherwise the client wouldn't receive them
42 debugSession.start(process.stdin, process.stdout);
43 debugSession.sendEvent(new OutputEvent(localize("UnableToStartDebugAdapter", "Unable to start debug adapter: {0}", e.toString()), "stderr"));
44 debugSession.sendEvent(new TerminatedEvent());
45 bailOut(e.toString());
46 }
47 } catch (e) {
48 // Nothing we can do here: can't even communicate back because we don't know how to speak debug adapter
49 bailOut("cannotFindDebugAdapter");
50 }
51
52}
53
54// Enable telemetry
55const entryPointHandler = new EntryPointHandler(ProcessType.Debugger);
56entryPointHandler.runApp(
57 extensionName,
58 version,
59 ErrorHelper.getInternalError(InternalErrorCode.DebuggingFailed),
60 telemetryReporter,
61 codeToRun
62);
63
64