Skip to content

Commit 25cc9f9

Browse files
committed
address comments, deprecate fs usage, use in memory content tracking
1 parent b935964 commit 25cc9f9

File tree

9 files changed

+161
-406
lines changed

9 files changed

+161
-406
lines changed

packages/core/src/codewhisperer/activation.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,11 @@ import { SecurityIssueTreeViewProvider } from './service/securityIssueTreeViewPr
9595
import { setContext } from '../shared/vscode/setContext'
9696
import { syncSecurityIssueWebview } from './views/securityIssue/securityIssueWebview'
9797
import { detectCommentAboveLine } from '../shared/utilities/commentUtils'
98-
import { activateNextEditPrediction } from './nextEditPrediction/activation'
98+
import { activateEditTracking } from './nextEditPrediction/activation'
9999

100100
let localize: nls.LocalizeFunc
101101

102102
export async function activate(context: ExtContext): Promise<void> {
103-
activateNextEditPrediction(context)
104103
localize = nls.loadMessageBundle()
105104

106105
// Import old CodeWhisperer settings into Amazon Q
@@ -526,6 +525,8 @@ export async function activate(context: ExtContext): Promise<void> {
526525
})
527526
)
528527
}
528+
529+
activateEditTracking(context)
529530
}
530531

531532
export async function shutdown() {

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@ export class PredictionKeyStrokeHandler {
4747

4848
/**
4949
* Registers listeners for visibility events to maintain shadow copies of document content
50+
* Only store and update shadow copies for currently visible editors
51+
* And remove shadow copies for files that are no longer visible
52+
* And edits are processed only if a shadow copy exists
53+
* This avoids the memory problem if hidden files are bulk edited, i.e. with global find/replace
5054
*/
5155
private registerVisibleDocumentListener(): void {
5256
// Track when documents become visible (switched to)
5357
const visibleDisposable = vscode.window.onDidChangeVisibleTextEditors((editors) => {
5458
const currentVisibleFiles = new Set<string>()
5559

56-
// Update shadow copies for currently visible editors
5760
for (const editor of editors) {
5861
if (editor.document.uri.scheme === 'file') {
5962
const filePath = editor.document.uri.fsPath
@@ -62,7 +65,6 @@ export class PredictionKeyStrokeHandler {
6265
}
6366
}
6467

65-
// Remove shadow copies for files that are no longer visible
6668
for (const filePath of this.shadowCopies.keys()) {
6769
if (!currentVisibleFiles.has(filePath)) {
6870
this.shadowCopies.delete(filePath)
@@ -76,7 +78,7 @@ export class PredictionKeyStrokeHandler {
7678
private updateShadowCopy(document: vscode.TextDocument): void {
7779
if (document.uri.scheme === 'file') {
7880
this.shadowCopies.set(document.uri.fsPath, document.getText())
79-
getLogger().debug(`Updated shadow copy for ${document.uri.fsPath}`)
81+
getLogger('nextEditPrediction').debug(`Updated shadow copy for ${document.uri.fsPath}`)
8082
}
8183
}
8284

@@ -85,7 +87,7 @@ export class PredictionKeyStrokeHandler {
8587
*/
8688
private registerTextDocumentChangeListener(): void {
8789
// Listen for document changes
88-
const changeDisposable = vscode.workspace.onDidChangeTextDocument((event) => {
90+
const changeDisposable = vscode.workspace.onDidChangeTextDocument(async (event) => {
8991
const filePath = event.document.uri.fsPath
9092
const prevContent = this.shadowCopies.get(filePath)
9193

@@ -99,7 +101,7 @@ export class PredictionKeyStrokeHandler {
99101
return
100102
}
101103

102-
this.tracker.processEdit(event.document, prevContent)
104+
await this.tracker.processEdit(event.document, prevContent)
103105
this.updateShadowCopy(event.document)
104106
})
105107

0 commit comments

Comments
 (0)