microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
cf911877212a8e04adfa526f170bcaeb217a1c6b

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/reactNativeDebugEntryPoint.ts

87lines · modeblame

40e4b177Patricio Beltran10 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 fs from "fs";
5import * as path from "path";
6
b8999098Dmitry Zinovyev9 years ago7import { TelemetryHelper } from "../common/telemetryHelper";
8import { EntryPointHandler, ProcessType } from "../common/entryPointHandler";
9import { ErrorHelper } from "../common/error/errorHelper";
10import { InternalErrorCode } from "../common/error/internalErrorCode";
11import { NullTelemetryReporter, ReassignableTelemetryReporter } from "../common/telemetryReporters";
e45838cbVladimir Kotikov9 years ago12import { makeAdapter, makeSession } from "./nodeDebugWrapper";
40e4b177Patricio Beltran10 years ago13
0a68f8dbArtem Egorov8 years ago14import { ChromeDebugSession, ChromeDebugAdapter } from "vscode-chrome-debug-core";
15import { DebugSession, OutputEvent, TerminatedEvent } from "vscode-debugadapter";
16
40e4b177Patricio Beltran10 years ago17const version = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "..", "package.json"), "utf-8")).version;
18const telemetryReporter = new ReassignableTelemetryReporter(new NullTelemetryReporter());
51a4641cArtem Egorov7 years ago19const extensionName = "react-native-tools";
d124bf0eYuri Skorokhodov7 years ago20import * as nls from "vscode-nls";
21const localize = nls.loadMessageBundle();
40e4b177Patricio Beltran10 years ago22
23function bailOut(reason: string): void {
24// Things have gone wrong in initialization: Report the error to telemetry and exit
25TelemetryHelper.sendSimpleEvent(reason);
26process.exit(1);
27}
28
b8999098Dmitry Zinovyev9 years ago29function codeToRun() {
30
31/**
32* For debugging React Native we basically want to debug node plus some other stuff.
33* There is no need to create a new adapter for node because ther already exists one.
34* We look for node debug adapter on client's computer so we can jump of on top of that.
35*/
36let nodeDebugFolder: string;
0a68f8dbArtem Egorov8 years ago37let Node2DebugAdapter: typeof ChromeDebugAdapter;
40e4b177Patricio Beltran10 years ago38
b8999098Dmitry Zinovyev9 years ago39// nodeDebugLocation.json is dynamically generated on extension activation.
40// If it fails, we must not have been in a react native project
41try {
42/* tslint:disable:no-var-requires */
43nodeDebugFolder = require("./nodeDebugLocation.json").nodeDebugPath;
44Node2DebugAdapter = require(path.join(nodeDebugFolder, "out/src/nodeDebugAdapter")).NodeDebugAdapter;
45/* tslint:enable:no-var-requires */
40e4b177Patricio Beltran10 years ago46
5c8365a6Artem Egorov8 years ago47/**
48* We did find chrome debugger package and node2 debug adapter. Lets create debug
49* session and adapter with our customizations.
50*/
0a68f8dbArtem Egorov8 years ago51let session: typeof ChromeDebugSession;
52let adapter: typeof ChromeDebugAdapter;
40e4b177Patricio Beltran10 years ago53
5c8365a6Artem Egorov8 years ago54try {
55/* Create customised react-native debug adapter based on Node-debug2 adapter */
56adapter = makeAdapter(Node2DebugAdapter);
57// Create a debug session class based on ChromeDebugSession
0a68f8dbArtem Egorov8 years ago58session = makeSession(ChromeDebugSession,
59{ adapter, extensionName }, telemetryReporter, extensionName, version);
5c8365a6Artem Egorov8 years ago60
61// Run the debug session for the node debug adapter with our modified requests
0a68f8dbArtem Egorov8 years ago62ChromeDebugSession.run(session);
5c8365a6Artem Egorov8 years ago63} catch (e) {
0a68f8dbArtem Egorov8 years ago64const debugSession = new DebugSession();
5c8365a6Artem Egorov8 years ago65// Start session before sending any events otherwise the client wouldn't receive them
66debugSession.start(process.stdin, process.stdout);
d124bf0eYuri Skorokhodov7 years ago67debugSession.sendEvent(new OutputEvent(localize("UnableToStartDebugAdapter", "Unable to start debug adapter: {0}", e.toString()), "stderr"));
0a68f8dbArtem Egorov8 years ago68debugSession.sendEvent(new TerminatedEvent());
5c8365a6Artem Egorov8 years ago69bailOut(e.toString());
70}
b8999098Dmitry Zinovyev9 years ago71} catch (e) {
5c8365a6Artem Egorov8 years ago72// Nothing we can do here: can't even communicate back because we don't know how to speak debug adapter
73bailOut("cannotFindDebugAdapter");
b8999098Dmitry Zinovyev9 years ago74}
40e4b177Patricio Beltran10 years ago75
b8999098Dmitry Zinovyev9 years ago76}
40e4b177Patricio Beltran10 years ago77
b8999098Dmitry Zinovyev9 years ago78// Enable telemetry
79const entryPointHandler = new EntryPointHandler(ProcessType.Debugger);
80entryPointHandler.runApp(
c9c3d133Artem Egorov8 years ago81extensionName,
2e432a9eArtem Egorov8 years ago82version,
b8999098Dmitry Zinovyev9 years ago83ErrorHelper.getInternalError(InternalErrorCode.DebuggingFailed),
84telemetryReporter,
85codeToRun
86);
e45838cbVladimir Kotikov9 years ago87