microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.8.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/reactNativeDebugConfigProvider.ts

257lines · 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";
e7a2c40dRedMickey4 years ago7import { debugConfigurations, DEBUG_CONFIGURATION_NAMES } from "./debugConfigTypesAndConstants";
5471436aRedMickey5 years ago8import { DebugScenarioNameGenerator } from "./debugScenarioNameGenerator";
9import { ILaunchRequestArgs } from "../../debugger/debugSessionBase";
10import {
11DEBUG_TYPES,
12DebugScenarioType,
13DebugConfigurationQuickPickItem,
14DebugConfigurationState,
15} from "./debugConfigTypesAndConstants";
16import { MultiStepInput, IMultiStepInput, InputStep, IQuickPickParameters } from "./multiStepInput";
17import { ConfigProviderFactory } from "./configurationProviders/configProviderFactory";
0bfa4e58Yuri Skorokhodov7 years ago18import * as nls from "vscode-nls";
34472878RedMickey5 years ago19nls.config({
20messageFormat: nls.MessageFormat.bundle,
21bundleFormat: nls.BundleFormat.standalone,
22})();
0bfa4e58Yuri Skorokhodov7 years ago23const localize = nls.loadMessageBundle();
24
25export class ReactNativeDebugConfigProvider implements vscode.DebugConfigurationProvider {
5471436aRedMickey5 years ago26private initialPickConfig: ReadonlyArray<vscode.QuickPickItem> = [
0bfa4e58Yuri Skorokhodov7 years ago27{
e7a2c40dRedMickey4 years ago28label: DEBUG_CONFIGURATION_NAMES.DEBUG_ANDROID,
0bfa4e58Yuri Skorokhodov7 years ago29description: localize("DebugAndroidConfigDesc", "Run and debug Android application"),
30},
5514e287RedMickey6 years ago31{
e7a2c40dRedMickey4 years ago32label: DEBUG_CONFIGURATION_NAMES.RUN_ANDROID,
5514e287RedMickey6 years ago33description: localize("RunAndroidConfigDesc", "Run Android application"),
34},
0bfa4e58Yuri Skorokhodov7 years ago35{
e7a2c40dRedMickey4 years ago36label: DEBUG_CONFIGURATION_NAMES.DEBUG_IOS,
0bfa4e58Yuri Skorokhodov7 years ago37description: localize("DebugiOSConfigDesc", "Run and debug iOS application"),
38},
5514e287RedMickey6 years ago39{
e7a2c40dRedMickey4 years ago40label: DEBUG_CONFIGURATION_NAMES.RUN_IOS,
5514e287RedMickey6 years ago41description: localize("RuniOSConfigDesc", "Run iOS application"),
42},
36e9730fDavid Serafimov6 years ago43{
e7a2c40dRedMickey4 years ago44label: DEBUG_CONFIGURATION_NAMES.DEBUG_WINDOWS,
36e9730fDavid Serafimov6 years ago45description: localize("DebugWindowsConfigDesc", "Run and debug Windows application"),
46},
341dba36Yuri Skorokhodov5 years ago47{
e7a2c40dRedMickey4 years ago48label: DEBUG_CONFIGURATION_NAMES.DEBUG_MACOS,
341dba36Yuri Skorokhodov5 years ago49description: localize("DebugmacOSConfigDesc", "Run and debug macOS application"),
50},
0bfa4e58Yuri Skorokhodov7 years ago51{
e7a2c40dRedMickey4 years ago52label: DEBUG_CONFIGURATION_NAMES.ATTACH_TO_PACKAGER,
34472878RedMickey5 years ago53description: localize(
54"AttachToPackagerConfigDesc",
55"Attach to already working application packager",
56),
0bfa4e58Yuri Skorokhodov7 years ago57},
58{
e7a2c40dRedMickey4 years ago59label: DEBUG_CONFIGURATION_NAMES.DEBUG_IN_EXPONENT,
34472878RedMickey5 years ago60description: localize(
61"DebugExpoConfigDesc",
62"Debug Expo application or React Native application in Expo",
63),
0bfa4e58Yuri Skorokhodov7 years ago64},
549baae2RedMickey6 years ago65{
e7a2c40dRedMickey4 years ago66label: DEBUG_CONFIGURATION_NAMES.DEBUG_ANDROID_HERMES_EXPERIMENTAL,
34472878RedMickey5 years ago67description: localize(
68"DebugAndroidHermesConfigDesc",
69"Run and debug Android Hermes application",
70),
549baae2RedMickey6 years ago71},
72{
e7a2c40dRedMickey4 years ago73label: DEBUG_CONFIGURATION_NAMES.RUN_ANDROID_HERMES_EXPERIMENTAL,
6f9a0779JiglioNero5 years ago74description: localize("RunAndroidHermesConfigDesc", "Run Android Hermes application"),
75},
76{
e7a2c40dRedMickey4 years ago77label: DEBUG_CONFIGURATION_NAMES.DEBUG_IOS_HERMES_EXPERIMENTAL,
34472878RedMickey5 years ago78description: localize(
6f9a0779JiglioNero5 years ago79"DebugIosHermesConfigDesc",
80"Run and debug iOS Hermes application",
34472878RedMickey5 years ago81),
259c018fYuri Skorokhodov5 years ago82},
83{
e7a2c40dRedMickey4 years ago84label: DEBUG_CONFIGURATION_NAMES.RUN_IOS_HERMES_EXPERIMENTAL,
6f9a0779JiglioNero5 years ago85description: localize("RunIosHermesConfigDesc", "Run iOS Hermes application"),
86},
5c9b8eb8RedMickey5 years ago87{
e7a2c40dRedMickey4 years ago88label: DEBUG_CONFIGURATION_NAMES.DEBUG_MACOS_HERMES_EXPERIMENTAL,
5c9b8eb8RedMickey5 years ago89description: localize(
90"DebugMacOSHermesConfigDesc",
91"Run and debug macOS Hermes application",
92),
93},
008d88e5RedMickey4 years ago94{
e7a2c40dRedMickey4 years ago95label: DEBUG_CONFIGURATION_NAMES.DEBUG_WINDOWS_HERMES_EXPERIMENTAL,
008d88e5RedMickey4 years ago96description: localize(
97"DebugWindowsHermesConfigDesc",
98"Run and debug Windows Hermes application",
99),
100},
6f9a0779JiglioNero5 years ago101{
e7a2c40dRedMickey4 years ago102label: DEBUG_CONFIGURATION_NAMES.ATTACH_TO_HERMES_APPLICATION_EXPERIMENTAL,
34472878RedMickey5 years ago103description: localize(
6f9a0779JiglioNero5 years ago104"AttachToPackagerHermesConfigDesc",
105"Attach to already working React Native Hermes application on Android directly",
34472878RedMickey5 years ago106),
259c018fYuri Skorokhodov5 years ago107},
108{
e7a2c40dRedMickey4 years ago109label: DEBUG_CONFIGURATION_NAMES.DEBUG_DIRECT_IOS_EXPERIMENTAL,
34472878RedMickey5 years ago110description: localize(
111"DebugDirectiOSConfigDesc",
112"Run and debug iOS application directly",
113),
259c018fYuri Skorokhodov5 years ago114},
115{
e7a2c40dRedMickey4 years ago116label: DEBUG_CONFIGURATION_NAMES.RUN_DIRECT_IOS_EXPERIMENTAL,
34472878RedMickey5 years ago117description: localize(
118"RunDirectiOSConfigDesc",
119"Run iOS application with direct debugging support",
120),
549baae2RedMickey6 years ago121},
6f9a0779JiglioNero5 years ago122{
e7a2c40dRedMickey4 years ago123label: DEBUG_CONFIGURATION_NAMES.ATTACH_TO_DIRECT_IOS_EXPERIMENTAL,
6f9a0779JiglioNero5 years ago124description: localize(
125"AttachToPackageriOSConfigDesc",
126"Attach to already working React Native iOS application directly",
127),
128},
0bfa4e58Yuri Skorokhodov7 years ago129];
130
5471436aRedMickey5 years ago131private sequentialPickConfig: ReadonlyArray<DebugConfigurationQuickPickItem> = [
132{
133label: "Run application",
134description: localize(
135"RunApplicationScenario",
136"Run React Native application without debugging",
137),
138type: DebugScenarioType.RunApp,
139},
140{
141label: "Debug application",
142description: localize("DebugApplicationScenario", "Debug React Native application"),
143type: DebugScenarioType.DebugApp,
144},
145{
146label: "Attach to application",
147description: localize(
148"AttachApplicationScenario",
149"Attach to running React Native application",
150),
151type: DebugScenarioType.AttachApp,
152},
153];
154
34472878RedMickey5 years ago155public async provideDebugConfigurations(
156folder: vscode.WorkspaceFolder | undefined, // eslint-disable-line @typescript-eslint/no-unused-vars
157token?: vscode.CancellationToken, // eslint-disable-line @typescript-eslint/no-unused-vars
158): Promise<vscode.DebugConfiguration[]> {
159return new Promise<vscode.DebugConfiguration[]>(resolve => {
0bfa4e58Yuri Skorokhodov7 years ago160const configPicker = this.prepareDebugConfigPicker();
161const disposables: vscode.Disposable[] = [];
162const pickHandler = () => {
34472878RedMickey5 years ago163let chosenConfigsEvent = TelemetryHelper.createTelemetryEvent(
164"chosenDebugConfigurations",
165);
0bfa4e58Yuri Skorokhodov7 years ago166let selected: string[] = configPicker.selectedItems.map(element => element.label);
74471e03Yuri Skorokhodov7 years ago167chosenConfigsEvent.properties["selectedItems"] = selected;
0bfa4e58Yuri Skorokhodov7 years ago168Telemetry.send(chosenConfigsEvent);
169const launchConfig = this.gatherDebugScenarios(selected);
170disposables.forEach(d => d.dispose());
171resolve(launchConfig);
172};
173
174disposables.push(
175configPicker.onDidAccept(pickHandler),
176configPicker.onDidHide(pickHandler),
34472878RedMickey5 years ago177configPicker,
0bfa4e58Yuri Skorokhodov7 years ago178);
179
180configPicker.show();
181});
182}
183
5471436aRedMickey5 years ago184public async provideDebugConfigurationSequentially(
185folder: vscode.WorkspaceFolder | undefined,
186token?: vscode.CancellationToken,
187): Promise<vscode.DebugConfiguration | undefined> {
188const config: Partial<ILaunchRequestArgs> = {};
189const state = { config, scenarioType: DebugScenarioType.DebugApp, folder, token };
190
191const multiStep = new MultiStepInput<DebugConfigurationState>();
192await multiStep.run((input, s) => this.pickDebugConfiguration(input, s), state);
193
194if (Object.keys(state.config).length === 0) {
195return;
196} else {
197if (state.config.type === DEBUG_TYPES.REACT_NATIVE_DIRECT) {
198state.config.name = DebugScenarioNameGenerator.createScenarioName(
199state.scenarioType,
200state.config.type,
201state.config.platform,
6f9a0779JiglioNero5 years ago202state.config.useHermesEngine !== false,
5471436aRedMickey5 years ago203true,
204);
205} else {
206state.config.name = DebugScenarioNameGenerator.createScenarioName(
207state.scenarioType,
208state.config.type || DEBUG_TYPES.REACT_NATIVE,
209state.config.platform,
210);
211}
212return state.config as vscode.DebugConfiguration;
213}
214}
215
216private async pickDebugConfiguration(
217input: IMultiStepInput<DebugConfigurationState>,
218state: DebugConfigurationState,
219): Promise<InputStep<DebugConfigurationState> | void> {
220state.config = {};
221const pick = await input.showQuickPick<
222DebugConfigurationQuickPickItem,
223IQuickPickParameters<DebugConfigurationQuickPickItem>
224>({
225title: localize("DebugConfigQuickPickSequentialLabel", "Select a debug configuration"),
226placeholder: "Debug Configuration",
227activeItem: this.sequentialPickConfig[0],
228items: this.sequentialPickConfig,
229});
230if (pick) {
231const provider = ConfigProviderFactory.create(pick.type);
232return provider.buildConfiguration.bind(provider);
233}
234}
235
0bfa4e58Yuri Skorokhodov7 years ago236private gatherDebugScenarios(selectedItems: string[]): vscode.DebugConfiguration[] {
34472878RedMickey5 years ago237let launchConfig: vscode.DebugConfiguration[] = selectedItems.map(
e7a2c40dRedMickey4 years ago238element => debugConfigurations[element],
34472878RedMickey5 years ago239);
0bfa4e58Yuri Skorokhodov7 years ago240return launchConfig;
241}
242
243private prepareDebugConfigPicker(): vscode.QuickPick<vscode.QuickPickItem> {
244const debugConfigPicker = vscode.window.createQuickPick();
245debugConfigPicker.canSelectMany = true;
246debugConfigPicker.ignoreFocusOut = true;
34472878RedMickey5 years ago247debugConfigPicker.title = localize(
248"DebugConfigQuickPickLabel",
249"Pick debug configurations",
250);
5471436aRedMickey5 years ago251debugConfigPicker.items = this.initialPickConfig;
0bfa4e58Yuri Skorokhodov7 years ago252// QuickPickItem property `picked` doesn't work, so this line will check first item in the list
253// which is supposed to be Debug Android
5471436aRedMickey5 years ago254debugConfigPicker.selectedItems = [this.initialPickConfig[0]];
0bfa4e58Yuri Skorokhodov7 years ago255return debugConfigPicker;
256}
257}