Skip to content

Commit

Permalink
Enhance feedback handling with unhelpfulReason support
Browse files Browse the repository at this point in the history
Bump version to 0.0.10
  • Loading branch information
tspascoal committed Dec 15, 2024
1 parent 8950f3d commit d498884
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "tspascoal-copilot-chat-parrot",
"displayName": "Parrot",
"description": "Parrot is a chat participant that repeats things",
"version": "0.0.9",
"version": "0.0.10",
"repository": {
"type": "git",
"url": "https://github.com/tspascoal/copilot-chat-parrot-extension.git"
Expand Down
23 changes: 17 additions & 6 deletions src/feedbackhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import * as vscode from 'vscode';
* Handles the feedback received from a chat result.
*
* @param feedback - The feedback object containing the kind of feedback.
* @returns void
* @remarks
* This function processes the feedback based on its kind and displays an appropriate message to the user.
*
* - If the feedback is of kind `Helpful`, an information message is shown.
* - If the feedback is of kind `Unhelpful`, a warning message is shown. If the feedback object contains an `unhelpfulReason` property, it is included in the message.
* - For any other kind of feedback, a default information message is shown.
*
* Logs the feedback to the console and shows an information message based on the kind of feedback.
* - If the feedback is helpful, it shows a message indicating that the user liked it.
* - If the feedback is unhelpful, it shows a message apologizing for the unsatisfactory response.
* - For any other feedback kind, it shows a message indicating an unknown feedback type.
* @example
* ```typescript
* const feedback: vscode.ChatResultFeedback = { kind: vscode.ChatResultFeedbackKind.Helpful };
* handleFeedback(feedback);
* ```
*/
export function handleFeedback(feedback: vscode.ChatResultFeedback) {
console.log('Feedback received:', feedback);
Expand All @@ -19,7 +25,12 @@ export function handleFeedback(feedback: vscode.ChatResultFeedback) {
vscode.window.showInformationMessage('🚀 Happy that you liked it.');
break;
case vscode.ChatResultFeedbackKind.Unhelpful:
vscode.window.showWarningMessage('😢 Sorry that you didn\'t like our response.');
let extraMessage = '';
// This isn't part of ChatResultFeedback nor it's documented, but it's a property of the feedback object. It might disappear in the future
if ((feedback as any).unhelpfulReason) {
extraMessage = ` With Reason: ${(feedback as any).unhelpfulReason}`;
}
vscode.window.showWarningMessage(`😢 Sorry that you didn\'t like our response.${extraMessage}`);
break;
default:
vscode.window.showInformationMessage('Don\'t know what to do with this feedback type.');
Expand Down
22 changes: 22 additions & 0 deletions src/test/feedbackhandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ suite('Feedback Handler Test Suite', () => {
vscode.window.showWarningMessage = originalShowWarningMessage;
});


test('Handles unhelpful with undocumented unhelpfulReason feedback correctly', () => {
const feedback: vscode.ChatResultFeedback = {
kind: vscode.ChatResultFeedbackKind.Unhelpful,
result: {} as any,
unhelpfulReason: 'incompleteCode'
} as any;
let messageShown = '';

const originalShowWarningMessage = vscode.window.showWarningMessage;
vscode.window.showWarningMessage = (message: string) => {
messageShown = message;
return Promise.resolve();
};

handleFeedback(feedback);

assert.strictEqual(messageShown, '😢 Sorry that you didn\'t like our response. With Reason: incompleteCode');

vscode.window.showWarningMessage = originalShowWarningMessage;
});

test('Handles unknown feedback correctly', () => {
const feedback: vscode.ChatResultFeedback = { kind: 666 as vscode.ChatResultFeedbackKind, result: {} as any };
let messageShown = '';
Expand Down

0 comments on commit d498884

Please sign in to comment.