microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/debugConfigurationProvider.ts
208lines · 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"; | |
259c018fYuri Skorokhodov5 years ago | 8 | import { PlatformType } from "./launchArgs"; |
| 9 | import { IWDPHelper } from "../debugger/direct/IWDPHelper"; | |
2d8af448Yuri Skorokhodov6 years ago | 10 | nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); |
0bfa4e58Yuri Skorokhodov7 years ago | 11 | const localize = nls.loadMessageBundle(); |
| 12 | | |
ebbd64f1RedMickey6 years ago | 13 | export const DEBUG_TYPES = { |
d55f3c22Yuri Skorokhodov5 years ago | 14 | REACT_NATIVE: "reactnative", |
| 15 | REACT_NATIVE_DIRECT: "reactnativedirect", | |
ebbd64f1RedMickey6 years ago | 16 | }; |
| 17 | | |
0bfa4e58Yuri Skorokhodov7 years ago | 18 | export class ReactNativeDebugConfigProvider implements vscode.DebugConfigurationProvider { |
| 19 | private debugConfigurations = { | |
d55f3c22Yuri Skorokhodov5 years ago | 20 | "Debug Android": { |
| 21 | "name": "Debug Android", | |
18ea7d15Yuri Skorokhodov7 years ago | 22 | "cwd": "${workspaceFolder}", |
ebbd64f1RedMickey6 years ago | 23 | "type": DEBUG_TYPES.REACT_NATIVE, |
0bfa4e58Yuri Skorokhodov7 years ago | 24 | "request": "launch", |
259c018fYuri Skorokhodov5 years ago | 25 | "platform": PlatformType.Android, |
0bfa4e58Yuri Skorokhodov7 years ago | 26 | }, |
d55f3c22Yuri Skorokhodov5 years ago | 27 | "Run Android": { |
| 28 | "name": "Run Android", | |
5514e287RedMickey6 years ago | 29 | "cwd": "${workspaceFolder}", |
| 30 | "type": DEBUG_TYPES.REACT_NATIVE, | |
| 31 | "request": "launch", | |
259c018fYuri Skorokhodov5 years ago | 32 | "platform": PlatformType.Android, |
5514e287RedMickey6 years ago | 33 | "enableDebug": false, |
| 34 | }, | |
d55f3c22Yuri Skorokhodov5 years ago | 35 | "Debug iOS": { |
| 36 | "name": "Debug iOS", | |
18ea7d15Yuri Skorokhodov7 years ago | 37 | "cwd": "${workspaceFolder}", |
ebbd64f1RedMickey6 years ago | 38 | "type": DEBUG_TYPES.REACT_NATIVE, |
0bfa4e58Yuri Skorokhodov7 years ago | 39 | "request": "launch", |
259c018fYuri Skorokhodov5 years ago | 40 | "platform": PlatformType.iOS, |
0bfa4e58Yuri Skorokhodov7 years ago | 41 | }, |
d55f3c22Yuri Skorokhodov5 years ago | 42 | "Run iOS": { |
| 43 | "name": "Run iOS", | |
5514e287RedMickey6 years ago | 44 | "cwd": "${workspaceFolder}", |
| 45 | "type": DEBUG_TYPES.REACT_NATIVE, | |
| 46 | "request": "launch", | |
259c018fYuri Skorokhodov5 years ago | 47 | "platform": PlatformType.iOS, |
5514e287RedMickey6 years ago | 48 | "enableDebug": false, |
| 49 | }, | |
d55f3c22Yuri Skorokhodov5 years ago | 50 | "Debug Windows": { |
| 51 | "name": "Debug Windows", | |
36e9730fDavid Serafimov6 years ago | 52 | "cwd": "${workspaceFolder}", |
ebbd64f1RedMickey6 years ago | 53 | "type": DEBUG_TYPES.REACT_NATIVE, |
36e9730fDavid Serafimov6 years ago | 54 | "request": "launch", |
259c018fYuri Skorokhodov5 years ago | 55 | "platform": PlatformType.Windows, |
36e9730fDavid Serafimov6 years ago | 56 | }, |
d55f3c22Yuri Skorokhodov5 years ago | 57 | "Attach to packager": { |
| 58 | "name": "Attach to packager", | |
18ea7d15Yuri Skorokhodov7 years ago | 59 | "cwd": "${workspaceFolder}", |
ebbd64f1RedMickey6 years ago | 60 | "type": DEBUG_TYPES.REACT_NATIVE, |
0bfa4e58Yuri Skorokhodov7 years ago | 61 | "request": "attach", |
| 62 | }, | |
d55f3c22Yuri Skorokhodov5 years ago | 63 | "Debug in Exponent": { |
| 64 | "name": "Debug in Exponent", | |
18ea7d15Yuri Skorokhodov7 years ago | 65 | "cwd": "${workspaceFolder}", |
ebbd64f1RedMickey6 years ago | 66 | "type": DEBUG_TYPES.REACT_NATIVE, |
0bfa4e58Yuri Skorokhodov7 years ago | 67 | "request": "launch", |
259c018fYuri Skorokhodov5 years ago | 68 | "platform": PlatformType.Exponent, |
0bfa4e58Yuri Skorokhodov7 years ago | 69 | }, |
d55f3c22Yuri Skorokhodov5 years ago | 70 | "Debug Android Hermes - Experimental": { |
| 71 | "name": "Debug Android Hermes - Experimental", | |
549baae2RedMickey6 years ago | 72 | "cwd": "${workspaceFolder}", |
ebbd64f1RedMickey6 years ago | 73 | "type": DEBUG_TYPES.REACT_NATIVE_DIRECT, |
549baae2RedMickey6 years ago | 74 | "request": "launch", |
259c018fYuri Skorokhodov5 years ago | 75 | "platform": PlatformType.Android, |
549baae2RedMickey6 years ago | 76 | }, |
d55f3c22Yuri Skorokhodov5 years ago | 77 | "Run Android Hermes - Experimental": { |
| 78 | "name": "Run Android Hermes - Experimental", | |
5514e287RedMickey6 years ago | 79 | "cwd": "${workspaceFolder}", |
| 80 | "type": DEBUG_TYPES.REACT_NATIVE_DIRECT, | |
| 81 | "request": "launch", | |
259c018fYuri Skorokhodov5 years ago | 82 | "platform": PlatformType.Android, |
5514e287RedMickey6 years ago | 83 | "enableDebug": false, |
| 84 | }, | |
259c018fYuri Skorokhodov5 years ago | 85 | "Attach to the React Native Hermes - Experimental": { |
| 86 | "name": "Attach to the React Native Hermes - Experimental", | |
549baae2RedMickey6 years ago | 87 | "cwd": "${workspaceFolder}", |
ebbd64f1RedMickey6 years ago | 88 | "type": DEBUG_TYPES.REACT_NATIVE_DIRECT, |
549baae2RedMickey6 years ago | 89 | "request": "attach", |
| 90 | }, | |
259c018fYuri Skorokhodov5 years ago | 91 | "Attach to the React Native iOS - Experimental": { |
| 92 | "name": "Attach to the React Native iOS - Experimental", | |
| 93 | "cwd": "${workspaceFolder}", | |
| 94 | "type": DEBUG_TYPES.REACT_NATIVE_DIRECT, | |
| 95 | "request": "attach", | |
| 96 | "platform": PlatformType.iOS, | |
| 97 | "port": IWDPHelper.iOS_WEBKIT_DEBUG_PROXY_DEFAULT_PORT // 9221 | |
| 98 | }, | |
d55f3c22Yuri Skorokhodov5 years ago | 99 | "Debug Direct iOS - Experimental": { |
| 100 | "name": "Debug Direct iOS - Experimental", | |
259c018fYuri Skorokhodov5 years ago | 101 | "cwd": "${workspaceFolder}", |
| 102 | "type": DEBUG_TYPES.REACT_NATIVE_DIRECT, | |
| 103 | "request": "launch", | |
| 104 | "platform": PlatformType.iOS, | |
| 105 | "port": IWDPHelper.iOS_WEBKIT_DEBUG_PROXY_DEFAULT_PORT // 9221 | |
| 106 | }, | |
d55f3c22Yuri Skorokhodov5 years ago | 107 | "Run Direct iOS - Experimental": { |
| 108 | "name": "Run Direct iOS - Experimental", | |
259c018fYuri Skorokhodov5 years ago | 109 | "cwd": "${workspaceFolder}", |
| 110 | "type": DEBUG_TYPES.REACT_NATIVE_DIRECT, | |
| 111 | "request": "launch", | |
| 112 | "platform": PlatformType.iOS, | |
| 113 | "enableDebug": false, | |
| 114 | } | |
0bfa4e58Yuri Skorokhodov7 years ago | 115 | }; |
| 116 | | |
| 117 | private pickConfig: ReadonlyArray<vscode.QuickPickItem> = [ | |
| 118 | { | |
d55f3c22Yuri Skorokhodov5 years ago | 119 | label: "Debug Android", |
0bfa4e58Yuri Skorokhodov7 years ago | 120 | description: localize("DebugAndroidConfigDesc", "Run and debug Android application"), |
| 121 | }, | |
5514e287RedMickey6 years ago | 122 | { |
d55f3c22Yuri Skorokhodov5 years ago | 123 | label: "Run Android", |
5514e287RedMickey6 years ago | 124 | description: localize("RunAndroidConfigDesc", "Run Android application"), |
| 125 | }, | |
0bfa4e58Yuri Skorokhodov7 years ago | 126 | { |
d55f3c22Yuri Skorokhodov5 years ago | 127 | label: "Debug iOS", |
0bfa4e58Yuri Skorokhodov7 years ago | 128 | description: localize("DebugiOSConfigDesc", "Run and debug iOS application"), |
| 129 | }, | |
5514e287RedMickey6 years ago | 130 | { |
d55f3c22Yuri Skorokhodov5 years ago | 131 | label: "Run iOS", |
5514e287RedMickey6 years ago | 132 | description: localize("RuniOSConfigDesc", "Run iOS application"), |
| 133 | }, | |
36e9730fDavid Serafimov6 years ago | 134 | { |
d55f3c22Yuri Skorokhodov5 years ago | 135 | label: "Debug Windows", |
36e9730fDavid Serafimov6 years ago | 136 | description: localize("DebugWindowsConfigDesc", "Run and debug Windows application"), |
| 137 | }, | |
0bfa4e58Yuri Skorokhodov7 years ago | 138 | { |
d55f3c22Yuri Skorokhodov5 years ago | 139 | label: "Attach to packager", |
0bfa4e58Yuri Skorokhodov7 years ago | 140 | description: localize("AttachToPackagerConfigDesc", "Attach to already working application packager"), |
| 141 | }, | |
| 142 | { | |
d55f3c22Yuri Skorokhodov5 years ago | 143 | label: "Debug in Exponent", |
0bfa4e58Yuri Skorokhodov7 years ago | 144 | description: localize("DebugExpoConfigDesc", "Debug Expo application or React Native application in Expo"), |
| 145 | }, | |
549baae2RedMickey6 years ago | 146 | { |
d55f3c22Yuri Skorokhodov5 years ago | 147 | label: "Debug Android Hermes - Experimental", |
549baae2RedMickey6 years ago | 148 | description: localize("DebugAndroidHermesConfigDesc", "Run and debug Android Hermes application"), |
| 149 | }, | |
| 150 | { | |
259c018fYuri Skorokhodov5 years ago | 151 | label: "Attach to the React Native Hermes - Experimental", |
| 152 | description: localize("AttachToPackagerHermesConfigDesc", "Attach to already working React Native Hermes application on Android directly"), | |
| 153 | }, | |
| 154 | { | |
| 155 | label: "Attach to the React Native iOS - Experimental", | |
| 156 | description: localize("AttachToPackageriOSConfigDesc", "Attach to already working React Native iOS application directly"), | |
| 157 | }, | |
| 158 | { | |
d55f3c22Yuri Skorokhodov5 years ago | 159 | label: "Debug Direct iOS - Experimental", |
259c018fYuri Skorokhodov5 years ago | 160 | description: localize("DebugDirectiOSConfigDesc", "Run and debug iOS application directly"), |
| 161 | }, | |
| 162 | { | |
d55f3c22Yuri Skorokhodov5 years ago | 163 | label: "Run Direct iOS - Experimental", |
259c018fYuri Skorokhodov5 years ago | 164 | description: localize("RunDirectiOSConfigDesc", "Run iOS application with direct debugging support"), |
549baae2RedMickey6 years ago | 165 | }, |
0bfa4e58Yuri Skorokhodov7 years ago | 166 | ]; |
| 167 | | |
| 168 | public async provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration[]> { | |
| 169 | return new Promise<vscode.DebugConfiguration[]>((resolve) => { | |
| 170 | const configPicker = this.prepareDebugConfigPicker(); | |
| 171 | const disposables: vscode.Disposable[] = []; | |
| 172 | const pickHandler = () => { | |
74471e03Yuri Skorokhodov7 years ago | 173 | let chosenConfigsEvent = TelemetryHelper.createTelemetryEvent("chosenDebugConfigurations"); |
0bfa4e58Yuri Skorokhodov7 years ago | 174 | let selected: string[] = configPicker.selectedItems.map(element => element.label); |
74471e03Yuri Skorokhodov7 years ago | 175 | chosenConfigsEvent.properties["selectedItems"] = selected; |
0bfa4e58Yuri Skorokhodov7 years ago | 176 | Telemetry.send(chosenConfigsEvent); |
| 177 | const launchConfig = this.gatherDebugScenarios(selected); | |
| 178 | disposables.forEach(d => d.dispose()); | |
| 179 | resolve(launchConfig); | |
| 180 | }; | |
| 181 | | |
| 182 | disposables.push( | |
| 183 | configPicker.onDidAccept(pickHandler), | |
| 184 | configPicker.onDidHide(pickHandler), | |
| 185 | configPicker | |
| 186 | ); | |
| 187 | | |
| 188 | configPicker.show(); | |
| 189 | }); | |
| 190 | } | |
| 191 | | |
| 192 | private gatherDebugScenarios(selectedItems: string[]): vscode.DebugConfiguration[] { | |
| 193 | let launchConfig: vscode.DebugConfiguration[] = selectedItems.map(element => this.debugConfigurations[element]); | |
| 194 | return launchConfig; | |
| 195 | } | |
| 196 | | |
| 197 | private prepareDebugConfigPicker(): vscode.QuickPick<vscode.QuickPickItem> { | |
| 198 | const debugConfigPicker = vscode.window.createQuickPick(); | |
| 199 | debugConfigPicker.canSelectMany = true; | |
| 200 | debugConfigPicker.ignoreFocusOut = true; | |
| 201 | debugConfigPicker.title = localize("DebugConfigQuickPickLabel", "Pick debug configurations"); | |
| 202 | debugConfigPicker.items = this.pickConfig; | |
| 203 | // QuickPickItem property `picked` doesn't work, so this line will check first item in the list | |
| 204 | // which is supposed to be Debug Android | |
| 205 | debugConfigPicker.selectedItems = [this.pickConfig[0]]; | |
| 206 | return debugConfigPicker; | |
| 207 | } | |
| 208 | } |