@@ -7,6 +7,7 @@ import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../../base/
7
7
import { TerminalCompletionModel } from '../../browser/terminalCompletionModel.js' ;
8
8
import { LineContext } from '../../../../../services/suggest/browser/simpleCompletionModel.js' ;
9
9
import { TerminalCompletionItem , TerminalCompletionItemKind , type ITerminalCompletion } from '../../browser/terminalCompletionItem.js' ;
10
+ import type { CompletionItemLabel } from '../../../../../services/suggest/browser/simpleCompletionItem.js' ;
10
11
11
12
function createItem ( options : Partial < ITerminalCompletion > ) : TerminalCompletionItem {
12
13
return new TerminalCompletionItem ( {
@@ -41,7 +42,7 @@ function createFolderItemsModel(...labels: string[]): TerminalCompletionModel {
41
42
) ;
42
43
}
43
44
44
- function assertItems ( model : TerminalCompletionModel , labels : string [ ] ) : void {
45
+ function assertItems ( model : TerminalCompletionModel , labels : ( string | CompletionItemLabel ) [ ] ) : void {
45
46
assert . deepStrictEqual ( model . items . map ( i => i . completion . label ) , labels ) ;
46
47
assert . strictEqual ( model . items . length , labels . length ) ; // sanity check
47
48
}
@@ -300,64 +301,58 @@ suite('TerminalCompletionModel', function () {
300
301
suite ( 'git branch priority sorting' , ( ) => {
301
302
test ( 'should prioritize main and master branches for git commands' , ( ) => {
302
303
const items = [
303
- createItem ( { label : 'feature-branch' , provider : 'terminal-suggest' } ) ,
304
- createItem ( { label : 'master' , provider : 'terminal-suggest' } ) ,
305
- createItem ( { label : 'development' , provider : 'terminal-suggest' } ) ,
306
- createItem ( { label : 'main' , provider : 'terminal-suggest' } )
304
+ createItem ( { label : 'feature-branch' } ) ,
305
+ createItem ( { label : 'master' } ) ,
306
+ createItem ( { label : 'development' } ) ,
307
+ createItem ( { label : 'main' } )
307
308
] ;
308
309
const model = new TerminalCompletionModel ( items , new LineContext ( 'git checkout ' , 0 ) ) ;
309
310
assertItems ( model , [ 'main' , 'master' , 'development' , 'feature-branch' ] ) ;
310
311
} ) ;
311
312
312
313
test ( 'should prioritize main and master branches for git switch command' , ( ) => {
313
314
const items = [
314
- createItem ( { label : 'feature-branch' , provider : 'terminal-suggest' } ) ,
315
- createItem ( { label : 'main' , provider : 'terminal-suggest' } ) ,
316
- createItem ( { label : 'another-feature' , provider : 'terminal-suggest' } ) ,
317
- createItem ( { label : 'master' , provider : 'terminal-suggest' } )
315
+ createItem ( { label : 'feature-branch' } ) ,
316
+ createItem ( { label : 'main' } ) ,
317
+ createItem ( { label : 'another-feature' } ) ,
318
+ createItem ( { label : 'master' } )
318
319
] ;
319
320
const model = new TerminalCompletionModel ( items , new LineContext ( 'git switch ' , 0 ) ) ;
320
321
assertItems ( model , [ 'main' , 'master' , 'another-feature' , 'feature-branch' ] ) ;
321
322
} ) ;
322
323
323
324
test ( 'should not prioritize main and master for non-git commands' , ( ) => {
324
325
const items = [
325
- createItem ( { label : 'feature-branch' , provider : 'terminal-suggest' } ) ,
326
- createItem ( { label : 'master' , provider : 'terminal-suggest' } ) ,
327
- createItem ( { label : 'main' , provider : 'terminal-suggest' } )
326
+ createItem ( { label : 'feature-branch' } ) ,
327
+ createItem ( { label : 'master' } ) ,
328
+ createItem ( { label : 'main' } )
328
329
] ;
329
330
const model = new TerminalCompletionModel ( items , new LineContext ( 'ls ' , 0 ) ) ;
330
331
assertItems ( model , [ 'feature-branch' , 'main' , 'master' ] ) ;
331
332
} ) ;
332
333
333
- test ( 'should only apply to terminal-suggest provider' , ( ) => {
334
- const items = [
335
- createItem ( { label : 'feature-branch' , provider : 'other-provider' } ) ,
336
- createItem ( { label : 'master' , provider : 'other-provider' } ) ,
337
- createItem ( { label : 'main' , provider : 'other-provider' } )
338
- ] ;
339
- const model = new TerminalCompletionModel ( items , new LineContext ( 'git checkout ' , 0 ) ) ;
340
- assertItems ( model , [ 'feature-branch' , 'main' , 'master' ] ) ;
341
- } ) ;
342
-
343
334
test ( 'should handle git commands with leading whitespace' , ( ) => {
344
335
const items = [
345
- createItem ( { label : 'feature-branch' , provider : 'terminal-suggest' } ) ,
346
- createItem ( { label : 'master' , provider : 'terminal-suggest' } ) ,
347
- createItem ( { label : 'main' , provider : 'terminal-suggest' } )
336
+ createItem ( { label : 'feature-branch' } ) ,
337
+ createItem ( { label : 'master' } ) ,
338
+ createItem ( { label : 'main' } )
348
339
] ;
349
340
const model = new TerminalCompletionModel ( items , new LineContext ( ' git checkout ' , 0 ) ) ;
350
341
assertItems ( model , [ 'main' , 'master' , 'feature-branch' ] ) ;
351
342
} ) ;
352
343
353
344
test ( 'should work with complex label objects' , ( ) => {
354
345
const items = [
355
- createItem ( { label : { label : 'feature-branch' , description : 'Feature branch' } , provider : 'terminal-suggest' } ) ,
356
- createItem ( { label : { label : 'master' , description : 'Master branch' } , provider : 'terminal-suggest' } ) ,
357
- createItem ( { label : { label : 'main' , description : 'Main branch' } , provider : 'terminal-suggest' } )
346
+ createItem ( { label : { label : 'feature-branch' , description : 'Feature branch' } } ) ,
347
+ createItem ( { label : { label : 'master' , description : 'Master branch' } } ) ,
348
+ createItem ( { label : { label : 'main' , description : 'Main branch' } } )
358
349
] ;
359
350
const model = new TerminalCompletionModel ( items , new LineContext ( 'git checkout ' , 0 ) ) ;
360
- assertItems ( model , [ 'main' , 'master' , 'feature-branch' ] ) ;
351
+ assertItems ( model , [
352
+ { label : "main" , description : "Main branch" } ,
353
+ { label : "master" , description : "Master branch" } ,
354
+ { label : "feature-branch" , description : "Feature branch" } ,
355
+ ] ) ;
361
356
} ) ;
362
357
} ) ;
363
358
} ) ;
0 commit comments