microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
4f8669f9862e5f7db84d8d4f84b7c0d2006d7bb6

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debugConfigurationProvider.ts

138lines · 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 * as vscode from "vscode";
5import { TelemetryHelper } from "../common/telemetryHelper";
6import { Telemetry } from "../common/telemetry";
7import * as nls from "vscode-nls";
8nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
9const localize = nls.loadMessageBundle();
10
11export const DEBUG_TYPES = {
12 REACT_NATIVE: "reactnative-preview",
13 REACT_NATIVE_DIRECT: "reactnativedirect-preview",
14};
15
16export class ReactNativeDebugConfigProvider implements vscode.DebugConfigurationProvider {
17 private debugConfigurations = {
18 "Debug Android (Preview)": {
19 "name": "Debug Android (Preview)",
20 "cwd": "${workspaceFolder}",
21 "type": DEBUG_TYPES.REACT_NATIVE,
22 "request": "launch",
23 "platform": "android",
24 },
25 "Debug iOS (Preview)": {
26 "name": "Debug iOS (Preview)",
27 "cwd": "${workspaceFolder}",
28 "type": DEBUG_TYPES.REACT_NATIVE,
29 "request": "launch",
30 "platform": "ios",
31 },
32 "Debug Windows (Preview)": {
33 "name": "Debug Windows (Preview)",
34 "cwd": "${workspaceFolder}",
35 "type": DEBUG_TYPES.REACT_NATIVE,
36 "request": "launch",
37 "platform": "windows",
38 },
39 "Attach to packager (Preview)": {
40 "name": "Attach to packager (Preview)",
41 "cwd": "${workspaceFolder}",
42 "type": DEBUG_TYPES.REACT_NATIVE,
43 "request": "attach",
44 },
45 "Debug in Exponent (Preview)": {
46 "name": "Debug in Exponent (Preview)",
47 "cwd": "${workspaceFolder}",
48 "type": DEBUG_TYPES.REACT_NATIVE,
49 "request": "launch",
50 "platform": "exponent",
51 },
52 "Debug Android Hermes (Preview) - Experimental": {
53 "name": "Debug Android Hermes (Preview) - Experimental",
54 "cwd": "${workspaceFolder}",
55 "type": DEBUG_TYPES.REACT_NATIVE_DIRECT,
56 "request": "launch",
57 "platform": "android",
58 },
59 "Attach to Hermes application (Preview) - Experimental": {
60 "name": "Attach to Hermes application (Preview) - Experimental",
61 "cwd": "${workspaceFolder}",
62 "type": DEBUG_TYPES.REACT_NATIVE_DIRECT,
63 "request": "attach",
64 },
65 };
66
67 private pickConfig: ReadonlyArray<vscode.QuickPickItem> = [
68 {
69 label: "Debug Android (Preview)",
70 description: localize("DebugAndroidConfigDesc", "Run and debug Android application"),
71 },
72 {
73 label: "Debug iOS (Preview)",
74 description: localize("DebugiOSConfigDesc", "Run and debug iOS application"),
75 },
76 {
77 label: "Debug Windows (Preview)",
78 description: localize("DebugWindowsConfigDesc", "Run and debug Windows application"),
79 },
80 {
81 label: "Attach to packager (Preview)",
82 description: localize("AttachToPackagerConfigDesc", "Attach to already working application packager"),
83 },
84 {
85 label: "Debug in Exponent (Preview)",
86 description: localize("DebugExpoConfigDesc", "Debug Expo application or React Native application in Expo"),
87 },
88 {
89 label: "Debug Android Hermes (Preview) - Experimental",
90 description: localize("DebugAndroidHermesConfigDesc", "Run and debug Android Hermes application"),
91 },
92 {
93 label: "Attach to Hermes application (Preview) - Experimental",
94 description: localize("AttachToPackagerHermesConfigDesc", "Attach to already working Android Hermes application packager"),
95 },
96 ];
97
98 public async provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration[]> {
99 return new Promise<vscode.DebugConfiguration[]>((resolve) => {
100 const configPicker = this.prepareDebugConfigPicker();
101 const disposables: vscode.Disposable[] = [];
102 const pickHandler = () => {
103 let chosenConfigsEvent = TelemetryHelper.createTelemetryEvent("chosenDebugConfigurations");
104 let selected: string[] = configPicker.selectedItems.map(element => element.label);
105 chosenConfigsEvent.properties["selectedItems"] = selected;
106 Telemetry.send(chosenConfigsEvent);
107 const launchConfig = this.gatherDebugScenarios(selected);
108 disposables.forEach(d => d.dispose());
109 resolve(launchConfig);
110 };
111
112 disposables.push(
113 configPicker.onDidAccept(pickHandler),
114 configPicker.onDidHide(pickHandler),
115 configPicker
116 );
117
118 configPicker.show();
119 });
120 }
121
122 private gatherDebugScenarios(selectedItems: string[]): vscode.DebugConfiguration[] {
123 let launchConfig: vscode.DebugConfiguration[] = selectedItems.map(element => this.debugConfigurations[element]);
124 return launchConfig;
125 }
126
127 private prepareDebugConfigPicker(): vscode.QuickPick<vscode.QuickPickItem> {
128 const debugConfigPicker = vscode.window.createQuickPick();
129 debugConfigPicker.canSelectMany = true;
130 debugConfigPicker.ignoreFocusOut = true;
131 debugConfigPicker.title = localize("DebugConfigQuickPickLabel", "Pick debug configurations");
132 debugConfigPicker.items = this.pickConfig;
133 // QuickPickItem property `picked` doesn't work, so this line will check first item in the list
134 // which is supposed to be Debug Android
135 debugConfigPicker.selectedItems = [this.pickConfig[0]];
136 return debugConfigPicker;
137 }
138}
139