Skip to content

Conversation

@MarcoWang3
Copy link
Contributor

@MarcoWang3 MarcoWang3 commented Jul 14, 2025

Problem

The previous diff animation system is totally based on the VSC side to detect the file change events and render the diffAnimation. So all the diff animations can be only rendered after the codes are generated. Previous version uses customized webview for rendering the diff animation.

Solution

Update the mechanism of the current diff animation system: receive stream chunks from the language servers side and render partial diff animation based on them for fsWrite events. Receive a complete chunk for fsReplace and render diff animation line by line. Use VSC's built in diffview for rendering the diff animations.

Demo

create.a.file.mov
edit.a.file.mov

- Add messages.ts with streaming diff animation support
- Add complete diffAnimation module with:
  - Animation queue management
  - Chat processing capabilities
  - Diff analysis and animation control
  - File system management
  - VSCode integration
  - Webview management
  - Streaming diff controller
@github-actions
Copy link

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.

@MarcoWang3 MarcoWang3 changed the title Feature/streaming diff animation feature:streaming diff animation Jul 14, 2025
@MarcoWang3 MarcoWang3 closed this Jul 14, 2025
@MarcoWang3 MarcoWang3 reopened this Jul 14, 2025
@github-actions
Copy link

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.
  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

@MarcoWang3 MarcoWang3 closed this Jul 14, 2025
@MarcoWang3 MarcoWang3 changed the title feature:streaming diff animation feat:streaming diff animation Jul 14, 2025
@MarcoWang3 MarcoWang3 reopened this Jul 14, 2025
@MarcoWang3 MarcoWang3 changed the title feat:streaming diff animation feat(amazonq):streaming diff animation Jul 14, 2025
@MarcoWang3 MarcoWang3 closed this Jul 14, 2025
@MarcoWang3 MarcoWang3 reopened this Jul 14, 2025
- Eliminated duplicate temp file creation and diff view opening logic in StreamingDiffController
- Consolidated session creation logic in DiffAnimationHandler
- Created reusable cleanup helper function in Messages
- Removed duplicate getCursorState function
- Reduced codebase by 53+ lines of duplicate code
@MarcoWang3 MarcoWang3 closed this Jul 14, 2025
@MarcoWang3 MarcoWang3 reopened this Jul 14, 2025
- Created comprehensive test suite for StreamingDiffController, DiffAnimationHandler, and AnimationQueueManager
- Tests cover initialization, session management, content streaming, and queue operations
- Uses Mocha/Sinon testing framework consistent with existing codebase
- Includes sanity tests to improve code coverage for Codecov requirements
- Update diffAnimationHandler for better streaming control
- Enhance streamingDiffController with improved state management
- Refactor chat messages handling for diff animations
@MarcoWang3 MarcoWang3 changed the base branch from master to feature/code-diff August 1, 2025 20:20
@MarcoWang3 MarcoWang3 changed the base branch from feature/code-diff to master August 4, 2025 08:18
@MarcoWang3 MarcoWang3 changed the base branch from master to feature/code-diff August 4, 2025 08:19
@MarcoWang3 MarcoWang3 force-pushed the feature/StreamingDiffAnimation branch from 467e84b to d906edf Compare August 4, 2025 08:29
@MarcoWang3 MarcoWang3 marked this pull request as ready for review August 4, 2025 15:59
@MarcoWang3 MarcoWang3 requested a review from a team as a code owner August 4, 2025 15:59
* Clean up all temporary files for a chat session
*/
async cleanupChatSession(): Promise<void> {
const tempFilesToCleanup: string[] = []
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

    const tempFilePaths: string[] = [];
    
    // Collect from active streaming sessions
    this.activeStreamingSessions.forEach(session => {
        if (session.tempFilePath) {
            tempFilePaths.push(session.tempFilePath);
        }
    });

    // Collect from fs replace sessions
    this.fsReplaceSessionsByFile.forEach(session => {
        if (session.tempFilePath) {
            tempFilePaths.push(session.tempFilePath);
        }
    });


languageClient.onNotification(chatUpdateNotificationType.method, (params: ChatUpdateParams) => {
languageClient.onNotification(chatUpdateNotificationType.method, async (params: ChatUpdateParams) => {
if ((params.data as any)?.streamingChunk) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this to separate function or file to make this more readable?

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 have moved the streaming chunk processing logic to a seperate function!

streamingChunk.isComplete || false
)

if (streamingChunk.isComplete) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid nested if statements?
Something like this?

if (!streamingChunk.isComplete || !streamingChunk.filePath) {
        return;
    }

    const toolUseIds = initializingStreamsByFile.get(streamingChunk.filePath);
    if (!toolUseIds) {
        return;
    }

    toolUseIds.delete(streamingChunk.toolUseId);
    
    if (toolUseIds.size === 0) {
        initializingStreamsByFile.delete(streamingChunk.filePath);
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

Applies to above code too

@laileni-aws laileni-aws self-requested a review August 6, 2025 00:33
@MarcoWang3 MarcoWang3 force-pushed the feature/StreamingDiffAnimation branch from 96ced1d to 120aba1 Compare August 6, 2025 17:14
* Scroll editor to line
*/
private scrollEditorToLine(editor: vscode.TextEditor, line: number): void {
const scrollLine = line
Copy link
Contributor

Choose a reason for hiding this comment

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

We dont need this?

session.activeLineController.clear()

// Save the temp file one final time
const diffEditor = session.activeDiffEditor
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not required var?

private async cleanupSessions(toolUseIds: Set<string>): Promise<void> {
for (const toolUseId of toolUseIds) {
const sessionToCleanup = this.activeStreamingSessions.get(toolUseId)
if (sessionToCleanup) {
Copy link
Contributor

Choose a reason for hiding this comment

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

but:
Can add continue here!

@MarcoWang3 MarcoWang3 requested a review from laileni-aws August 7, 2025 21:43

const processedChunks = new Map<string, Set<string>>() // toolUseId -> Set of content hashes

// Initialize DiffAnimationHandler
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sometimes there are duplicated chunks are received and this is used for avoiding process them for multiple times

/**
* Handle streaming chunk processing for diff animations
*/
async function handleStreamingChunk(
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move this function to another class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@ashishrp-aws ashishrp-aws merged commit 117cded into aws:feature/code-diff Aug 13, 2025
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants