-
Notifications
You must be signed in to change notification settings - Fork 747
feat(nep): Data Instrumentation #7109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
808d95e
ced1ec6
475c5dd
440c44e
ea601c9
2bfa873
5aa4c51
9cdb6f5
a371128
dabf670
9476765
d233c0c
fa6b40b
b935964
25cc9f9
18603fa
6c3d6ab
c683cb8
7d25d3f
0446ccb
1a9b305
4250b65
ed30502
6261398
adfe12e
092d0b7
71384d6
399d67d
d94891d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,10 +95,13 @@ 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> { | ||
| // Activate the Next Edit Prediction system | ||
| activateNextEditPrediction(context) | ||
|
||
| localize = nls.loadMessageBundle() | ||
|
|
||
| // Import old CodeWhisperer settings into Amazon Q | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| /*! | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
jpinkney-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * 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') { | ||
jpinkney-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 = [] | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.