microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/debugConfigurationProvider.ts
132lines · modeblame
0bfa4e58Yuri Skorokhodov7 years ago | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. | |
| 3 | | |
| 4 | import * as vscode from "vscode"; | |
| 5 | import { TelemetryHelper } from "../common/telemetryHelper"; | |
| 6 | import { Telemetry } from "../common/telemetry"; | |
| 7 | import * as nls from "vscode-nls"; | |
| 8 | const localize = nls.loadMessageBundle(); | |
| 9 | | |
| 10 | export class ReactNativeDebugConfigProvider implements vscode.DebugConfigurationProvider { | |
| 11 | private debugConfigurations = { | |
| 12 | "Debug Android": { | |
| 13 | "name": "Debug Android", | |
18ea7d15Yuri Skorokhodov6 years ago | 14 | "cwd": "${workspaceFolder}", |
0bfa4e58Yuri Skorokhodov7 years ago | 15 | "type": "reactnative", |
| 16 | "request": "launch", | |
| 17 | "platform": "android", | |
| 18 | }, | |
| 19 | "Debug iOS": { | |
| 20 | "name": "Debug iOS", | |
18ea7d15Yuri Skorokhodov6 years ago | 21 | "cwd": "${workspaceFolder}", |
0bfa4e58Yuri Skorokhodov7 years ago | 22 | "type": "reactnative", |
| 23 | "request": "launch", | |
| 24 | "platform": "ios", | |
| 25 | }, | |
36e9730fDavid Serafimov6 years ago | 26 | "Debug Windows": { |
| 27 | "name": "Debug Windows", | |
| 28 | "cwd": "${workspaceFolder}", | |
| 29 | "type": "reactnative", | |
| 30 | "request": "launch", | |
| 31 | "platform": "windows", | |
| 32 | }, | |
0bfa4e58Yuri Skorokhodov7 years ago | 33 | "Attach to packager": { |
| 34 | "name": "Attach to packager", | |
18ea7d15Yuri Skorokhodov6 years ago | 35 | "cwd": "${workspaceFolder}", |
0bfa4e58Yuri Skorokhodov7 years ago | 36 | "type": "reactnative", |
| 37 | "request": "attach", | |
| 38 | }, | |
| 39 | "Debug in Exponent": { | |
| 40 | "name": "Debug in Exponent", | |
18ea7d15Yuri Skorokhodov6 years ago | 41 | "cwd": "${workspaceFolder}", |
0bfa4e58Yuri Skorokhodov7 years ago | 42 | "type": "reactnative", |
| 43 | "request": "launch", | |
| 44 | "platform": "exponent", | |
| 45 | }, | |
549baae2RedMickey6 years ago | 46 | "Debug Android (Hermes) - Experimental": { |
| 47 | "name": "Debug Android (Hermes) - Experimental", | |
| 48 | "cwd": "${workspaceFolder}", | |
| 49 | "type": "reactnativedirect", | |
| 50 | "request": "launch", | |
| 51 | "platform": "android", | |
| 52 | }, | |
8411a7adYuri Skorokhodov6 years ago | 53 | "Attach to Hermes application - Experimental": { |
| 54 | "name": "Attach to Hermes application - Experimental", | |
549baae2RedMickey6 years ago | 55 | "cwd": "${workspaceFolder}", |
| 56 | "type": "reactnativedirect", | |
| 57 | "request": "attach", | |
| 58 | }, | |
0bfa4e58Yuri Skorokhodov7 years ago | 59 | }; |
| 60 | | |
| 61 | private pickConfig: ReadonlyArray<vscode.QuickPickItem> = [ | |
| 62 | { | |
| 63 | label: "Debug Android", | |
| 64 | description: localize("DebugAndroidConfigDesc", "Run and debug Android application"), | |
| 65 | }, | |
| 66 | { | |
| 67 | label: "Debug iOS", | |
| 68 | description: localize("DebugiOSConfigDesc", "Run and debug iOS application"), | |
| 69 | }, | |
36e9730fDavid Serafimov6 years ago | 70 | { |
| 71 | label: "Debug Windows", | |
| 72 | description: localize("DebugWindowsConfigDesc", "Run and debug Windows application"), | |
| 73 | }, | |
0bfa4e58Yuri Skorokhodov7 years ago | 74 | { |
| 75 | label: "Attach to packager", | |
| 76 | description: localize("AttachToPackagerConfigDesc", "Attach to already working application packager"), | |
| 77 | }, | |
| 78 | { | |
| 79 | label: "Debug in Exponent", | |
| 80 | description: localize("DebugExpoConfigDesc", "Debug Expo application or React Native application in Expo"), | |
| 81 | }, | |
549baae2RedMickey6 years ago | 82 | { |
| 83 | label: "Debug Android (Hermes) - Experimental", | |
| 84 | description: localize("DebugAndroidHermesConfigDesc", "Run and debug Android Hermes application"), | |
| 85 | }, | |
| 86 | { | |
8411a7adYuri Skorokhodov6 years ago | 87 | label: "Attach to Hermes application - Experimental", |
549baae2RedMickey6 years ago | 88 | description: localize("AttachToPackagerHermesConfigDesc", "Attach to already working Android Hermes application packager"), |
| 89 | }, | |
0bfa4e58Yuri Skorokhodov7 years ago | 90 | ]; |
| 91 | | |
| 92 | public async provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration[]> { | |
| 93 | return new Promise<vscode.DebugConfiguration[]>((resolve) => { | |
| 94 | const configPicker = this.prepareDebugConfigPicker(); | |
| 95 | const disposables: vscode.Disposable[] = []; | |
| 96 | const pickHandler = () => { | |
74471e03Yuri Skorokhodov6 years ago | 97 | let chosenConfigsEvent = TelemetryHelper.createTelemetryEvent("chosenDebugConfigurations"); |
0bfa4e58Yuri Skorokhodov7 years ago | 98 | let selected: string[] = configPicker.selectedItems.map(element => element.label); |
74471e03Yuri Skorokhodov6 years ago | 99 | chosenConfigsEvent.properties["selectedItems"] = selected; |
0bfa4e58Yuri Skorokhodov7 years ago | 100 | Telemetry.send(chosenConfigsEvent); |
| 101 | const launchConfig = this.gatherDebugScenarios(selected); | |
| 102 | disposables.forEach(d => d.dispose()); | |
| 103 | resolve(launchConfig); | |
| 104 | }; | |
| 105 | | |
| 106 | disposables.push( | |
| 107 | configPicker.onDidAccept(pickHandler), | |
| 108 | configPicker.onDidHide(pickHandler), | |
| 109 | configPicker | |
| 110 | ); | |
| 111 | | |
| 112 | configPicker.show(); | |
| 113 | }); | |
| 114 | } | |
| 115 | | |
| 116 | private gatherDebugScenarios(selectedItems: string[]): vscode.DebugConfiguration[] { | |
| 117 | let launchConfig: vscode.DebugConfiguration[] = selectedItems.map(element => this.debugConfigurations[element]); | |
| 118 | return launchConfig; | |
| 119 | } | |
| 120 | | |
| 121 | private prepareDebugConfigPicker(): vscode.QuickPick<vscode.QuickPickItem> { | |
| 122 | const debugConfigPicker = vscode.window.createQuickPick(); | |
| 123 | debugConfigPicker.canSelectMany = true; | |
| 124 | debugConfigPicker.ignoreFocusOut = true; | |
| 125 | debugConfigPicker.title = localize("DebugConfigQuickPickLabel", "Pick debug configurations"); | |
| 126 | debugConfigPicker.items = this.pickConfig; | |
| 127 | // QuickPickItem property `picked` doesn't work, so this line will check first item in the list | |
| 128 | // which is supposed to be Debug Android | |
| 129 | debugConfigPicker.selectedItems = [this.pickConfig[0]]; | |
| 130 | return debugConfigPicker; | |
| 131 | } | |
| 132 | } |