microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.1.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debugConfigurationProvider.ts

219lines · 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";
259c018fYuri Skorokhodov5 years ago8import { PlatformType } from "./launchArgs";
9import { IWDPHelper } from "../debugger/direct/IWDPHelper";
2d8af448Yuri Skorokhodov6 years ago10nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
0bfa4e58Yuri Skorokhodov7 years ago11const localize = nls.loadMessageBundle();
12
ebbd64f1RedMickey6 years ago13export const DEBUG_TYPES = {
d55f3c22Yuri Skorokhodov5 years ago14REACT_NATIVE: "reactnative",
15REACT_NATIVE_DIRECT: "reactnativedirect",
ebbd64f1RedMickey6 years ago16};
17
0bfa4e58Yuri Skorokhodov7 years ago18export class ReactNativeDebugConfigProvider implements vscode.DebugConfigurationProvider {
19private debugConfigurations = {
d55f3c22Yuri Skorokhodov5 years ago20"Debug Android": {
21"name": "Debug Android",
18ea7d15Yuri Skorokhodov7 years ago22"cwd": "${workspaceFolder}",
ebbd64f1RedMickey6 years ago23"type": DEBUG_TYPES.REACT_NATIVE,
0bfa4e58Yuri Skorokhodov7 years ago24"request": "launch",
259c018fYuri Skorokhodov5 years ago25"platform": PlatformType.Android,
0bfa4e58Yuri Skorokhodov7 years ago26},
d55f3c22Yuri Skorokhodov5 years ago27"Run Android": {
28"name": "Run Android",
5514e287RedMickey6 years ago29"cwd": "${workspaceFolder}",
30"type": DEBUG_TYPES.REACT_NATIVE,
31"request": "launch",
259c018fYuri Skorokhodov5 years ago32"platform": PlatformType.Android,
5514e287RedMickey6 years ago33"enableDebug": false,
34},
d55f3c22Yuri Skorokhodov5 years ago35"Debug iOS": {
36"name": "Debug iOS",
18ea7d15Yuri Skorokhodov7 years ago37"cwd": "${workspaceFolder}",
ebbd64f1RedMickey6 years ago38"type": DEBUG_TYPES.REACT_NATIVE,
0bfa4e58Yuri Skorokhodov7 years ago39"request": "launch",
259c018fYuri Skorokhodov5 years ago40"platform": PlatformType.iOS,
0bfa4e58Yuri Skorokhodov7 years ago41},
d55f3c22Yuri Skorokhodov5 years ago42"Run iOS": {
43"name": "Run iOS",
5514e287RedMickey6 years ago44"cwd": "${workspaceFolder}",
45"type": DEBUG_TYPES.REACT_NATIVE,
46"request": "launch",
259c018fYuri Skorokhodov5 years ago47"platform": PlatformType.iOS,
5514e287RedMickey6 years ago48"enableDebug": false,
49},
d55f3c22Yuri Skorokhodov5 years ago50"Debug Windows": {
51"name": "Debug Windows",
36e9730fDavid Serafimov6 years ago52"cwd": "${workspaceFolder}",
ebbd64f1RedMickey6 years ago53"type": DEBUG_TYPES.REACT_NATIVE,
36e9730fDavid Serafimov6 years ago54"request": "launch",
259c018fYuri Skorokhodov5 years ago55"platform": PlatformType.Windows,
36e9730fDavid Serafimov6 years ago56},
341dba36Yuri Skorokhodov5 years ago57"Debug macOS": {
58"name": "Debug macOS",
59"cwd": "${workspaceFolder}",
60"type": DEBUG_TYPES.REACT_NATIVE,
61"request": "launch",
62"platform": PlatformType.macOS,
63},
d55f3c22Yuri Skorokhodov5 years ago64"Attach to packager": {
65"name": "Attach to packager",
18ea7d15Yuri Skorokhodov7 years ago66"cwd": "${workspaceFolder}",
ebbd64f1RedMickey6 years ago67"type": DEBUG_TYPES.REACT_NATIVE,
0bfa4e58Yuri Skorokhodov7 years ago68"request": "attach",
69},
d55f3c22Yuri Skorokhodov5 years ago70"Debug in Exponent": {
71"name": "Debug in Exponent",
18ea7d15Yuri Skorokhodov7 years ago72"cwd": "${workspaceFolder}",
ebbd64f1RedMickey6 years ago73"type": DEBUG_TYPES.REACT_NATIVE,
0bfa4e58Yuri Skorokhodov7 years ago74"request": "launch",
259c018fYuri Skorokhodov5 years ago75"platform": PlatformType.Exponent,
0bfa4e58Yuri Skorokhodov7 years ago76},
d55f3c22Yuri Skorokhodov5 years ago77"Debug Android Hermes - Experimental": {
78"name": "Debug Android Hermes - Experimental",
549baae2RedMickey6 years ago79"cwd": "${workspaceFolder}",
ebbd64f1RedMickey6 years ago80"type": DEBUG_TYPES.REACT_NATIVE_DIRECT,
549baae2RedMickey6 years ago81"request": "launch",
259c018fYuri Skorokhodov5 years ago82"platform": PlatformType.Android,
549baae2RedMickey6 years ago83},
d55f3c22Yuri Skorokhodov5 years ago84"Run Android Hermes - Experimental": {
85"name": "Run Android Hermes - Experimental",
5514e287RedMickey6 years ago86"cwd": "${workspaceFolder}",
87"type": DEBUG_TYPES.REACT_NATIVE_DIRECT,
88"request": "launch",
259c018fYuri Skorokhodov5 years ago89"platform": PlatformType.Android,
5514e287RedMickey6 years ago90"enableDebug": false,
91},
259c018fYuri Skorokhodov5 years ago92"Attach to the React Native Hermes - Experimental": {
93"name": "Attach to the React Native Hermes - Experimental",
549baae2RedMickey6 years ago94"cwd": "${workspaceFolder}",
ebbd64f1RedMickey6 years ago95"type": DEBUG_TYPES.REACT_NATIVE_DIRECT,
549baae2RedMickey6 years ago96"request": "attach",
97},
259c018fYuri Skorokhodov5 years ago98"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},
d55f3c22Yuri Skorokhodov5 years ago106"Debug Direct iOS - Experimental": {
107"name": "Debug Direct iOS - Experimental",
259c018fYuri Skorokhodov5 years ago108"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},
d55f3c22Yuri Skorokhodov5 years ago114"Run Direct iOS - Experimental": {
115"name": "Run Direct iOS - Experimental",
259c018fYuri Skorokhodov5 years ago116"cwd": "${workspaceFolder}",
117"type": DEBUG_TYPES.REACT_NATIVE_DIRECT,
118"request": "launch",
119"platform": PlatformType.iOS,
120"enableDebug": false,
121}
0bfa4e58Yuri Skorokhodov7 years ago122};
123
124private pickConfig: ReadonlyArray<vscode.QuickPickItem> = [
125{
d55f3c22Yuri Skorokhodov5 years ago126label: "Debug Android",
0bfa4e58Yuri Skorokhodov7 years ago127description: localize("DebugAndroidConfigDesc", "Run and debug Android application"),
128},
5514e287RedMickey6 years ago129{
d55f3c22Yuri Skorokhodov5 years ago130label: "Run Android",
5514e287RedMickey6 years ago131description: localize("RunAndroidConfigDesc", "Run Android application"),
132},
0bfa4e58Yuri Skorokhodov7 years ago133{
d55f3c22Yuri Skorokhodov5 years ago134label: "Debug iOS",
0bfa4e58Yuri Skorokhodov7 years ago135description: localize("DebugiOSConfigDesc", "Run and debug iOS application"),
136},
5514e287RedMickey6 years ago137{
d55f3c22Yuri Skorokhodov5 years ago138label: "Run iOS",
5514e287RedMickey6 years ago139description: localize("RuniOSConfigDesc", "Run iOS application"),
140},
36e9730fDavid Serafimov6 years ago141{
d55f3c22Yuri Skorokhodov5 years ago142label: "Debug Windows",
36e9730fDavid Serafimov6 years ago143description: localize("DebugWindowsConfigDesc", "Run and debug Windows application"),
144},
341dba36Yuri Skorokhodov5 years ago145{
146label: "Debug macOS",
147description: localize("DebugmacOSConfigDesc", "Run and debug macOS application"),
148},
0bfa4e58Yuri Skorokhodov7 years ago149{
d55f3c22Yuri Skorokhodov5 years ago150label: "Attach to packager",
0bfa4e58Yuri Skorokhodov7 years ago151description: localize("AttachToPackagerConfigDesc", "Attach to already working application packager"),
152},
153{
d55f3c22Yuri Skorokhodov5 years ago154label: "Debug in Exponent",
0bfa4e58Yuri Skorokhodov7 years ago155description: localize("DebugExpoConfigDesc", "Debug Expo application or React Native application in Expo"),
156},
549baae2RedMickey6 years ago157{
d55f3c22Yuri Skorokhodov5 years ago158label: "Debug Android Hermes - Experimental",
549baae2RedMickey6 years ago159description: localize("DebugAndroidHermesConfigDesc", "Run and debug Android Hermes application"),
160},
161{
259c018fYuri Skorokhodov5 years ago162label: "Attach to the React Native Hermes - Experimental",
163description: localize("AttachToPackagerHermesConfigDesc", "Attach to already working React Native Hermes application on Android directly"),
164},
165{
166label: "Attach to the React Native iOS - Experimental",
167description: localize("AttachToPackageriOSConfigDesc", "Attach to already working React Native iOS application directly"),
168},
169{
d55f3c22Yuri Skorokhodov5 years ago170label: "Debug Direct iOS - Experimental",
259c018fYuri Skorokhodov5 years ago171description: localize("DebugDirectiOSConfigDesc", "Run and debug iOS application directly"),
172},
173{
d55f3c22Yuri Skorokhodov5 years ago174label: "Run Direct iOS - Experimental",
259c018fYuri Skorokhodov5 years ago175description: localize("RunDirectiOSConfigDesc", "Run iOS application with direct debugging support"),
549baae2RedMickey6 years ago176},
0bfa4e58Yuri Skorokhodov7 years ago177];
178
179public async provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration[]> {
180return new Promise<vscode.DebugConfiguration[]>((resolve) => {
181const configPicker = this.prepareDebugConfigPicker();
182const disposables: vscode.Disposable[] = [];
183const pickHandler = () => {
74471e03Yuri Skorokhodov7 years ago184let chosenConfigsEvent = TelemetryHelper.createTelemetryEvent("chosenDebugConfigurations");
0bfa4e58Yuri Skorokhodov7 years ago185let selected: string[] = configPicker.selectedItems.map(element => element.label);
74471e03Yuri Skorokhodov7 years ago186chosenConfigsEvent.properties["selectedItems"] = selected;
0bfa4e58Yuri Skorokhodov7 years ago187Telemetry.send(chosenConfigsEvent);
188const launchConfig = this.gatherDebugScenarios(selected);
189disposables.forEach(d => d.dispose());
190resolve(launchConfig);
191};
192
193disposables.push(
194configPicker.onDidAccept(pickHandler),
195configPicker.onDidHide(pickHandler),
196configPicker
197);
198
199configPicker.show();
200});
201}
202
203private gatherDebugScenarios(selectedItems: string[]): vscode.DebugConfiguration[] {
204let launchConfig: vscode.DebugConfiguration[] = selectedItems.map(element => this.debugConfigurations[element]);
205return launchConfig;
206}
207
208private prepareDebugConfigPicker(): vscode.QuickPick<vscode.QuickPickItem> {
209const debugConfigPicker = vscode.window.createQuickPick();
210debugConfigPicker.canSelectMany = true;
211debugConfigPicker.ignoreFocusOut = true;
212debugConfigPicker.title = localize("DebugConfigQuickPickLabel", "Pick debug configurations");
213debugConfigPicker.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
216debugConfigPicker.selectedItems = [this.pickConfig[0]];
217return debugConfigPicker;
218}
219}