microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
58882bb6b3dda8f9ee5cf6fad0f03021b3cb44a3

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debugConfigurationProvider.ts

219lines · 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";
8import { PlatformType } from "./launchArgs";
9import { IWDPHelper } from "../debugger/direct/IWDPHelper";
10nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
11const localize = nls.loadMessageBundle();
12
13export const DEBUG_TYPES = {
14 REACT_NATIVE: "reactnative",
15 REACT_NATIVE_DIRECT: "reactnativedirect",
16};
17
18export class ReactNativeDebugConfigProvider implements vscode.DebugConfigurationProvider {
19 private debugConfigurations = {
20 "Debug Android": {
21 "name": "Debug Android",
22 "cwd": "${workspaceFolder}",
23 "type": DEBUG_TYPES.REACT_NATIVE,
24 "request": "launch",
25 "platform": PlatformType.Android,
26 },
27 "Run Android": {
28 "name": "Run Android",
29 "cwd": "${workspaceFolder}",
30 "type": DEBUG_TYPES.REACT_NATIVE,
31 "request": "launch",
32 "platform": PlatformType.Android,
33 "enableDebug": false,
34 },
35 "Debug iOS": {
36 "name": "Debug iOS",
37 "cwd": "${workspaceFolder}",
38 "type": DEBUG_TYPES.REACT_NATIVE,
39 "request": "launch",
40 "platform": PlatformType.iOS,
41 },
42 "Run iOS": {
43 "name": "Run iOS",
44 "cwd": "${workspaceFolder}",
45 "type": DEBUG_TYPES.REACT_NATIVE,
46 "request": "launch",
47 "platform": PlatformType.iOS,
48 "enableDebug": false,
49 },
50 "Debug Windows": {
51 "name": "Debug Windows",
52 "cwd": "${workspaceFolder}",
53 "type": DEBUG_TYPES.REACT_NATIVE,
54 "request": "launch",
55 "platform": PlatformType.Windows,
56 },
57 "Debug macOS": {
58 "name": "Debug macOS",
59 "cwd": "${workspaceFolder}",
60 "type": DEBUG_TYPES.REACT_NATIVE,
61 "request": "launch",
62 "platform": PlatformType.macOS,
63 },
64 "Attach to packager": {
65 "name": "Attach to packager",
66 "cwd": "${workspaceFolder}",
67 "type": DEBUG_TYPES.REACT_NATIVE,
68 "request": "attach",
69 },
70 "Debug in Exponent": {
71 "name": "Debug in Exponent",
72 "cwd": "${workspaceFolder}",
73 "type": DEBUG_TYPES.REACT_NATIVE,
74 "request": "launch",
75 "platform": PlatformType.Exponent,
76 },
77 "Debug Android Hermes - Experimental": {
78 "name": "Debug Android Hermes - Experimental",
79 "cwd": "${workspaceFolder}",
80 "type": DEBUG_TYPES.REACT_NATIVE_DIRECT,
81 "request": "launch",
82 "platform": PlatformType.Android,
83 },
84 "Run Android Hermes - Experimental": {
85 "name": "Run Android Hermes - Experimental",
86 "cwd": "${workspaceFolder}",
87 "type": DEBUG_TYPES.REACT_NATIVE_DIRECT,
88 "request": "launch",
89 "platform": PlatformType.Android,
90 "enableDebug": false,
91 },
92 "Attach to the React Native Hermes - Experimental": {
93 "name": "Attach to the React Native Hermes - Experimental",
94 "cwd": "${workspaceFolder}",
95 "type": DEBUG_TYPES.REACT_NATIVE_DIRECT,
96 "request": "attach",
97 },
98 "Attach to the React Native iOS - Experimental": {
99 "name": "Attach to the React Native iOS - Experimental",
100 "cwd": "${workspaceFolder}",
101 "type": DEBUG_TYPES.REACT_NATIVE_DIRECT,
102 "request": "attach",
103 "platform": PlatformType.iOS,
104 "port": IWDPHelper.iOS_WEBKIT_DEBUG_PROXY_DEFAULT_PORT // 9221
105 },
106 "Debug Direct iOS - Experimental": {
107 "name": "Debug Direct iOS - Experimental",
108 "cwd": "${workspaceFolder}",
109 "type": DEBUG_TYPES.REACT_NATIVE_DIRECT,
110 "request": "launch",
111 "platform": PlatformType.iOS,
112 "port": IWDPHelper.iOS_WEBKIT_DEBUG_PROXY_DEFAULT_PORT // 9221
113 },
114 "Run Direct iOS - Experimental": {
115 "name": "Run Direct iOS - Experimental",
116 "cwd": "${workspaceFolder}",
117 "type": DEBUG_TYPES.REACT_NATIVE_DIRECT,
118 "request": "launch",
119 "platform": PlatformType.iOS,
120 "enableDebug": false,
121 }
122 };
123
124 private pickConfig: ReadonlyArray<vscode.QuickPickItem> = [
125 {
126 label: "Debug Android",
127 description: localize("DebugAndroidConfigDesc", "Run and debug Android application"),
128 },
129 {
130 label: "Run Android",
131 description: localize("RunAndroidConfigDesc", "Run Android application"),
132 },
133 {
134 label: "Debug iOS",
135 description: localize("DebugiOSConfigDesc", "Run and debug iOS application"),
136 },
137 {
138 label: "Run iOS",
139 description: localize("RuniOSConfigDesc", "Run iOS application"),
140 },
141 {
142 label: "Debug Windows",
143 description: localize("DebugWindowsConfigDesc", "Run and debug Windows application"),
144 },
145 {
146 label: "Debug macOS",
147 description: localize("DebugmacOSConfigDesc", "Run and debug macOS application"),
148 },
149 {
150 label: "Attach to packager",
151 description: localize("AttachToPackagerConfigDesc", "Attach to already working application packager"),
152 },
153 {
154 label: "Debug in Exponent",
155 description: localize("DebugExpoConfigDesc", "Debug Expo application or React Native application in Expo"),
156 },
157 {
158 label: "Debug Android Hermes - Experimental",
159 description: localize("DebugAndroidHermesConfigDesc", "Run and debug Android Hermes application"),
160 },
161 {
162 label: "Attach to the React Native Hermes - Experimental",
163 description: localize("AttachToPackagerHermesConfigDesc", "Attach to already working React Native Hermes application on Android directly"),
164 },
165 {
166 label: "Attach to the React Native iOS - Experimental",
167 description: localize("AttachToPackageriOSConfigDesc", "Attach to already working React Native iOS application directly"),
168 },
169 {
170 label: "Debug Direct iOS - Experimental",
171 description: localize("DebugDirectiOSConfigDesc", "Run and debug iOS application directly"),
172 },
173 {
174 label: "Run Direct iOS - Experimental",
175 description: localize("RunDirectiOSConfigDesc", "Run iOS application with direct debugging support"),
176 },
177 ];
178
179 public async provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration[]> {
180 return new Promise<vscode.DebugConfiguration[]>((resolve) => {
181 const configPicker = this.prepareDebugConfigPicker();
182 const disposables: vscode.Disposable[] = [];
183 const pickHandler = () => {
184 let chosenConfigsEvent = TelemetryHelper.createTelemetryEvent("chosenDebugConfigurations");
185 let selected: string[] = configPicker.selectedItems.map(element => element.label);
186 chosenConfigsEvent.properties["selectedItems"] = selected;
187 Telemetry.send(chosenConfigsEvent);
188 const launchConfig = this.gatherDebugScenarios(selected);
189 disposables.forEach(d => d.dispose());
190 resolve(launchConfig);
191 };
192
193 disposables.push(
194 configPicker.onDidAccept(pickHandler),
195 configPicker.onDidHide(pickHandler),
196 configPicker
197 );
198
199 configPicker.show();
200 });
201 }
202
203 private gatherDebugScenarios(selectedItems: string[]): vscode.DebugConfiguration[] {
204 let launchConfig: vscode.DebugConfiguration[] = selectedItems.map(element => this.debugConfigurations[element]);
205 return launchConfig;
206 }
207
208 private prepareDebugConfigPicker(): vscode.QuickPick<vscode.QuickPickItem> {
209 const debugConfigPicker = vscode.window.createQuickPick();
210 debugConfigPicker.canSelectMany = true;
211 debugConfigPicker.ignoreFocusOut = true;
212 debugConfigPicker.title = localize("DebugConfigQuickPickLabel", "Pick debug configurations");
213 debugConfigPicker.items = this.pickConfig;
214 // QuickPickItem property `picked` doesn't work, so this line will check first item in the list
215 // which is supposed to be Debug Android
216 debugConfigPicker.selectedItems = [this.pickConfig[0]];
217 return debugConfigPicker;
218 }
219}
220