microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
4aec730e44bfea8933accd82b72fab4853eadbd0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debugConfigurationProvider.ts

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