microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
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 | |
| 4 | import { TelemetryHelper } from "../../common/telemetryHelper"; |
| 5 | import { EntryPointHandler, ProcessType } from "../../common/entryPointHandler"; |
| 6 | import { getExtensionVersion } from "../../common/extensionHelper"; |
| 7 | import { ErrorHelper } from "../../common/error/errorHelper"; |
| 8 | import { InternalErrorCode } from "../../common/error/internalErrorCode"; |
| 9 | import { NullTelemetryReporter, ReassignableTelemetryReporter } from "../../common/telemetryReporters"; |
| 10 | import { DirectDebugAdapter } from "./directDebugAdapter"; |
| 11 | import { makeDirectSession } from "./directSessionWrapper"; |
| 12 | import { ChromeDebugSession } from "vscode-chrome-debug-core"; |
| 13 | import { DebugSession, OutputEvent, TerminatedEvent } from "vscode-debugadapter"; |
| 14 | import * as nls from "vscode-nls"; |
| 15 | const localize = nls.loadMessageBundle(); |
| 16 | |
| 17 | const version = getExtensionVersion(); |
| 18 | const extensionName = "react-native-tools"; |
| 19 | const telemetryReporter = new ReassignableTelemetryReporter(new NullTelemetryReporter()); |
| 20 | |
| 21 | function 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 | |
| 27 | function 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 |
| 55 | const entryPointHandler = new EntryPointHandler(ProcessType.Debugger); |
| 56 | entryPointHandler.runApp( |
| 57 | extensionName, |
| 58 | version, |
| 59 | ErrorHelper.getInternalError(InternalErrorCode.DebuggingFailed), |
| 60 | telemetryReporter, |
| 61 | codeToRun |
| 62 | ); |
| 63 | |
| 64 | |