Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
808d95e
Added Prediction folder, integrated with API, status bar visualier
tomcat323 Apr 18, 2025
ced1ec6
refactor supplemental context generation into diffGenerator
tomcat323 Apr 18, 2025
475c5dd
clean up pakcage.json
tomcat323 Apr 18, 2025
440c44e
update supplemental context logic according to science feedback
tomcat323 Apr 21, 2025
ea601c9
not include debug webview in release
tomcat323 Apr 21, 2025
2bfa873
refactor config to constants.ts
tomcat323 Apr 21, 2025
5aa4c51
added tests for prediction tracker
tomcat323 Apr 22, 2025
9cdb6f5
clean up
tomcat323 Apr 22, 2025
a371128
remove tracker dispose in activation
tomcat323 Apr 22, 2025
dabf670
remove unused imports
tomcat323 Apr 22, 2025
9476765
refactored filePath to getter functions
tomcat323 Apr 22, 2025
d233c0c
refactor load from storage, use reduce in getTotalCount
tomcat323 Apr 22, 2025
fa6b40b
remove predictionTypes from request
tomcat323 Apr 24, 2025
b935964
enforce supplemental context char limit
tomcat323 Apr 24, 2025
25cc9f9
address comments, deprecate fs usage, use in memory content tracking
tomcat323 Apr 28, 2025
18603fa
clean up logging, fix predictionTracker tests
tomcat323 Apr 29, 2025
6c3d6ab
Merge branch 'master' into NEP/DataInstrumentationLaunch
tomcat323 Apr 29, 2025
c683cb8
refactor paths for windows test fail
tomcat323 Apr 29, 2025
7d25d3f
fix uri path leading seperator
tomcat323 Apr 29, 2025
0446ccb
add more try-catch for error handling
tomcat323 Apr 30, 2025
1a9b305
remove unused maxfiles constant
tomcat323 Apr 30, 2025
4250b65
add tests for diff context generation
tomcat323 Apr 30, 2025
ed30502
Merge branch 'master' into NEP/DataInstrumentationLaunch
tomcat323 May 2, 2025
6261398
resolve merge conflict in settings
tomcat323 May 2, 2025
adfe12e
renamed files, removed redundent checks
tomcat323 May 5, 2025
092d0b7
Rename PredictionTracker.ts to predictionTracker.ts
tomcat323 May 5, 2025
71384d6
Rename PredictionKeyStrokeHandler.ts to predictionKeyStrokeHandler.ts
tomcat323 May 5, 2025
399d67d
Rename PredictionTracker.test.ts to predictionTracker.test.ts
tomcat323 May 5, 2025
d94891d
clean up
tomcat323 May 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/src/codewhisperer/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ import { SecurityIssueTreeViewProvider } from './service/securityIssueTreeViewPr
import { setContext } from '../shared/vscode/setContext'
import { syncSecurityIssueWebview } from './views/securityIssue/securityIssueWebview'
import { detectCommentAboveLine } from '../shared/utilities/commentUtils'
import { activateNextEditPrediction } from './nextEditPrediction/activation'

let localize: nls.LocalizeFunc

