microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
a3bcb94dbaa8181be0dc2a9e42b1767209a75139

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/reactNativeDebugConfigProvider.ts

333lines · 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";
5471436aRedMickey5 years ago5import { TelemetryHelper } from "../../common/telemetryHelper";
6import { Telemetry } from "../../common/telemetry";
7import { PlatformType } from "../launchArgs";
8import { IWDPHelper } from "../../debugger/direct/IWDPHelper";
9import { DebugScenarioNameGenerator } from "./debugScenarioNameGenerator";
10import { ILaunchRequestArgs } from "../../debugger/debugSessionBase";
11import {
12DEBUG_TYPES,
13DebugScenarioType,
14DebugConfigurationQuickPickItem,
15DebugConfigurationState,
16} from "./debugConfigTypesAndConstants";
17import { MultiStepInput, IMultiStepInput, InputStep, IQuickPickParameters } from "./multiStepInput";
18import { ConfigProviderFactory } from "./configurationProviders/configProviderFactory";
0bfa4e58Yuri Skorokhodov7 years ago19import * as nls from "vscode-nls";
34472878RedMickey5 years ago20nls.config({
21messageFormat: nls.MessageFormat.bundle,
22bundleFormat: nls.BundleFormat.standalone,
23})();
0bfa4e58Yuri Skorokhodov7 years ago24const localize = nls.loadMessageBundle();
25
26export class ReactNativeDebugConfigProvider implements vscode.DebugConfigurationProvider {
27private debugConfigurations = {
d55f3c22Yuri Skorokhodov5 years ago28"Debug Android": {
34472878RedMickey5 years ago29name: "Debug Android",
30cwd: "${workspaceFolder}",
31type: DEBUG_TYPES.REACT_NATIVE,
32request: "launch",
33platform: PlatformType.Android,
0bfa4e58Yuri Skorokhodov7 years ago34},
d55f3c22Yuri Skorokhodov5 years ago35"Run Android": {
34472878RedMickey5 years ago36name: "Run Android",
37cwd: "${workspaceFolder}",
38type: DEBUG_TYPES.REACT_NATIVE,
39request: "launch",
40platform: PlatformType.Android,
41enableDebug: false,
5514e287RedMickey6 years ago42},
d55f3c22Yuri Skorokhodov5 years ago43"Debug iOS": {
34472878RedMickey5 years ago44name: "Debug iOS",
45cwd: "${workspaceFolder}",
46type: DEBUG_TYPES.REACT_NATIVE,
47request: "launch",
48platform: PlatformType.iOS,
0bfa4e58Yuri Skorokhodov7 years ago49},
d55f3c22Yuri Skorokhodov5 years ago50"Run iOS": {
34472878RedMickey5 years ago51name: "Run iOS",
52cwd: "${workspaceFolder}",
53type: DEBUG_TYPES.REACT_NATIVE,
54request: "launch",
55platform: PlatformType.iOS,
56enableDebug: false,
5514e287RedMickey6 years ago57},
d55f3c22Yuri Skorokhodov5 years ago58"Debug Windows": {
34472878RedMickey5 years ago59name: "Debug Windows",
60cwd: "${workspaceFolder}",
61type: DEBUG_TYPES.REACT_NATIVE,
62request: "launch",
63platform: PlatformType.Windows,
36e9730fDavid Serafimov6 years ago64},
341dba36Yuri Skorokhodov5 years ago65"Debug macOS": {
34472878RedMickey5 years ago66name: "Debug macOS",
67cwd: "${workspaceFolder}",
68type: DEBUG_TYPES.REACT_NATIVE,
69request: "launch",
70platform: PlatformType.macOS,
341dba36Yuri Skorokhodov5 years ago71},
d55f3c22Yuri Skorokhodov5 years ago72"Attach to packager": {
34472878RedMickey5 years ago73name: "Attach to packager",
74cwd: "${workspaceFolder}",
75type: DEBUG_TYPES.REACT_NATIVE,
76request: "attach",
0bfa4e58Yuri Skorokhodov7 years ago77},
d55f3c22Yuri Skorokhodov5 years ago78"Debug in Exponent": {
34472878RedMickey5 years ago79name: "Debug in Exponent",
80cwd: "${workspaceFolder}",
81type: DEBUG_TYPES.REACT_NATIVE,
82request: "launch",
83platform: PlatformType.Exponent,
0bfa4e58Yuri Skorokhodov7 years ago84},
d55f3c22Yuri Skorokhodov5 years ago85"Debug Android Hermes - Experimental": {
34472878RedMickey5 years ago86name: "Debug Android Hermes - Experimental",
87cwd: "${workspaceFolder}",
88type: DEBUG_TYPES.REACT_NATIVE_DIRECT,
89request: "launch",
90platform: PlatformType.Android,
549baae2RedMickey6 years ago91},
d55f3c22Yuri Skorokhodov5 years ago92"Run Android Hermes - Experimental": {
34472878RedMickey5 years ago93name: "Run Android Hermes - Experimental",
94cwd: "${workspaceFolder}",
95type: DEBUG_TYPES.REACT_NATIVE_DIRECT,
96request: "launch",
97platform: PlatformType.Android,
98enableDebug: false,
5514e287RedMickey6 years ago99},
259c018fYuri Skorokhodov5 years ago100"Attach to the React Native Hermes - Experimental": {
34472878RedMickey5 years ago101name: "Attach to the React Native Hermes - Experimental",
102cwd: "${workspaceFolder}",
103type: DEBUG_TYPES.REACT_NATIVE_DIRECT,
104request: "attach",
549baae2RedMickey6 years ago105},
259c018fYuri Skorokhodov5 years ago106"Attach to the React Native iOS - Experimental": {
34472878RedMickey5 years ago107name: "Attach to the React Native iOS - Experimental",
108cwd: "${workspaceFolder}",
109type: DEBUG_TYPES.REACT_NATIVE_DIRECT,
110request: "attach",
111platform: PlatformType.iOS,
112port: IWDPHelper.iOS_WEBKIT_DEBUG_PROXY_DEFAULT_PORT, // 9221
259c018fYuri Skorokhodov5 years ago113},
d55f3c22Yuri Skorokhodov5 years ago114"Debug Direct iOS - Experimental": {
34472878RedMickey5 years ago115name: "Debug Direct iOS - Experimental",
116cwd: "${workspaceFolder}",
117type: DEBUG_TYPES.REACT_NATIVE_DIRECT,
118request: "launch",
119platform: PlatformType.iOS,
120port: IWDPHelper.iOS_WEBKIT_DEBUG_PROXY_DEFAULT_PORT, // 9221
259c018fYuri Skorokhodov5 years ago121},
d55f3c22Yuri Skorokhodov5 years ago122"Run Direct iOS - Experimental": {
34472878RedMickey5 years ago123name: "Run Direct iOS - Experimental",
124cwd: "${workspaceFolder}",
125type: DEBUG_TYPES.REACT_NATIVE_DIRECT,
126request: "launch",
127platform: PlatformType.iOS,
128enableDebug: false,
129},
0bfa4e58Yuri Skorokhodov7 years ago130};
131
5471436aRedMickey5 years ago132private initialPickConfig: ReadonlyArray<vscode.QuickPickItem> = [
0bfa4e58Yuri Skorokhodov7 years ago133{
d55f3c22Yuri Skorokhodov5 years ago134label: "Debug Android",
0bfa4e58Yuri Skorokhodov7 years ago135description: localize("DebugAndroidConfigDesc", "Run and debug Android application"),
136},
5514e287RedMickey6 years ago137{
d55f3c22Yuri Skorokhodov5 years ago138label: "Run Android",
5514e287RedMickey6 years ago139description: localize("RunAndroidConfigDesc", "Run Android application"),
140},
0bfa4e58Yuri Skorokhodov7 years ago141{
d55f3c22Yuri Skorokhodov5 years ago142label: "Debug iOS",
0bfa4e58Yuri Skorokhodov7 years ago143description: localize("DebugiOSConfigDesc", "Run and debug iOS application"),
144},
5514e287RedMickey6 years ago145{
d55f3c22Yuri Skorokhodov5 years ago146label: "Run iOS",
5514e287RedMickey6 years ago147description: localize("RuniOSConfigDesc", "Run iOS application"),
148},
36e9730fDavid Serafimov6 years ago149{
d55f3c22Yuri Skorokhodov5 years ago150label: "Debug Windows",
36e9730fDavid Serafimov6 years ago151description: localize("DebugWindowsConfigDesc", "Run and debug Windows application"),
152},
341dba36Yuri Skorokhodov5 years ago153{
154label: "Debug macOS",
155description: localize("DebugmacOSConfigDesc", "Run and debug macOS application"),
156},
0bfa4e58Yuri Skorokhodov7 years ago157{
d55f3c22Yuri Skorokhodov5 years ago158label: "Attach to packager",
34472878RedMickey5 years ago159description: localize(
160"AttachToPackagerConfigDesc",
161"Attach to already working application packager",
162),
0bfa4e58Yuri Skorokhodov7 years ago163},
164{
d55f3c22Yuri Skorokhodov5 years ago165label: "Debug in Exponent",
34472878RedMickey5 years ago166description: localize(
167"DebugExpoConfigDesc",
168"Debug Expo application or React Native application in Expo",
169),
0bfa4e58Yuri Skorokhodov7 years ago170},
549baae2RedMickey6 years ago171{
d55f3c22Yuri Skorokhodov5 years ago172label: "Debug Android Hermes - Experimental",
34472878RedMickey5 years ago173description: localize(
174"DebugAndroidHermesConfigDesc",
175"Run and debug Android Hermes application",
176),
549baae2RedMickey6 years ago177},
178{
259c018fYuri Skorokhodov5 years ago179label: "Attach to the React Native Hermes - Experimental",
34472878RedMickey5 years ago180description: localize(
181"AttachToPackagerHermesConfigDesc",
182"Attach to already working React Native Hermes application on Android directly",
183),
259c018fYuri Skorokhodov5 years ago184},
185{
186label: "Attach to the React Native iOS - Experimental",
34472878RedMickey5 years ago187description: localize(
188"AttachToPackageriOSConfigDesc",
189"Attach to already working React Native iOS application directly",
190),
259c018fYuri Skorokhodov5 years ago191},
192{
d55f3c22Yuri Skorokhodov5 years ago193label: "Debug Direct iOS - Experimental",
34472878RedMickey5 years ago194description: localize(
195"DebugDirectiOSConfigDesc",
196"Run and debug iOS application directly",
197),
259c018fYuri Skorokhodov5 years ago198},
199{
d55f3c22Yuri Skorokhodov5 years ago200label: "Run Direct iOS - Experimental",
34472878RedMickey5 years ago201description: localize(
202"RunDirectiOSConfigDesc",
203"Run iOS application with direct debugging support",
204),
549baae2RedMickey6 years ago205},
0bfa4e58Yuri Skorokhodov7 years ago206];
207
5471436aRedMickey5 years ago208private sequentialPickConfig: ReadonlyArray<DebugConfigurationQuickPickItem> = [
209{
210label: "Run application",
211description: localize(
212"RunApplicationScenario",
213"Run React Native application without debugging",
214),
215type: DebugScenarioType.RunApp,
216},
217{
218label: "Debug application",
219description: localize("DebugApplicationScenario", "Debug React Native application"),
220type: DebugScenarioType.DebugApp,
221},
222{
223label: "Attach to application",
224description: localize(
225"AttachApplicationScenario",
226"Attach to running React Native application",
227),
228type: DebugScenarioType.AttachApp,
229},
230];
231
34472878RedMickey5 years ago232public async provideDebugConfigurations(
233folder: vscode.WorkspaceFolder | undefined, // eslint-disable-line @typescript-eslint/no-unused-vars
234token?: vscode.CancellationToken, // eslint-disable-line @typescript-eslint/no-unused-vars
235): Promise<vscode.DebugConfiguration[]> {
236return new Promise<vscode.DebugConfiguration[]>(resolve => {
0bfa4e58Yuri Skorokhodov7 years ago237const configPicker = this.prepareDebugConfigPicker();
238const disposables: vscode.Disposable[] = [];
239const pickHandler = () => {
34472878RedMickey5 years ago240let chosenConfigsEvent = TelemetryHelper.createTelemetryEvent(
241"chosenDebugConfigurations",
242);
0bfa4e58Yuri Skorokhodov7 years ago243let selected: string[] = configPicker.selectedItems.map(element => element.label);
74471e03Yuri Skorokhodov7 years ago244chosenConfigsEvent.properties["selectedItems"] = selected;
0bfa4e58Yuri Skorokhodov7 years ago245Telemetry.send(chosenConfigsEvent);
246const launchConfig = this.gatherDebugScenarios(selected);
247disposables.forEach(d => d.dispose());
248resolve(launchConfig);
249};
250
251disposables.push(
252configPicker.onDidAccept(pickHandler),
253configPicker.onDidHide(pickHandler),
34472878RedMickey5 years ago254configPicker,
0bfa4e58Yuri Skorokhodov7 years ago255);
256
257configPicker.show();
258});
259}
260
5471436aRedMickey5 years ago261public async provideDebugConfigurationSequentially(
262folder: vscode.WorkspaceFolder | undefined,
263token?: vscode.CancellationToken,
264): Promise<vscode.DebugConfiguration | undefined> {
265const config: Partial<ILaunchRequestArgs> = {};
266const state = { config, scenarioType: DebugScenarioType.DebugApp, folder, token };
267
268const multiStep = new MultiStepInput<DebugConfigurationState>();
269await multiStep.run((input, s) => this.pickDebugConfiguration(input, s), state);
270
271if (Object.keys(state.config).length === 0) {
272return;
273} else {
274if (state.config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT) {
275state.config.name = DebugScenarioNameGenerator.createScenarioName(
276state.scenarioType,
277state.config.type,
278state.config.platform,
279true,
280);
281} else {
282state.config.name = DebugScenarioNameGenerator.createScenarioName(
283state.scenarioType,
284state.config.type || DEBUG_TYPES.REACT_NATIVE,
285state.config.platform,
286);
287}
288return state.config as vscode.DebugConfiguration;
289}
290}
291
292private async pickDebugConfiguration(
293input: IMultiStepInput<DebugConfigurationState>,
294state: DebugConfigurationState,
295): Promise<InputStep<DebugConfigurationState> | void> {
296state.config = {};
297const pick = await input.showQuickPick<
298DebugConfigurationQuickPickItem,
299IQuickPickParameters<DebugConfigurationQuickPickItem>
300>({
301title: localize("DebugConfigQuickPickSequentialLabel", "Select a debug configuration"),
302placeholder: "Debug Configuration",
303activeItem: this.sequentialPickConfig[0],
304items: this.sequentialPickConfig,
305});
306if (pick) {
307const provider = ConfigProviderFactory.create(pick.type);
308return provider.buildConfiguration.bind(provider);
309}
310}
311
0bfa4e58Yuri Skorokhodov7 years ago312private gatherDebugScenarios(selectedItems: string[]): vscode.DebugConfiguration[] {
34472878RedMickey5 years ago313let launchConfig: vscode.DebugConfiguration[] = selectedItems.map(
314element => this.debugConfigurations[element],
315);
0bfa4e58Yuri Skorokhodov7 years ago316return launchConfig;
317}
318
319private prepareDebugConfigPicker(): vscode.QuickPick<vscode.QuickPickItem> {
320const debugConfigPicker = vscode.window.createQuickPick();
321debugConfigPicker.canSelectMany = true;
322debugConfigPicker.ignoreFocusOut = true;
34472878RedMickey5 years ago323debugConfigPicker.title = localize(
324"DebugConfigQuickPickLabel",
325"Pick debug configurations",
326);
5471436aRedMickey5 years ago327debugConfigPicker.items = this.initialPickConfig;
0bfa4e58Yuri Skorokhodov7 years ago328// QuickPickItem property `picked` doesn't work, so this line will check first item in the list
329// which is supposed to be Debug Android
5471436aRedMickey5 years ago330debugConfigPicker.selectedItems = [this.initialPickConfig[0]];
0bfa4e58Yuri Skorokhodov7 years ago331return debugConfigPicker;
332}
333}