Skip to content

Commit

Permalink
src/pickProcess: show error when the process picker is hidden
Browse files Browse the repository at this point in the history
If a user accidentally hides the UI for the process picker, the
debugging setup process will hang, and it is unclear how to stop
or restart the process. This makes sure to dispose of the ui
element when we are finished with it and rejects the input if the
ui is hidden.

Change-Id: I32516ffbde7f2a48c59439769b44806c969a642e
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/499601
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
  • Loading branch information
suzmue committed Jun 2, 2023
1 parent 9ae57e8 commit 03cf976
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/pickProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,34 @@ export async function pickGoProcess(): Promise<string> {
}

async function processPicker(processes: AttachItem[], name?: string): Promise<string> {
// We need to use createQuickPick instead of showQuickPick
// to set the starting value for the menu.
const menu = vscode.window.createQuickPick<AttachItem>();
if (name) {
menu.value = name;
}
menu.items = processes;
menu.placeholder = 'Choose a process to attach to';
menu.matchOnDescription = true;
menu.matchOnDetail = true;
return new Promise<string>(async (resolve, reject) => {
const menu = vscode.window.createQuickPick<AttachItem>();
if (name) {
menu.value = name;
}
menu.items = processes;
menu.placeholder = 'Choose a process to attach to';
menu.matchOnDescription = true;
menu.matchOnDetail = true;

menu.onDidAccept(() => {
if (menu.selectedItems.length !== 1) {
reject(new Error('No process selected.'));
}
const selectedId = menu.selectedItems[0].id;

menu.dispose();

resolve(selectedId);
});
// The quickpick menu can be hidden either explicitly or
// through other UI interactions. When the quick pick menu is
// missing we want to keep the debugging setup process from
// hanging, so we reject the selection.
menu.onDidHide(() => {
reject(new Error('No process selected.'));
});

menu.show();
});
}).finally(() => menu.dispose());
}

// Modified from:
Expand Down

0 comments on commit 03cf976

Please sign in to comment.