microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
transitive-dependency-serialize-javascript

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/reactNativeDebugConfigProvider.ts

305lines · 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{
8363a9dcEzio Li11 months ago70label: DEBUG_CONFIGURATION_NAMES.DEBUG_IN_EXPONENT_HERMES,
0b86204dEzio Li3 years ago71description: localize(
72"DebugHermesExpoConfigDesc",
73"Debug Hermes Expo application or React Native application in Expo",
74),
75},
9f8c460dEzio Li2 years ago76{
8363a9dcEzio Li11 months ago77label: DEBUG_CONFIGURATION_NAMES.DEBUG_IN_EXPONENT_WEB,
9f8c460dEzio Li2 years ago78description: 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{
8363a9dcEzio Li11 months ago106label: DEBUG_CONFIGURATION_NAMES.DEBUG_MACOS_HERMES,
5c9b8eb8RedMickey5 years ago107description: localize(
108"DebugMacOSHermesConfigDesc",
109"Run and debug macOS Hermes application",
110),
111},
008d88e5RedMickey4 years ago112{
8363a9dcEzio Li11 months ago113label: DEBUG_CONFIGURATION_NAMES.DEBUG_WINDOWS_HERMES,
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);
7a4506dclexie0111 years ago229} else if (state.config.platform === "exponent") {
230state.config.name = DebugScenarioNameGenerator.createScenarioName(
231state.scenarioType,
232state.config.type,
233state.config.platform,
234state.config.useHermesEngine !== false,
235false,
236state.config.expoPlatformType,
237);
9f8c460dEzio Li2 years ago238} else {
239state.config.name = DebugScenarioNameGenerator.createScenarioName(
240state.scenarioType,
241state.config.type,
242state.config.platform,
243state.config.useHermesEngine !== false,
244);
245}
c6ca8545Ezio Li3 years ago246} else {
247state.config.name = DebugScenarioNameGenerator.createScenarioName(
248state.scenarioType,
9f8c460dEzio Li2 years ago249state.config.type || DEBUG_TYPES.REACT_NATIVE,
c6ca8545Ezio Li3 years ago250state.config.platform,
251);
252}
5471436aRedMickey5 years ago253} else {
09f6024fHeniker4 years ago254state.config.name = DebugScenarioNameGenerator.createScenarioName(
255state.scenarioType,
256state.config.type || DEBUG_TYPES.REACT_NATIVE,
257state.config.platform,
258);
5471436aRedMickey5 years ago259}
9f8c460dEzio Li2 years ago260
09f6024fHeniker4 years ago261return state.config as vscode.DebugConfiguration;
5471436aRedMickey5 years ago262}
263
264private async pickDebugConfiguration(
265input: IMultiStepInput<DebugConfigurationState>,
266state: DebugConfigurationState,
267): Promise<InputStep<DebugConfigurationState> | void> {
268state.config = {};
269const pick = await input.showQuickPick<
270DebugConfigurationQuickPickItem,
271IQuickPickParameters<DebugConfigurationQuickPickItem>
272>({
273title: localize("DebugConfigQuickPickSequentialLabel", "Select a debug configuration"),
274placeholder: "Debug Configuration",
275activeItem: this.sequentialPickConfig[0],
276items: this.sequentialPickConfig,
277});
278if (pick) {
279const provider = ConfigProviderFactory.create(pick.type);
280return provider.buildConfiguration.bind(provider);
281}
282}
283
0bfa4e58Yuri Skorokhodov7 years ago284private gatherDebugScenarios(selectedItems: string[]): vscode.DebugConfiguration[] {
09f6024fHeniker4 years ago285const launchConfig: vscode.DebugConfiguration[] = selectedItems.map(
e7a2c40dRedMickey4 years ago286element => debugConfigurations[element],
34472878RedMickey5 years ago287);
0bfa4e58Yuri Skorokhodov7 years ago288return launchConfig;
289}
290
291private prepareDebugConfigPicker(): vscode.QuickPick<vscode.QuickPickItem> {
292const debugConfigPicker = vscode.window.createQuickPick();
293debugConfigPicker.canSelectMany = true;
294debugConfigPicker.ignoreFocusOut = true;
34472878RedMickey5 years ago295debugConfigPicker.title = localize(
296"DebugConfigQuickPickLabel",
297"Pick debug configurations",
298);
5471436aRedMickey5 years ago299debugConfigPicker.items = this.initialPickConfig;
0bfa4e58Yuri Skorokhodov7 years ago300// QuickPickItem property `picked` doesn't work, so this line will check first item in the list
301// which is supposed to be Debug Android
5471436aRedMickey5 years ago302debugConfigPicker.selectedItems = [this.initialPickConfig[0]];
0bfa4e58Yuri Skorokhodov7 years ago303return debugConfigPicker;
304}
305}