microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.12.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/reactNativeDebugConfigProvider.ts

297lines · 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";
09f6024fHeniker4 years ago5import * as nls from "vscode-nls";
5471436aRedMickey5 years ago6import { TelemetryHelper } from "../../common/telemetryHelper";
7import { Telemetry } from "../../common/telemetry";
8import { ILaunchRequestArgs } from "../../debugger/debugSessionBase";
9f8c460dEzio Li2 years ago9import { PlatformType } from "../launchArgs";
5471436aRedMickey5 years ago10import {
09f6024fHeniker4 years ago11debugConfigurations,
12DEBUG_CONFIGURATION_NAMES,
5471436aRedMickey5 years ago13DEBUG_TYPES,
14DebugScenarioType,
15DebugConfigurationQuickPickItem,
16DebugConfigurationState,
17} from "./debugConfigTypesAndConstants";
09f6024fHeniker4 years ago18import { DebugScenarioNameGenerator } from "./debugScenarioNameGenerator";
19
5471436aRedMickey5 years ago20import { MultiStepInput, IMultiStepInput, InputStep, IQuickPickParameters } from "./multiStepInput";
21import { ConfigProviderFactory } from "./configurationProviders/configProviderFactory";
09f6024fHeniker4 years ago22
34472878RedMickey5 years ago23nls.config({
24messageFormat: nls.MessageFormat.bundle,
25bundleFormat: nls.BundleFormat.standalone,
26})();
0bfa4e58Yuri Skorokhodov7 years ago27const localize = nls.loadMessageBundle();
28
29export class ReactNativeDebugConfigProvider implements vscode.DebugConfigurationProvider {
5471436aRedMickey5 years ago30private initialPickConfig: ReadonlyArray<vscode.QuickPickItem> = [
0bfa4e58Yuri Skorokhodov7 years ago31{
e7a2c40dRedMickey4 years ago32label: DEBUG_CONFIGURATION_NAMES.DEBUG_ANDROID,
0bfa4e58Yuri Skorokhodov7 years ago33description: localize("DebugAndroidConfigDesc", "Run and debug Android application"),
34},
5514e287RedMickey6 years ago35{
e7a2c40dRedMickey4 years ago36label: DEBUG_CONFIGURATION_NAMES.RUN_ANDROID,
5514e287RedMickey6 years ago37description: localize("RunAndroidConfigDesc", "Run Android application"),
38},
0bfa4e58Yuri Skorokhodov7 years ago39{
e7a2c40dRedMickey4 years ago40label: DEBUG_CONFIGURATION_NAMES.DEBUG_IOS,
0bfa4e58Yuri Skorokhodov7 years ago41description: localize("DebugiOSConfigDesc", "Run and debug iOS application"),
42},
5514e287RedMickey6 years ago43{
e7a2c40dRedMickey4 years ago44label: DEBUG_CONFIGURATION_NAMES.RUN_IOS,
5514e287RedMickey6 years ago45description: localize("RuniOSConfigDesc", "Run iOS application"),
46},
36e9730fDavid Serafimov6 years ago47{
e7a2c40dRedMickey4 years ago48label: DEBUG_CONFIGURATION_NAMES.DEBUG_WINDOWS,
36e9730fDavid Serafimov6 years ago49description: localize("DebugWindowsConfigDesc", "Run and debug Windows application"),
50},
341dba36Yuri Skorokhodov5 years ago51{
e7a2c40dRedMickey4 years ago52label: DEBUG_CONFIGURATION_NAMES.DEBUG_MACOS,
341dba36Yuri Skorokhodov5 years ago53description: localize("DebugmacOSConfigDesc", "Run and debug macOS application"),
54},
0bfa4e58Yuri Skorokhodov7 years ago55{
e7a2c40dRedMickey4 years ago56label: DEBUG_CONFIGURATION_NAMES.ATTACH_TO_PACKAGER,
34472878RedMickey5 years ago57description: localize(
58"AttachToPackagerConfigDesc",
59"Attach to already working application packager",
60),
0bfa4e58Yuri Skorokhodov7 years ago61},
62{
e7a2c40dRedMickey4 years ago63label: DEBUG_CONFIGURATION_NAMES.DEBUG_IN_EXPONENT,
34472878RedMickey5 years ago64description: localize(
65"DebugExpoConfigDesc",
66"Debug Expo application or React Native application in Expo",
67),
0bfa4e58Yuri Skorokhodov7 years ago68},
0b86204dEzio Li3 years ago69{
70label: DEBUG_CONFIGURATION_NAMES.DEBUG_IN_EXPONENT_HERMES_EXPERIMENTAL,
71description: localize(
72"DebugHermesExpoConfigDesc",
73"Debug Hermes Expo application or React Native application in Expo",
74),
75},
9f8c460dEzio Li2 years ago76{
77label: DEBUG_CONFIGURATION_NAMES.DEBUG_IN_EXPONENT_WEB_EXPERIMENTAL,
78description: localize(
79"DebugExpoWebConfigDesc",
80"Debug Hermes Expo application on web browser",
81),
82},
549baae2RedMickey6 years ago83{
c6ca8545Ezio Li3 years ago84label: DEBUG_CONFIGURATION_NAMES.DEBUG_ANDROID_HERMES,
34472878RedMickey5 years ago85description: localize(
86"DebugAndroidHermesConfigDesc",
87"Run and debug Android Hermes application",
88),
549baae2RedMickey6 years ago89},
90{
c6ca8545Ezio Li3 years ago91label: DEBUG_CONFIGURATION_NAMES.RUN_ANDROID_HERMES,
6f9a0779JiglioNero5 years ago92description: localize("RunAndroidHermesConfigDesc", "Run Android Hermes application"),
93},
94{
c6ca8545Ezio Li3 years ago95label: DEBUG_CONFIGURATION_NAMES.DEBUG_IOS_HERMES,
34472878RedMickey5 years ago96description: localize(
6f9a0779JiglioNero5 years ago97"DebugIosHermesConfigDesc",
98"Run and debug iOS Hermes application",
34472878RedMickey5 years ago99),
259c018fYuri Skorokhodov5 years ago100},
101{
c6ca8545Ezio Li3 years ago102label: DEBUG_CONFIGURATION_NAMES.RUN_IOS_HERMES,
6f9a0779JiglioNero5 years ago103description: localize("RunIosHermesConfigDesc", "Run iOS Hermes application"),
104},
5c9b8eb8RedMickey5 years ago105{
e7a2c40dRedMickey4 years ago106label: DEBUG_CONFIGURATION_NAMES.DEBUG_MACOS_HERMES_EXPERIMENTAL,
5c9b8eb8RedMickey5 years ago107description: localize(
108"DebugMacOSHermesConfigDesc",
109"Run and debug macOS Hermes application",
110),
111},
008d88e5RedMickey4 years ago112{
e7a2c40dRedMickey4 years ago113label: DEBUG_CONFIGURATION_NAMES.DEBUG_WINDOWS_HERMES_EXPERIMENTAL,
008d88e5RedMickey4 years ago114description: localize(
115"DebugWindowsHermesConfigDesc",
116"Run and debug Windows Hermes application",
117),
118},
6f9a0779JiglioNero5 years ago119{
c6ca8545Ezio Li3 years ago120label: DEBUG_CONFIGURATION_NAMES.ATTACH_TO_HERMES_APPLICATION,
34472878RedMickey5 years ago121description: localize(
6f9a0779JiglioNero5 years ago122"AttachToPackagerHermesConfigDesc",
123"Attach to already working React Native Hermes application on Android directly",
34472878RedMickey5 years ago124),
259c018fYuri Skorokhodov5 years ago125},
126{
e7a2c40dRedMickey4 years ago127label: DEBUG_CONFIGURATION_NAMES.DEBUG_DIRECT_IOS_EXPERIMENTAL,
34472878RedMickey5 years ago128description: localize(
129"DebugDirectiOSConfigDesc",
130"Run and debug iOS application directly",
131),
259c018fYuri Skorokhodov5 years ago132},
133{
e7a2c40dRedMickey4 years ago134label: DEBUG_CONFIGURATION_NAMES.RUN_DIRECT_IOS_EXPERIMENTAL,
34472878RedMickey5 years ago135description: localize(
136"RunDirectiOSConfigDesc",
137"Run iOS application with direct debugging support",
138),
549baae2RedMickey6 years ago139},
6f9a0779JiglioNero5 years ago140{
e7a2c40dRedMickey4 years ago141label: DEBUG_CONFIGURATION_NAMES.ATTACH_TO_DIRECT_IOS_EXPERIMENTAL,
6f9a0779JiglioNero5 years ago142description: localize(
143"AttachToPackageriOSConfigDesc",
144"Attach to already working React Native iOS application directly",
145),
146},
0bfa4e58Yuri Skorokhodov7 years ago147];
148
5471436aRedMickey5 years ago149private sequentialPickConfig: ReadonlyArray<DebugConfigurationQuickPickItem> = [
150{
151label: "Run application",
152description: localize(
153"RunApplicationScenario",
154"Run React Native application without debugging",
155),
156type: DebugScenarioType.RunApp,
157},
158{
159label: "Debug application",
160description: localize("DebugApplicationScenario", "Debug React Native application"),
161type: DebugScenarioType.DebugApp,
162},
163{
164label: "Attach to application",
165description: localize(
166"AttachApplicationScenario",
167"Attach to running React Native application",
168),
169type: DebugScenarioType.AttachApp,
170},
171];
172
34472878RedMickey5 years ago173public async provideDebugConfigurations(
174folder: vscode.WorkspaceFolder | undefined, // eslint-disable-line @typescript-eslint/no-unused-vars
175token?: vscode.CancellationToken, // eslint-disable-line @typescript-eslint/no-unused-vars
176): Promise<vscode.DebugConfiguration[]> {
177return new Promise<vscode.DebugConfiguration[]>(resolve => {
0bfa4e58Yuri Skorokhodov7 years ago178const configPicker = this.prepareDebugConfigPicker();
179const disposables: vscode.Disposable[] = [];
180const pickHandler = () => {
09f6024fHeniker4 years ago181const chosenConfigsEvent = TelemetryHelper.createTelemetryEvent(
34472878RedMickey5 years ago182"chosenDebugConfigurations",
183);
09f6024fHeniker4 years ago184const selected: string[] = configPicker.selectedItems.map(element => element.label);
185chosenConfigsEvent.properties.selectedItems = selected;
0bfa4e58Yuri Skorokhodov7 years ago186Telemetry.send(chosenConfigsEvent);
187const launchConfig = this.gatherDebugScenarios(selected);
188disposables.forEach(d => d.dispose());
189resolve(launchConfig);
190};
191
192disposables.push(
193configPicker.onDidAccept(pickHandler),
194configPicker.onDidHide(pickHandler),
34472878RedMickey5 years ago195configPicker,
0bfa4e58Yuri Skorokhodov7 years ago196);
197
198configPicker.show();
199});
200}
201
5471436aRedMickey5 years ago202public async provideDebugConfigurationSequentially(
203folder: vscode.WorkspaceFolder | undefined,
204token?: vscode.CancellationToken,
205): Promise<vscode.DebugConfiguration | undefined> {
206const config: Partial<ILaunchRequestArgs> = {};
207const state = { config, scenarioType: DebugScenarioType.DebugApp, folder, token };
208
209const multiStep = new MultiStepInput<DebugConfigurationState>();
210await multiStep.run((input, s) => this.pickDebugConfiguration(input, s), state);
211
212if (Object.keys(state.config).length === 0) {
213return;
09f6024fHeniker4 years ago214}
9f8c460dEzio Li2 years ago215if (state.config.platform !== PlatformType.ExpoWeb) {
216if (state.config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT) {
217if (
218state.config.platform === "android" ||
219(state.config.platform === "ios" &&
220state.config.target !== "device" &&
221state.config.request !== "attach")
222) {
223state.config.name = DebugScenarioNameGenerator.createScenarioName(
224state.scenarioType,
225state.config.type,
226state.config.platform,
227state.config.useHermesEngine !== false,
228);
229} else {
230state.config.name = DebugScenarioNameGenerator.createScenarioName(
231state.scenarioType,
232state.config.type,
233state.config.platform,
234state.config.useHermesEngine !== false,
235true,
236);
237}
c6ca8545Ezio Li3 years ago238} else {
239state.config.name = DebugScenarioNameGenerator.createScenarioName(
240state.scenarioType,
9f8c460dEzio Li2 years ago241state.config.type || DEBUG_TYPES.REACT_NATIVE,
c6ca8545Ezio Li3 years ago242state.config.platform,
243);
244}
5471436aRedMickey5 years ago245} else {
09f6024fHeniker4 years ago246state.config.name = DebugScenarioNameGenerator.createScenarioName(
247state.scenarioType,
248state.config.type || DEBUG_TYPES.REACT_NATIVE,
249state.config.platform,
250);
5471436aRedMickey5 years ago251}
9f8c460dEzio Li2 years ago252
09f6024fHeniker4 years ago253return state.config as vscode.DebugConfiguration;
5471436aRedMickey5 years ago254}
255
256private async pickDebugConfiguration(
257input: IMultiStepInput<DebugConfigurationState>,
258state: DebugConfigurationState,
259): Promise<InputStep<DebugConfigurationState> | void> {
260state.config = {};
261const pick = await input.showQuickPick<
262DebugConfigurationQuickPickItem,
263IQuickPickParameters<DebugConfigurationQuickPickItem>
264>({
265title: localize("DebugConfigQuickPickSequentialLabel", "Select a debug configuration"),
266placeholder: "Debug Configuration",
267activeItem: this.sequentialPickConfig[0],
268items: this.sequentialPickConfig,
269});
270if (pick) {
271const provider = ConfigProviderFactory.create(pick.type);
272return provider.buildConfiguration.bind(provider);
273}
274}
275
0bfa4e58Yuri Skorokhodov7 years ago276private gatherDebugScenarios(selectedItems: string[]): vscode.DebugConfiguration[] {
09f6024fHeniker4 years ago277const launchConfig: vscode.DebugConfiguration[] = selectedItems.map(
e7a2c40dRedMickey4 years ago278element => debugConfigurations[element],
34472878RedMickey5 years ago279);
0bfa4e58Yuri Skorokhodov7 years ago280return launchConfig;
281}
282
283private prepareDebugConfigPicker(): vscode.QuickPick<vscode.QuickPickItem> {
284const debugConfigPicker = vscode.window.createQuickPick();
285debugConfigPicker.canSelectMany = true;
286debugConfigPicker.ignoreFocusOut = true;
34472878RedMickey5 years ago287debugConfigPicker.title = localize(
288"DebugConfigQuickPickLabel",
289"Pick debug configurations",
290);
5471436aRedMickey5 years ago291debugConfigPicker.items = this.initialPickConfig;
0bfa4e58Yuri Skorokhodov7 years ago292// QuickPickItem property `picked` doesn't work, so this line will check first item in the list
293// which is supposed to be Debug Android
5471436aRedMickey5 years ago294debugConfigPicker.selectedItems = [this.initialPickConfig[0]];
0bfa4e58Yuri Skorokhodov7 years ago295return debugConfigPicker;
296}
297}