@@ -7,16 +7,14 @@ import * as vscode from 'vscode'
77import * as path from 'path'
88import fs from '../../shared/fs/fs'
99import { getLogger } from '../../shared/logger/logger'
10- import { DiffGenerator } from './diffGenerator'
10+ import * as diffGenerator from './diffGenerator'
1111import * as codewhispererClient from '../client/codewhisperer'
1212
1313export interface FileTrackerConfig {
1414 /** Maximum number of files to track (default: 15) */
1515 maxFiles : number
1616 /** Maximum total size in kilobytes (default: 200) */
1717 maxTotalSizeKb : number
18- /** Maximum size per file in kilobytes */
19- maxFileSizeKb : number
2018 /** Debounce interval in milliseconds (default: 2000) */
2119 debounceIntervalMs : number
2220 /** Maximum age of snapshots in milliseconds (default: 30000) */
@@ -49,7 +47,6 @@ export class PredictionTracker {
4947 const defaultConfig = {
5048 maxFiles : 25 ,
5149 maxTotalSizeKb : 50000 ,
52- maxFileSizeKb : 100 , // Default max size per file
5350 debounceIntervalMs : 2000 ,
5451 maxAgeMs : 30000 , // 30 sec
5552 maxSupplementalContext : 15 , // Default max supplemental contexts
@@ -90,12 +87,6 @@ export class PredictionTracker {
9087 const content = previousContent
9188 const size = Buffer . byteLength ( content , 'utf8' )
9289
93- // Skip if the file is too large
94- if ( size > this . config . maxFileSizeKb * 1024 ) {
95- getLogger ( ) . info ( `File ${ filePath } exceeds maximum size limit` )
96- return
97- }
98-
9990 const timestamp = Date . now ( )
10091 const storageKey = this . generateStorageKey ( filePath , timestamp )
10192
@@ -291,7 +282,7 @@ export class PredictionTracker {
291282 throw new Error ( 'Storage path not available' )
292283 }
293284
294- const snapshotsDir = path . join ( this . storagePath , 'file-snapshots' )
285+ const snapshotsDir = path . join ( this . storagePath , 'AmazonQ- file-snapshots' )
295286 if ( ! ( await fs . existsDir ( snapshotsDir ) ) ) {
296287 await fs . mkdir ( snapshotsDir )
297288 }
@@ -309,7 +300,7 @@ export class PredictionTracker {
309300 return
310301 }
311302
312- const snapshotsDir = path . join ( this . storagePath , 'file-snapshots' )
303+ const snapshotsDir = path . join ( this . storagePath , 'AmazonQ- file-snapshots' )
313304 const filePath = path . join ( snapshotsDir , `${ snapshot . storageKey } .content` )
314305
315306 if ( await fs . exists ( filePath ) ) {
@@ -331,7 +322,7 @@ export class PredictionTracker {
331322 throw new Error ( 'Storage path not available' )
332323 }
333324
334- const snapshotsDir = path . join ( this . storagePath , 'file-snapshots' )
325+ const snapshotsDir = path . join ( this . storagePath , 'AmazonQ- file-snapshots' )
335326 const filePath = path . join ( snapshotsDir , `${ snapshot . storageKey } .content` )
336327
337328 try {
@@ -346,8 +337,6 @@ export class PredictionTracker {
346337 * Generates unified diffs between adjacent snapshots of a file
347338 * and between the newest snapshot and the current file content
348339 *
349- * @param filePath Path to the file for which diffs should be generated
350- * @param currentContent Current content of the file to compare with the latest snapshot
351340 * @returns Array of SupplementalContext objects containing diffs between snapshots and current content
352341 */
353342 public async generatePredictionSupplementalContext ( ) : Promise < codewhispererClient . SupplementalContext [ ] > {
@@ -357,97 +346,44 @@ export class PredictionTracker {
357346 }
358347 const filePath = activeEditor . document . uri . fsPath
359348 const currentContent = activeEditor . document . getText ( )
349+
360350 // Get all snapshots for this file
361351 const snapshots = this . getFileSnapshots ( filePath )
362352
363353 if ( snapshots . length === 0 ) {
364354 return [ ]
365355 }
366356
367- // Sort snapshots by timestamp (oldest first)
368- const sortedSnapshots = [ ...snapshots ] . sort ( ( a , b ) => a . timestamp - b . timestamp )
369- const supplementalContexts : codewhispererClient . SupplementalContext [ ] = [ ]
370- const currentTimestamp = Date . now ( )
371-
372- // Generate diffs between adjacent snapshots
373- for ( let i = 0 ; i < sortedSnapshots . length - 1 ; i ++ ) {
374- const oldSnapshot = sortedSnapshots [ i ]
375- const newSnapshot = sortedSnapshots [ i + 1 ]
376-
377- try {
378- const oldContent = await this . getSnapshotContent ( oldSnapshot )
379- const newContent = await this . getSnapshotContent ( newSnapshot )
380-
381- const diff = await DiffGenerator . generateUnifiedDiffWithTimestamps (
382- oldSnapshot . filePath ,
383- newSnapshot . filePath ,
384- oldContent ,
385- newContent ,
386- oldSnapshot . timestamp ,
387- newSnapshot . timestamp
388- )
389-
390- supplementalContexts . push ( {
391- filePath : oldSnapshot . filePath ,
392- content : diff ,
393- type : 'PreviousEditorState' ,
394- metadata : {
395- previousEditorStateMetadata : {
396- timeOffset : currentTimestamp - oldSnapshot . timestamp ,
397- } ,
398- } ,
399- } )
400- } catch ( err ) {
401- getLogger ( ) . error ( `Failed to generate diff: ${ err } ` )
402- }
403- }
404-
405- // Generate diff between the newest snapshot and the current file content
406- if ( sortedSnapshots . length > 0 ) {
407- const newestSnapshot = sortedSnapshots [ sortedSnapshots . length - 1 ]
408-
357+ // Load all snapshot contents
358+ const snapshotContents : diffGenerator . SnapshotContent [ ] = [ ]
359+ for ( const snapshot of snapshots ) {
409360 try {
410- // Need to temporarily save files to compare
411- const newestContent = await this . getSnapshotContent ( newestSnapshot )
412-
413- const diff = await DiffGenerator . generateUnifiedDiffWithTimestamps (
414- newestSnapshot . filePath ,
415- newestSnapshot . filePath ,
416- newestContent ,
417- currentContent ,
418- newestSnapshot . timestamp ,
419- currentTimestamp
420- )
421-
422- supplementalContexts . push ( {
423- filePath : newestSnapshot . filePath ,
424- content : diff ,
425- type : 'PreviousEditorState' ,
426- metadata : {
427- previousEditorStateMetadata : {
428- timeOffset : currentTimestamp - newestSnapshot . timestamp ,
429- } ,
430- } ,
361+ const content = await this . getSnapshotContent ( snapshot )
362+ snapshotContents . push ( {
363+ filePath : snapshot . filePath ,
364+ content,
365+ timestamp : snapshot . timestamp ,
431366 } )
432367 } catch ( err ) {
433- getLogger ( ) . error ( `Failed to generate diff with current content: ${ err } ` )
368+ getLogger ( ) . error ( `Failed to load snapshot content: ${ err } ` )
434369 }
435370 }
436371
437- // Limit the number of supplemental contexts based on config
438- if ( supplementalContexts . length > this . config . maxSupplementalContext ) {
439- return supplementalContexts . slice ( - this . config . maxSupplementalContext )
440- }
441-
442- return supplementalContexts
372+ // Use the diffGenerator module to generate supplemental contexts
373+ return diffGenerator . generateDiffContexts (
374+ filePath ,
375+ currentContent ,
376+ snapshotContents ,
377+ this . config . maxSupplementalContext
378+ )
443379 }
444380
445381 private async ensureStorageDirectoryExists ( ) : Promise < void > {
446382 if ( ! this . storagePath ) {
447383 return
448384 }
449385
450- const snapshotsDir = path . join ( this . storagePath , 'file-snapshots' )
386+ const snapshotsDir = path . join ( this . storagePath , 'AmazonQ- file-snapshots' )
451387 if ( ! ( await fs . existsDir ( snapshotsDir ) ) ) {
452388 await fs . mkdir ( snapshotsDir )
453389 }
@@ -458,7 +394,7 @@ export class PredictionTracker {
458394 return
459395 }
460396
461- const snapshotsDir = path . join ( this . storagePath , 'file-snapshots' )
397+ const snapshotsDir = path . join ( this . storagePath , 'AmazonQ- file-snapshots' )
462398 if ( ! ( await fs . existsDir ( snapshotsDir ) ) ) {
463399 return
464400 }
0 commit comments