@@ -232,7 +232,7 @@ export default function nvimGitRebaseTodo(plugin: NvimPlugin): void {
232
232
return committish ;
233
233
} ;
234
234
235
- let count : number = 0 ;
235
+ let gParseStatCount : number = 0 ;
236
236
/**
237
237
* TODO consider an option where we precompute stats for all commits,
238
238
* set the window to the the longest height out of them,
@@ -267,30 +267,47 @@ export default function nvimGitRebaseTodo(plugin: NvimPlugin): void {
267
267
? [ ]
268
268
: x . stdout . split ( "\n" )
269
269
) ;
270
+
271
+ gParseStatCount ++ ;
272
+
270
273
if ( ! stat . length ) {
271
274
return [ ] ;
272
275
}
273
276
274
- if ( config . showStatParsingCount ) {
275
- stat . unshift ( ( count ++ ) . toString ( ) ) ;
276
- }
277
-
278
277
return stat ;
279
278
} ;
280
279
281
280
type Committish = string | null ;
282
281
type State = {
283
282
committish : Committish ;
283
+
284
+ /**
285
+ * will not include the extra "informational" lines;
286
+ * use `getExtraInfoLines` for that.
287
+ */
284
288
lines : string [ ] ;
289
+
285
290
width : number ;
286
291
height : number ;
287
292
} ;
293
+ type CommitStateOpts = {
294
+ isCacheHit : boolean ; //
295
+ } ;
288
296
289
297
let prevState : State | null = null ;
290
298
const committishToStatCache : Map < NonNullable < Committish > , State > = new Map ( ) ;
291
- const commitState = ( state : State ) : Promise < State > =>
299
+ const commitState = (
300
+ state : State ,
301
+ {
302
+ isCacheHit = false , //
303
+ } : Partial < CommitStateOpts > = { }
304
+ ) : Promise < State > =>
292
305
Promise . resolve ( )
293
- . then ( ( ) => updateBuffer ( state . lines ) )
306
+ . then ( ( ) : string [ ] => [
307
+ ...getExtraInfoLines ( { isCacheHit } ) ,
308
+ ...state . lines , // do not mutate state.lines
309
+ ] )
310
+ . then ( ( lines ) => updateBuffer ( lines ) )
294
311
. then ( ( buffer ) =>
295
312
updateWindow ( {
296
313
buffer, //
@@ -301,6 +318,19 @@ export default function nvimGitRebaseTodo(plugin: NvimPlugin): void {
301
318
. then ( ( ) => state . committish && committishToStatCache . set ( state . committish , state ) )
302
319
. then ( ( ) => ( prevState = state ) ) ;
303
320
321
+ function getExtraInfoLines ( opts : CommitStateOpts ) : string [ ] {
322
+ const extra : string [ ] = [ ] ;
323
+
324
+ if ( config . showStatParsingCount ) {
325
+ extra . push ( gParseStatCount . toString ( ) ) ;
326
+ }
327
+ if ( config . showCacheHitOrMiss && opts . isCacheHit ) {
328
+ extra . push ( "cache hit" ) ;
329
+ }
330
+
331
+ return extra ;
332
+ }
333
+
304
334
const drawLinesOfCommittishStat = async ( ) : Promise < State > => {
305
335
const committish : Committish = await getCommittishOfCurrentLine ( ) ;
306
336
@@ -319,17 +349,9 @@ export default function nvimGitRebaseTodo(plugin: NvimPlugin): void {
319
349
320
350
let tmp : State | undefined ;
321
351
if ( ( tmp = committishToStatCache . get ( committish ) ) ) {
322
- if ( ! config . showCacheHitOrMiss ) {
323
- return commitState ( tmp ) ;
324
- }
325
-
326
- const cacheHit = "cache hit" ;
327
- if ( ! tmp . lines [ 0 ] . includes ( cacheHit ) ) {
328
- tmp . lines . unshift ( "" ) ;
329
- }
330
- tmp . lines [ 0 ] = cacheHit ;
331
-
332
- return commitState ( tmp ) ;
352
+ return commitState ( tmp , {
353
+ isCacheHit : true , //
354
+ } ) ;
333
355
}
334
356
335
357
const stat : string [ ] = await getStatLines ( committish ) ;
0 commit comments