export async function activate(context: ExtContext): Promise<void> {
activateNextEditPrediction(context)
Copy link
Contributor

@nkomonen-amazon nkomonen-amazon Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I would move this to the bottom of the function since the beginning is for more general activation (eg auth).

  • Also I think it is better to have this in activateAmazonQCommon(). We want to move as much Q specific code in to their so that we can reduce our dependency on core. You may need to export this in one of the index.ts, see amazonQDiffScheme and how it is exported

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit : Lets scope the namining to EditTracking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this needs to have it's own index.ts and export it to QCommon, since it's not a stand-alone feature, but rather an addition on existing codeWhisper API flow. Will move it to the bottom of codeWhisper activation.

localize = nls.loadMessageBundle()

// Import old CodeWhisperer settings into Amazon Q
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/codewhisperer/models/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -931,3 +931,11 @@ export const testGenExcludePatterns = [
'**/*.deb',
'**/*.model',
]

export const predictionTrackerDefaultConfig = {
maxFiles: 25,
maxStorageSizeKb: 10000,
debounceIntervalMs: 2000,
maxAgeMs: 30000,
maxSupplementalContext: 15,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this these NEP modules live in the same dir as the other "trackers"?

https://github.com/aws/aws-toolkit-vscode/tree/master/packages/core/src/codewhisperer/tracker

are they really not sharing any concepts at all? this PR is all new code.

Copy link
Contributor Author

@tomcat323 tomcat323 Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not shared IMO, the existing tracker collects statistical metrics for telemetry, the NEP tracker tracks content changes. Their hyper parameters are also very different.

Since the new tracker is populating the supplementalContext field, maybe we can also consider https://github.com/aws/aws-toolkit-vscode/tree/master/packages/core/src/codewhisperer/util/supplementalContext?

* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import * as vscode from 'vscode'
import { getLogger } from '../../shared/logger/logger'
import { PredictionTracker } from './PredictionTracker'

/**
* Monitors document changes in the editor and track them for prediction.
*/
export class PredictionKeyStrokeHandler {
private disposables: vscode.Disposable[] = []
private tracker: PredictionTracker
private shadowCopies: Map<string, string> = new Map()

/**
* Creates a new PredictionKeyStrokeHandler
* @param context The extension context
* @param tracker The prediction tracker instance
* @param config Configuration options
*/
constructor(tracker: PredictionTracker) {
this.tracker = tracker

// Initialize shadow copies for currently visible editors when extension starts
this.initializeVisibleDocuments()

// Register event handlers
this.registerVisibleDocumentListener()
this.registerTextDocumentChangeListener()
}

/**
* Initializes shadow copies for all currently visible text editors
*/
private initializeVisibleDocuments(): void {
const editors = vscode.window.visibleTextEditors

for (const editor of editors) {
if (editor.document.uri.scheme === 'file') {
this.updateShadowCopy(editor.document)
}
}
}

/**
* Registers listeners for visibility events to maintain shadow copies of document content
*/
private registerVisibleDocumentListener(): void {
// Track when documents become visible (switched to)
const visibleDisposable = vscode.window.onDidChangeVisibleTextEditors((editors) => {
const currentVisibleFiles = new Set<string>()

// Update shadow copies for currently visible editors
for (const editor of editors) {
if (editor.document.uri.scheme === 'file') {
const filePath = editor.document.uri.fsPath
currentVisibleFiles.add(filePath)
this.updateShadowCopy(editor.document)
}
}

// Remove shadow copies for files that are no longer visible
for (const filePath of this.shadowCopies.keys()) {
if (!currentVisibleFiles.has(filePath)) {
this.shadowCopies.delete(filePath)
}
}
})

this.disposables.push(visibleDisposable)
}

private updateShadowCopy(document: vscode.TextDocument): void {
if (document.uri.scheme === 'file') {
this.shadowCopies.set(document.uri.fsPath, document.getText())
getLogger().debug(`Updated shadow copy for ${document.uri.fsPath}`)
}
}

/**
* Registers listener for text document changes to send to tracker
*/
private registerTextDocumentChangeListener(): void {
// Listen for document changes
const changeDisposable = vscode.workspace.onDidChangeTextDocument((event) => {
const filePath = event.document.uri.fsPath
const prevContent = this.shadowCopies.get(filePath)

// Skip if there are no content changes or if the file is not visible
// This avoids tracking bulk edits on non-visible files
if (
event.contentChanges.length === 0 ||
event.document.uri.scheme !== 'file' ||
prevContent === undefined
) {
return
}

this.tracker.processEdit(event.document, prevContent)
this.updateShadowCopy(event.document)
})

this.disposables.push(changeDisposable)
}

/**
* Disposes of all resources used by this handler
*/
public dispose(): void {
for (const disposable of this.disposables) {
disposable.dispose()
}
this.disposables = []
}
}
Loading
Loading