microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
5d47053f3f15910ff32e9fc13144aafdeefe5f72

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debugConfigurationProvider.ts

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