@@ -6,7 +6,6 @@ import { assertNever } from '../../../../../base/common/assert.js';
6
6
import { Codicon } from '../../../../../base/common/codicons.js' ;
7
7
import { diffSets } from '../../../../../base/common/collections.js' ;
8
8
import { Event } from '../../../../../base/common/event.js' ;
9
- import { Iterable } from '../../../../../base/common/iterator.js' ;
10
9
import { DisposableStore } from '../../../../../base/common/lifecycle.js' ;
11
10
import { ThemeIcon } from '../../../../../base/common/themables.js' ;
12
11
import { assertType } from '../../../../../base/common/types.js' ;
@@ -108,7 +107,9 @@ export async function showToolsPicker(
108
107
if ( ! toolsEntries ) {
109
108
const defaultEntries = new Map ( ) ;
110
109
for ( const tool of toolsService . getTools ( ) ) {
111
- defaultEntries . set ( tool , false ) ;
110
+ if ( tool . canBeReferencedInPrompt ) {
111
+ defaultEntries . set ( tool , false ) ;
112
+ }
112
113
}
113
114
for ( const toolSet of toolsService . toolSets . get ( ) ) {
114
115
defaultEntries . set ( toolSet , false ) ;
@@ -203,8 +204,8 @@ export async function showToolsPicker(
203
204
} else {
204
205
// stash the MCP toolset into the bucket item
205
206
bucket . toolset = toolSetOrTool ;
207
+ bucket . picked = picked ;
206
208
}
207
-
208
209
} else if ( toolSetOrTool . canBeReferencedInPrompt ) {
209
210
bucket . children . push ( {
210
211
parent : bucket ,
@@ -216,10 +217,6 @@ export async function showToolsPicker(
216
217
indented : true ,
217
218
} ) ;
218
219
}
219
-
220
- if ( picked ) {
221
- bucket . picked = true ;
222
- }
223
220
}
224
221
225
222
for ( const bucket of [ builtinBucket , userBucket ] ) {
@@ -228,6 +225,21 @@ export async function showToolsPicker(
228
225
}
229
226
}
230
227
228
+ // set the checkmarks in the UI:
229
+ // bucket is checked if at least one of the children is checked
230
+ // tool is checked if the bucket is checked or the tool itself is checked
231
+ for ( const bucket of toolBuckets . values ( ) ) {
232
+ if ( bucket . picked ) {
233
+ // check all children if the bucket is checked
234
+ for ( const child of bucket . children ) {
235
+ child . picked = true ;
236
+ }
237
+ } else {
238
+ // check the bucket if one of the children is checked
239
+ bucket . picked = bucket . children . some ( child => child . picked ) ;
240
+ }
241
+ }
242
+
231
243
const store = new DisposableStore ( ) ;
232
244
233
245
const picks : ( MyPick | IQuickPickSeparator ) [ ] = [ ] ;
@@ -385,22 +397,12 @@ export async function showToolsPicker(
385
397
386
398
store . dispose ( ) ;
387
399
388
- const mcpToolSets = new Set < ToolSet > ( ) ;
389
-
400
+ // in the result, a MCP toolset is only enabled if all tools in the toolset are enabled
390
401
for ( const item of toolsService . toolSets . get ( ) ) {
391
402
if ( item . source . type === 'mcp' ) {
392
- mcpToolSets . add ( item ) ;
393
-
394
- if ( Iterable . every ( item . getTools ( ) , tool => result . get ( tool ) ) ) {
395
- // ALL tools from the MCP tool set are here, replace them with just the toolset
396
- // but only when computing the final result
397
- for ( const tool of item . getTools ( ) ) {
398
- result . delete ( tool ) ;
399
- }
400
- result . set ( item , true ) ;
401
- }
403
+ const toolsInSet = Array . from ( item . getTools ( ) ) ;
404
+ result . set ( item , toolsInSet . every ( tool => result . get ( tool ) ) ) ;
402
405
}
403
406
}
404
-
405
407
return didAccept ? result : undefined ;
406
408
}
0 commit comments