microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
10136ee86a53d80ade52ebf07175f4acbed01d7f

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debugConfigurationProvider.ts

121lines · modeblame

0bfa4e58Yuri Skorokhodov7 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 vscode from "vscode";
5import { TelemetryHelper } from "../common/telemetryHelper";
6import { Telemetry } from "../common/telemetry";
7import * as nls from "vscode-nls";
8const localize = nls.loadMessageBundle();
9
10export class ReactNativeDebugConfigProvider implements vscode.DebugConfigurationProvider {
11private debugConfigurations = {
12"Debug Android": {
13"name": "Debug Android",
18ea7d15Yuri Skorokhodov7 years ago14"cwd": "${workspaceFolder}",
0bfa4e58Yuri Skorokhodov7 years ago15"type": "reactnative",
16"request": "launch",
17"platform": "android",
18},
19"Debug iOS": {
20"name": "Debug iOS",
18ea7d15Yuri Skorokhodov7 years ago21"cwd": "${workspaceFolder}",
0bfa4e58Yuri Skorokhodov7 years ago22"type": "reactnative",
23"request": "launch",
24"platform": "ios",
25},
26"Attach to packager": {
27"name": "Attach to packager",
18ea7d15Yuri Skorokhodov7 years ago28"cwd": "${workspaceFolder}",
0bfa4e58Yuri Skorokhodov7 years ago29"type": "reactnative",
30"request": "attach",
31},
32"Debug in Exponent": {
33"name": "Debug in Exponent",
18ea7d15Yuri Skorokhodov7 years ago34"cwd": "${workspaceFolder}",
0bfa4e58Yuri Skorokhodov7 years ago35"type": "reactnative",
36"request": "launch",
37"platform": "exponent",
38},
549baae2RedMickey6 years ago39"Debug Android (Hermes) - Experimental": {
40"name": "Debug Android (Hermes) - Experimental",
41"cwd": "${workspaceFolder}",
42"type": "reactnativedirect",
43"request": "launch",
44"platform": "android",
45},
8411a7adYuri Skorokhodov6 years ago46"Attach to Hermes application - Experimental": {
47"name": "Attach to Hermes application - Experimental",
549baae2RedMickey6 years ago48"cwd": "${workspaceFolder}",
49"type": "reactnativedirect",
50"request": "attach",
51},
0bfa4e58Yuri Skorokhodov7 years ago52};
53
54private pickConfig: ReadonlyArray<vscode.QuickPickItem> = [
55{
56label: "Debug Android",
57description: localize("DebugAndroidConfigDesc", "Run and debug Android application"),
58},
59{
60label: "Debug iOS",
61description: localize("DebugiOSConfigDesc", "Run and debug iOS application"),
62},
63{
64label: "Attach to packager",
65description: localize("AttachToPackagerConfigDesc", "Attach to already working application packager"),
66},
67{
68label: "Debug in Exponent",
69description: localize("DebugExpoConfigDesc", "Debug Expo application or React Native application in Expo"),
70},
549baae2RedMickey6 years ago71{
72label: "Debug Android (Hermes) - Experimental",
73description: localize("DebugAndroidHermesConfigDesc", "Run and debug Android Hermes application"),
74},
75{
8411a7adYuri Skorokhodov6 years ago76label: "Attach to Hermes application - Experimental",
549baae2RedMickey6 years ago77description: localize("AttachToPackagerHermesConfigDesc", "Attach to already working Android Hermes application packager"),
78},
0bfa4e58Yuri Skorokhodov7 years ago79];
80
81public async provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration[]> {
82return new Promise<vscode.DebugConfiguration[]>((resolve) => {
83const configPicker = this.prepareDebugConfigPicker();
84const disposables: vscode.Disposable[] = [];
85const pickHandler = () => {
74471e03Yuri Skorokhodov7 years ago86let chosenConfigsEvent = TelemetryHelper.createTelemetryEvent("chosenDebugConfigurations");
0bfa4e58Yuri Skorokhodov7 years ago87let selected: string[] = configPicker.selectedItems.map(element => element.label);
74471e03Yuri Skorokhodov7 years ago88chosenConfigsEvent.properties["selectedItems"] = selected;
0bfa4e58Yuri Skorokhodov7 years ago89Telemetry.send(chosenConfigsEvent);
90const launchConfig = this.gatherDebugScenarios(selected);
91disposables.forEach(d => d.dispose());
92resolve(launchConfig);
93};
94
95disposables.push(
96configPicker.onDidAccept(pickHandler),
97configPicker.onDidHide(pickHandler),
98configPicker
99);
100
101configPicker.show();
102});
103}
104
105private gatherDebugScenarios(selectedItems: string[]): vscode.DebugConfiguration[] {
106let launchConfig: vscode.DebugConfiguration[] = selectedItems.map(element => this.debugConfigurations[element]);
107return launchConfig;
108}
109
110private prepareDebugConfigPicker(): vscode.QuickPick<vscode.QuickPickItem> {
111const debugConfigPicker = vscode.window.createQuickPick();
112debugConfigPicker.canSelectMany = true;
113debugConfigPicker.ignoreFocusOut = true;
114debugConfigPicker.title = localize("DebugConfigQuickPickLabel", "Pick debug configurations");
115debugConfigPicker.items = this.pickConfig;
116// QuickPickItem property `picked` doesn't work, so this line will check first item in the list
117// which is supposed to be Debug Android
118debugConfigPicker.selectedItems = [this.pickConfig[0]];
119return debugConfigPicker;
120}
121}