Skip to content

Commit

Permalink
use terminal.processId for auto-attach; fixes #55918
Browse files Browse the repository at this point in the history
  • Loading branch information
weinand committed Aug 7, 2018
1 parent 96a0a43 commit edfda96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 48 deletions.
24 changes: 0 additions & 24 deletions extensions/debug-auto-launch/src/autoAttach.ts

This file was deleted.

33 changes: 9 additions & 24 deletions extensions/debug-auto-launch/src/nodeProcessTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ export function attachToProcess(folder: vscode.WorkspaceFolder | undefined, name

function findChildProcesses(rootPid: number, inTerminal: boolean, cb: (pid: number, cmd: string, args: string) => void): Promise<void> {

function walker(node: ProcessTreeNode, terminal: boolean, renderer: number) {
function walker(node: ProcessTreeNode, terminal: boolean, terminalPids: number[]) {

if ((node.args.indexOf('--type=terminal') >= 0 || node.command.indexOf('\\winpty-agent.exe') >= 0) && (renderer === 0 || node.ppid === renderer)) {
terminal = true;
if (terminalPids.indexOf(node.pid) >= 0) {
terminal = true; // found the terminal shell
}

let { protocol } = analyseArguments(node.args);
Expand All @@ -107,32 +107,17 @@ function findChildProcesses(rootPid: number, inTerminal: boolean, cb: (pid: numb
}

for (const child of node.children || []) {
walker(child, terminal, renderer);
walker(child, terminal, terminalPids);
}
}

function finder(node: ProcessTreeNode, pid: number): ProcessTreeNode | undefined {
if (node.pid === pid) {
return node;
}
for (const child of node.children || []) {
const p = finder(child, pid);
if (p) {
return p;
}
}
return undefined;
}

return getProcessTree(rootPid).then(tree => {
if (tree) {

// find the pid of the renderer process
const extensionHost = finder(tree, process.pid);
let rendererPid = extensionHost ? extensionHost.ppid : 0;

for (const child of tree.children || []) {
walker(child, !inTerminal, rendererPid);
const terminals = vscode.window.terminals;
if (terminals.length > 0) {
Promise.all(terminals.map(terminal => terminal.processId)).then(terminalPids => {
walker(tree, !inTerminal, terminalPids);
});
}
}
});
Expand Down

0 comments on commit edfda96

Please sign in to comment.