MCPcopy
hub / github.com/PowerShell/vscode-powershell / showChoicePrompt

Function showChoicePrompt

src/features/Console.ts:72–129  ·  view source on GitHub ↗
(
    promptDetails: IShowChoicePromptRequestArgs,
)

Source from the content-addressed store, hash-verified

70}
71
72function showChoicePrompt(
73 promptDetails: IShowChoicePromptRequestArgs,
74): Thenable<IShowChoicePromptResponseBody> {
75 let resultThenable: Thenable<IShowChoicePromptResponseBody>;
76
77 if (!promptDetails.isMultiChoice) {
78 let quickPickItems = promptDetails.choices.map<vscode.QuickPickItem>(
79 (choice) => {
80 return {
81 label: choice.label,
82 description: choice.helpMessage,
83 };
84 },
85 );
86
87 if (promptDetails.defaultChoices.length > 0) {
88 // Shift the default items to the front of the
89 // array so that the user can select it easily
90 const defaultChoice = promptDetails.defaultChoices[0];
91 if (
92 defaultChoice > -1 &&
93 defaultChoice < promptDetails.choices.length
94 ) {
95 const defaultChoiceItem = quickPickItems[defaultChoice];
96 quickPickItems.splice(defaultChoice, 1);
97
98 // Add the default choice to the head of the array
99 quickPickItems = [defaultChoiceItem].concat(quickPickItems);
100 }
101 }
102
103 resultThenable = vscode.window
104 .showQuickPick(quickPickItems, {
105 placeHolder: promptDetails.message,
106 })
107 .then(onItemSelected);
108 } else {
109 const checkboxQuickPickItems =
110 promptDetails.choices.map<ICheckboxQuickPickItem>((choice) => {
111 return {
112 label: choice.label,
113 description: choice.helpMessage,
114 isSelected: false,
115 };
116 });
117
118 // Select the defaults
119 for (const choice of promptDetails.defaultChoices) {
120 checkboxQuickPickItems[choice].isSelected = true;
121 }
122
123 resultThenable = showCheckboxQuickPick(checkboxQuickPickItems, {
124 confirmPlaceHolder: promptDetails.message,
125 }).then(onItemsSelected);
126 }
127
128 return resultThenable;
129}

Callers 1

onLanguageClientSetMethod · 0.85

Calls 1

showCheckboxQuickPickFunction · 0.90

Tested by

no test coverage detected