Skip to content
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

Fix chat streaming bug #299

Merged
merged 2 commits into from
Dec 10, 2024
Merged

Fix chat streaming bug #299

merged 2 commits into from
Dec 10, 2024

Conversation

taldekar
Copy link
Contributor

@taldekar taldekar commented Dec 5, 2024

Issue #295

Description of changes:

  • Introduced a CompletableFuture for the ChatUiRequestListener to manage asynchronous operations more effectively.
  • Implemented a chain of thenApply calls on the CompletableFuture to process streaming messages sequentially.
  • This approach ensures that each message in the stream is properly handled, even if the Amazon Q view is closed unexpectedly during the streaming process.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@@ -148,8 +149,7 @@ private ChatRequestParams addEditorState(final ChatRequestParams chatRequestPara
// only include files that are accessible via lsp which have absolute paths
getOpenFileUri().ifPresent(filePathUri -> {
chatRequestParams.setTextDocument(new TextDocumentIdentifier(filePathUri));
getSelectionRangeCursorState()
.ifPresent(cursorState -> chatRequestParams.setCursorState(Arrays.asList(cursorState)));
getSelectionRangeCursorState().ifPresent(cursorState -> chatRequestParams.setCursorState(Arrays.asList(cursorState)));
Copy link
Contributor

Choose a reason for hiding this comment

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

please revert any formatting changes in this PR. That takes away time from reviewing the actual change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, will do. Sorry!

chatUiRequestListener.onSendToChatUi(message);
}
String message = jsonHandler.serialize(command);
chatUiRequestListenerFuture.thenApply(listener -> {
Copy link
Contributor

@shruti0085 shruti0085 Dec 6, 2024

Choose a reason for hiding this comment

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

this approach seems a lil odd IMO although correct. Traditionally listeners in an event subscriber pattern are not intended to be completable futures. In this case, the webview class is the listener to an event. Why do we need to return the listener on L248? Instead can we not make the event handling async i.e make the sendToChatUi call a completable Future insead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's address this as part of the larger refactor to the views @taldekar.

@taldekar taldekar requested a review from shruti0085 December 6, 2024 23:02
@breedloj breedloj merged commit cdbbbf5 into main Dec 10, 2024
1 check passed
@breedloj breedloj deleted the taldekar/ChatStreamingIssueFix branch December 10, 2024 19:09
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