@@ -8,7 +8,15 @@ import * as commas from '../../api/core-main'
8
8
import { flatAsync , normalizeArray } from '../../shared/helper'
9
9
import { extractCommand , extractCommandEntries } from './command'
10
10
import type { FigContext } from './fig'
11
- import { aliasGenerator , commandGenerator , generateFigSpec , generateFigSuggestions , invalidateFigHistory } from './fig'
11
+ import {
12
+ createCommandWithFilepathsArg ,
13
+ createCurrentTokenGenerator ,
14
+ generateFigSpec ,
15
+ generateFigSuggestions ,
16
+ getFigSeparator ,
17
+ invalidateFigHistory ,
18
+ stepOnCommand ,
19
+ } from './fig'
12
20
import { memoizeAsync } from './helper'
13
21
import { BIN_PATH , loginExecute } from './shell'
14
22
@@ -59,12 +67,6 @@ function stripFigCursor(insertion: string) {
59
67
return insertion . slice ( 0 , index ) + suffix + '\u001b[D' . repeat ( suffix . length )
60
68
}
61
69
62
- function getFigSeparator ( spec : Fig . Option ) {
63
- return spec . requiresSeparator
64
- ? ( typeof spec . requiresSeparator === 'string' ? spec . requiresSeparator : '=' )
65
- : ( spec . requiresEquals ? '=' : undefined )
66
- }
67
-
68
70
function getFigValues ( spec : Fig . Subcommand | Fig . Suggestion | Fig . Option ) {
69
71
if ( spec . insertValue ) {
70
72
return [ stripFigCursor ( spec . insertValue ) ]
@@ -100,21 +102,22 @@ function getFigSuggestionType(spec: Fig.Suggestion): CommandCompletion['type'] {
100
102
case 'folder' :
101
103
return 'directory'
102
104
default :
103
- if ( 'context' in spec ) {
104
- const templateContext = ( spec as Fig . TemplateSuggestion ) . context
105
- switch ( templateContext . templateType ) {
106
- case 'filepaths' :
107
- return 'file'
108
- case 'folders ' :
109
- return 'directory '
110
- case 'history ' :
111
- return 'history '
112
- default :
113
- break
114
- }
115
- }
116
- return 'command'
105
+ break
106
+ }
107
+ if ( 'context' in spec ) {
108
+ const templateContext = ( spec as Fig . TemplateSuggestion ) . context
109
+ switch ( templateContext . templateType ) {
110
+ case 'filepaths ' :
111
+ return 'file '
112
+ case 'folders ' :
113
+ return 'directory '
114
+ case 'history' :
115
+ return 'history'
116
+ default :
117
+ break
118
+ }
117
119
}
120
+ return 'command'
118
121
}
119
122
120
123
function transformFigSuggestion ( raw : string | Fig . Suggestion , query : string , strict ?: boolean ) {
@@ -203,7 +206,8 @@ function getFigArgCompletions(spec: Fig.Subcommand | Fig.Option, query: string,
203
206
}
204
207
}
205
208
return flatAsync ( specArgs . map ( async arg => {
206
- const generators = [
209
+ const generators : Fig . Generator [ ] = [
210
+ ...( arg . suggestCurrentToken ? [ createCurrentTokenGenerator ( 'arg' ) ] : [ ] ) ,
207
211
...( arg . template ? [ { template : arg . template } ] : [ ] ) ,
208
212
...normalizeArray ( arg . generators ) ,
209
213
]
@@ -352,25 +356,13 @@ async function getCompletions(
352
356
// Commands
353
357
if ( ! command && ! / ^ ( .+ | ~ ) ? [ \\ / ] / . test ( query ) ) {
354
358
asyncCompletionLists . push (
355
- getFigCompletions ( {
356
- name : '' ,
357
- args : {
358
- name : 'command' ,
359
- generators : [ commandGenerator , aliasGenerator ] ,
360
- } ,
361
- } , query , args , figContext ) ,
359
+ getFigCompletions ( stepOnCommand , query , args , figContext ) ,
362
360
)
363
361
}
364
362
// Files
365
363
if ( ! isCommandLineArgument ( query ) && ( operator && operator . op === '>' || / [ \\ / ] / . test ( query ) ) ) {
366
364
asyncCompletionLists . push (
367
- getFigCompletions ( {
368
- name : command ,
369
- args : {
370
- name : 'file' ,
371
- template : 'filepaths' ,
372
- } ,
373
- } , query , args , figContext ) ,
365
+ getFigCompletions ( createCommandWithFilepathsArg ( command ) , query , args , figContext ) ,
374
366
)
375
367
}
376
368
}
0 commit comments