Skip to content

Commit 2bfa873

Browse files
committed
refactor config to constants.ts
1 parent ea601c9 commit 2bfa873

File tree

3 files changed

+12
-26
lines changed

3 files changed

+12
-26
lines changed

packages/core/src/codewhisperer/models/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,3 +931,11 @@ export const testGenExcludePatterns = [
931931
'**/*.deb',
932932
'**/*.model',
933933
]
934+
935+
export const predictionTrackerDefaultConfig = {
936+
maxFiles: 25,
937+
maxTotalSizeKb: 50000,
938+
debounceIntervalMs: 2000,
939+
maxAgeMs: 30000,
940+
maxSupplementalContext: 15,
941+
}

packages/core/src/codewhisperer/nextEditPrediction/PredictionTracker.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import fs from '../../shared/fs/fs'
99
import { getLogger } from '../../shared/logger/logger'
1010
import * as diffGenerator from './diffContextGenerator'
1111
import * as codewhispererClient from '../client/codewhisperer'
12+
import { predictionTrackerDefaultConfig } from '../models/constants'
1213

1314
export interface FileTrackerConfig {
1415
/** Maximum number of files to track (default: 15) */
@@ -43,17 +44,8 @@ export class PredictionTracker {
4344
constructor(extensionContext: vscode.ExtensionContext, config?: Partial<FileTrackerConfig>) {
4445
getLogger().debug('Initializing PredictionTracker')
4546

46-
// Default configuration values
47-
const defaultConfig = {
48-
maxFiles: 25,
49-
maxTotalSizeKb: 50000,
50-
debounceIntervalMs: 2000,
51-
maxAgeMs: 30000, // 30 sec
52-
maxSupplementalContext: 15, // Default max supplemental contexts
53-
}
54-
5547
this.config = {
56-
...defaultConfig,
48+
...predictionTrackerDefaultConfig,
5749
...config,
5850
}
5951

@@ -62,9 +54,6 @@ export class PredictionTracker {
6254

6355
void this.ensureStorageDirectoryExists()
6456
void this.loadSnapshotsFromStorage()
65-
66-
// Schedule periodic cleanup
67-
// setInterval(() => this.cleanupOldSnapshots(), this.config.maxAgeMs / 2)
6857
}
6958

7059
public processEdit(document: vscode.TextDocument, previousContent: string): void {
@@ -112,11 +101,8 @@ export class PredictionTracker {
112101

113102
fileSnapshots.push(snapshot)
114103
this.snapshots.set(filePath, fileSnapshots)
115-
116-
// Update total size
117104
this.totalSize += size
118105

119-
// Enforce memory limits
120106
await this.enforceMemoryLimits()
121107

122108
// Set a timeout to delete the snapshot after maxAgeMs
@@ -162,14 +148,12 @@ export class PredictionTracker {
162148
continue
163149
}
164150

165-
// Remove the oldest snapshot
166151
const removedSnapshot = fileSnapshots.shift()
167152
if (removedSnapshot) {
168153
this.totalSize -= removedSnapshot.size
169154
await this.deleteSnapshotFromStorage(removedSnapshot)
170155
}
171156

172-
// If no snapshots left for this file, remove the file entry
173157
if (fileSnapshots.length === 0) {
174158
this.snapshots.delete(oldestFile)
175159
}

packages/core/src/codewhisperer/nextEditPrediction/diffContextGenerator.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ async function generateUnifiedDiffWithTimestamps(
4848
return patchResult
4949
}
5050

51-
/**
52-
* Interface for snapshot content with timestamp
53-
*/
5451
export interface SnapshotContent {
5552
filePath: string
5653
content: string
@@ -82,11 +79,8 @@ export async function generateDiffContexts(
8279
const supplementalContexts: codewhispererClient.SupplementalContext[] = []
8380
const currentTimestamp = Date.now()
8481

85-
// Create a copy of snapshots and reverse it so newest snapshots are processed first
86-
const sortedSnapshots = [...snapshotContents].reverse()
87-
88-
// Generate diffs between each snapshot and the current content
89-
for (const snapshot of sortedSnapshots) {
82+
for (let i = snapshotContents.length - 1; i >= 0; i--) {
83+
const snapshot = snapshotContents[i]
9084
try {
9185
const unifiedDiff = await generateUnifiedDiffWithTimestamps(
9286
snapshot.filePath,

0 commit comments

Comments
 (0)