@@ -17,12 +17,15 @@ interface IParameter {
17
17
18
18
const DEFAULT_WORD_TO_AUTOCOMPLETE : string = '' ;
19
19
const DEFAULT_POSITION : number = 0 ;
20
+
21
+ interface IActionMap {
22
+ [ actionName : string ] : IParameter [ ] ;
23
+ }
24
+
20
25
export class TabCompleteAction extends BaseRushAction {
21
26
private _wordToCompleteParameter : CommandLineStringParameter ;
22
27
private _positionParameter : CommandLineIntegerParameter ;
23
28
24
- private static _actions : { [ actionName : string ] : IParameter [ ] } = { } ;
25
-
26
29
public constructor ( parser : RushCommandLineParser ) {
27
30
super ( {
28
31
actionName : 'tab-complete' ,
@@ -59,6 +62,7 @@ export class TabCompleteAction extends BaseRushAction {
59
62
}
60
63
61
64
public * _getCompletions ( commandLine : string , caretPosition : number ) : IterableIterator < string > {
65
+ const actions : IActionMap = { } ;
62
66
this . parser . actions . forEach ( ( element ) => {
63
67
const actionParameters : IParameter [ ] = [ ] ;
64
68
element . parameters . forEach ( ( elem ) => {
@@ -67,13 +71,13 @@ export class TabCompleteAction extends BaseRushAction {
67
71
actionParameters . push ( { name : elem . shortName , kind : elem . kind } ) ;
68
72
}
69
73
} ) ;
70
- TabCompleteAction . _actions [ element . actionName ] = actionParameters ;
74
+ actions [ element . actionName ] = actionParameters ;
71
75
} ) ;
72
76
73
- TabCompleteAction . _actions [ '-d' ] = [ ] ;
74
- TabCompleteAction . _actions [ '--debug' ] = [ ] ;
75
- TabCompleteAction . _actions [ '-h' ] = [ ] ;
76
- TabCompleteAction . _actions [ '--help' ] = [ ] ;
77
+ actions [ '-d' ] = [ ] ;
78
+ actions [ '--debug' ] = [ ] ;
79
+ actions [ '-h' ] = [ ] ;
80
+ actions [ '--help' ] = [ ] ;
77
81
78
82
// yield ('arg count: ' + process.argv.length);
79
83
@@ -82,7 +86,7 @@ export class TabCompleteAction extends BaseRushAction {
82
86
// }
83
87
84
88
if ( ! commandLine || ! caretPosition ) {
85
- yield * this . _getAllActions ( ) ;
89
+ yield * Object . keys ( actions ) ; // return all actions
86
90
return ;
87
91
}
88
92
@@ -98,7 +102,7 @@ export class TabCompleteAction extends BaseRushAction {
98
102
const debugParameterOffset : number = debugParameterUsed ? 1 : 0 ; // if debug switch is used, then offset everything by 1.
99
103
100
104
if ( commands . length < 2 + debugParameterOffset ) {
101
- yield * this . _getAllActions ( ) ;
105
+ yield * Object . keys ( actions ) ; // return all actions
102
106
return ;
103
107
}
104
108
@@ -110,13 +114,13 @@ export class TabCompleteAction extends BaseRushAction {
110
114
const completePartialWord : boolean = caretPosition === commandLine . length ;
111
115
112
116
if ( completePartialWord && commands . length === 2 + debugParameterOffset ) {
113
- for ( const actionName of Object . keys ( TabCompleteAction . _actions ) ) {
117
+ for ( const actionName of Object . keys ( actions ) ) {
114
118
if ( actionName . indexOf ( commands [ 1 + debugParameterOffset ] ) === 0 ) {
115
119
yield actionName ;
116
120
}
117
121
}
118
122
} else {
119
- for ( const actionName of Object . keys ( TabCompleteAction . _actions ) ) {
123
+ for ( const actionName of Object . keys ( actions ) ) {
120
124
if ( actionName === commands [ 1 + debugParameterOffset ] ) {
121
125
if ( actionName === 'build' || actionName === 'rebuild' ) {
122
126
const choiceParameter : string [ ] = [ '-f' , '--from' , '-t' , '--to' ] ;
@@ -156,24 +160,24 @@ export class TabCompleteAction extends BaseRushAction {
156
160
}
157
161
158
162
if ( completePartialWord ) {
159
- for ( let i : number = 0 ; i < TabCompleteAction . _actions [ actionName ] . length ; i ++ ) {
160
- if ( TabCompleteAction . _actions [ actionName ] [ i ] . name . indexOf ( lastCommand ) === 0 ) {
161
- yield TabCompleteAction . _actions [ actionName ] [ i ] . name ;
163
+ for ( let i : number = 0 ; i < actions [ actionName ] . length ; i ++ ) {
164
+ if ( actions [ actionName ] [ i ] . name . indexOf ( lastCommand ) === 0 ) {
165
+ yield actions [ actionName ] [ i ] . name ;
162
166
}
163
167
}
164
168
} else {
165
- for ( let i : number = 0 ; i < TabCompleteAction . _actions [ actionName ] . length ; i ++ ) {
169
+ for ( let i : number = 0 ; i < actions [ actionName ] . length ; i ++ ) {
166
170
if (
167
- lastCommand === TabCompleteAction . _actions [ actionName ] [ i ] . name &&
168
- TabCompleteAction . _actions [ actionName ] [ i ] . kind !== CommandLineParameterKind . Flag
171
+ lastCommand === actions [ actionName ] [ i ] . name &&
172
+ actions [ actionName ] [ i ] . kind !== CommandLineParameterKind . Flag
169
173
) {
170
174
// The parameter is expecting a value, so don't suggest parameter names again
171
175
return ;
172
176
}
173
177
}
174
178
175
- for ( let i : number = 0 ; i < TabCompleteAction . _actions [ actionName ] . length ; i ++ ) {
176
- yield TabCompleteAction . _actions [ actionName ] [ i ] . name ;
179
+ for ( let i : number = 0 ; i < actions [ actionName ] . length ; i ++ ) {
180
+ yield actions [ actionName ] [ i ] . name ;
177
181
}
178
182
}
179
183
}
@@ -198,16 +202,8 @@ export class TabCompleteAction extends BaseRushAction {
198
202
}
199
203
} else {
200
204
if ( choiceParameter . indexOf ( lastCommand ) !== - 1 ) {
201
- for ( let i : number = 0 ; i < choiceParamaterValues . length ; i ++ ) {
202
- yield choiceParamaterValues [ i ] ;
203
- }
205
+ yield * choiceParamaterValues ;
204
206
}
205
207
}
206
208
}
207
-
208
- private * _getAllActions ( ) : IterableIterator < string > {
209
- for ( const actionName of Object . keys ( TabCompleteAction . _actions ) ) {
210
- yield actionName ;
211
- }
212
- }
213
209
}
0 commit comments