(
delegate: DelegateLauncherFactory,
launcher: ITerminalLauncherLike,
options: Partial<ITerminalLaunchConfiguration> = {},
filterTarget: (target: ITarget) => boolean = () => true,
)
| 35 | import { DapTelemetryReporter } from '../telemetry/dapTelemetryReporter'; |
| 36 | |
| 37 | export const launchVirtualTerminalParent = ( |
| 38 | delegate: DelegateLauncherFactory, |
| 39 | launcher: ITerminalLauncherLike, |
| 40 | options: Partial<ITerminalLaunchConfiguration> = {}, |
| 41 | filterTarget: (target: ITarget) => boolean = () => true, |
| 42 | ) => { |
| 43 | const telemetry = new DapTelemetryReporter(); |
| 44 | const baseDebugOptions: Partial<ITerminalLaunchConfiguration> = { |
| 45 | ...readConfig(vscode.workspace, Configuration.TerminalDebugConfig), |
| 46 | // Prevent switching over the the Debug Console whenever a process starts |
| 47 | internalConsoleOptions: 'neverOpen', |
| 48 | }; |
| 49 | |
| 50 | // We don't have a debug session initially when we launch the terminal, so, |
| 51 | // we create a shell DAP instance that queues messages until it gets attached |
| 52 | // to a connection. Terminal processes don't use this too much except for |
| 53 | // telemetry. |
| 54 | const dap = createPendingDapApi(); |
| 55 | telemetry.attachDap(dap); |
| 56 | |
| 57 | // Watch the set of targets we get from this terminal launcher. Remember |
| 58 | // that we can get targets from child processes of session too. When we |
| 59 | // get a new top-level target (one without a parent session), start |
| 60 | // debugging. Removing delegated targets will automatically end debug |
| 61 | // sessions. Once all are removed, reset the DAP since we'll get a new |
| 62 | // instance for the next process that starts. |
| 63 | let previousTargets = new Set<ITarget>(); |
| 64 | |
| 65 | // Gets the ideal workspace folder for the given process. |
| 66 | const getWorkingDirectory = async (target: ITarget) => { |
| 67 | const telemetry = await launcher.getProcessTelemetry(target); |
| 68 | const fromTelemetry = telemetry && vscode.Uri.file(telemetry.cwd); |
| 69 | const preferred = fromTelemetry && vscode.workspace.getWorkspaceFolder(fromTelemetry); |
| 70 | if (preferred) { |
| 71 | return preferred.uri; |
| 72 | } |
| 73 | |
| 74 | if (options.__workspaceFolder) { |
| 75 | return vscode.Uri.file(options.__workspaceFolder); |
| 76 | } |
| 77 | |
| 78 | return vscode.workspace.workspaceFolders?.[0].uri ?? fromTelemetry; |
| 79 | }; |
| 80 | |
| 81 | launcher.onTargetListChanged(async () => { |
| 82 | const trusted = await vscode.workspace.requestWorkspaceTrust(); |
| 83 | const newTargets = new Set<ITarget>(); |
| 84 | for (const target of launcher.targetList()) { |
| 85 | newTargets.add(target); |
| 86 | |
| 87 | if (previousTargets.has(target)) { |
| 88 | previousTargets.delete(target); |
| 89 | continue; |
| 90 | } |
| 91 | |
| 92 | const delegateId = delegate.addDelegate(target, dap, target.parent()); |
| 93 | |
| 94 | // Skip targets the consumer asked to filter out. |
no test coverage detected