From d25b866449770df066d91ba13b6974528867b079 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 11 Jun 2024 23:47:35 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feedback=20mechanism=20for=20autoco?= =?UTF-8?q?mplete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/continueServer/stubs/client.ts | 19 ++++++++++++++ extensions/vscode/package-lock.json | 9 +++++++ extensions/vscode/package.json | 1 + extensions/vscode/src/commands.ts | 26 ++++++++++++++++++- .../vscode/src/extension/vscodeExtension.ts | 1 + 5 files changed, 55 insertions(+), 1 deletion(-) diff --git a/core/continueServer/stubs/client.ts b/core/continueServer/stubs/client.ts index 9c1c5d45cd..534060b584 100644 --- a/core/continueServer/stubs/client.ts +++ b/core/continueServer/stubs/client.ts @@ -39,4 +39,23 @@ export class ContinueServerClient implements IContinueServerClient { ): Promise> { return { files: {} }; } + + public async sendFeedback(feedback: string, data: string): Promise { + if (!this.url) { + return; + } + + const url = new URL("feedback", this.url); + + const response = await fetch(url, { + method: "POST", + headers: { + Authorization: `Bearer ${await this.userToken}`, + }, + body: JSON.stringify({ + feedback, + data, + }), + }); + } } diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index ae1349e888..331c5866dd 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -40,6 +40,7 @@ "posthog-node": "^3.6.3", "react-markdown": "^8.0.7", "react-redux": "^8.0.5", + "read-last-lines": "^1.8.0", "request": "^2.88.2", "socket.io-client": "^4.7.2", "strip-ansi": "^7.1.0", @@ -9293,6 +9294,14 @@ "pify": "^2.3.0" } }, + "node_modules/read-last-lines": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/read-last-lines/-/read-last-lines-1.8.0.tgz", + "integrity": "sha512-oPL0cnZkhsO2xF7DBrdzVhXSNajPP5TzzCim/2IAjeGb17ArLLTRriI/ceV6Rook3L27mvbrOvLlf9xYYnaftQ==", + "dependencies": { + "mz": "^2.7.0" + } + }, "node_modules/readable-stream": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index ff7afdc30e..885e887985 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -554,6 +554,7 @@ "posthog-node": "^3.6.3", "react-markdown": "^8.0.7", "react-redux": "^8.0.5", + "read-last-lines": "^1.8.0", "request": "^2.88.2", "socket.io-client": "^4.7.2", "strip-ansi": "^7.1.0", diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index df102df6bf..b2bf277f81 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -6,9 +6,11 @@ import * as vscode from "vscode"; import { ContextMenuConfig, IDE } from "core"; import { CompletionProvider } from "core/autocomplete/completionProvider"; import { ConfigHandler } from "core/config/handler"; +import { ContinueServerClient } from "core/continueServer/stubs/client"; import { fetchwithRequestOptions } from "core/util/fetchWithOptions"; import { GlobalContext } from "core/util/GlobalContext"; -import { getConfigJsonPath } from "core/util/paths"; +import { getConfigJsonPath, getDevDataFilePath } from "core/util/paths"; +import readLastLines from "read-last-lines"; import { ContinueGUIWebviewViewProvider } from "./debugPanel"; import { DiffManager } from "./diff/horizontal"; import { VerticalPerLineDiffManager } from "./diff/verticalPerLine/manager"; @@ -142,6 +144,7 @@ const commandsMap: ( configHandler: ConfigHandler, diffManager: DiffManager, verticalDiffManager: VerticalPerLineDiffManager, + continueServerClientPromise: Promise, ) => { [command: string]: (...args: any) => any } = ( ide, extensionContext, @@ -149,6 +152,7 @@ const commandsMap: ( configHandler, diffManager, verticalDiffManager, + continueServerClientPromise, ) => { async function streamInlineEdit( promptName: keyof ContextMenuConfig, @@ -552,6 +556,9 @@ const commandsMap: ( { label: "$(gear) Configure autocomplete options", }, + { + label: "$(feedback) Give feedback", + }, { kind: vscode.QuickPickItemKind.Separator, label: "Switch model", @@ -585,11 +592,26 @@ const commandsMap: ( selectedOption, ); configHandler.reloadConfig(); + } else if (selectedOption === "$(feedback) Give feedback") { + vscode.commands.executeCommand("continue.giveAutocompleteFeedback"); } quickPick.dispose(); }); quickPick.show(); }, + "continue.giveAutocompleteFeedback": async () => { + const feedback = await vscode.window.showInputBox({ + prompt: + "Please share what went wrong with the last completion. The details of the completion as well as this message will be sent to the Continue team in order to improve.", + }); + if (feedback) { + const client = await continueServerClientPromise; + const completionsPath = getDevDataFilePath("autocomplete"); + + const lastLines = await readLastLines.read(completionsPath, 2); + client.sendFeedback(feedback, lastLines); + } + }, }; }; @@ -601,6 +623,7 @@ export function registerAllCommands( configHandler: ConfigHandler, diffManager: DiffManager, verticalDiffManager: VerticalPerLineDiffManager, + continueServerClientPromise: Promise, ) { for (const [command, callback] of Object.entries( commandsMap( @@ -610,6 +633,7 @@ export function registerAllCommands( configHandler, diffManager, verticalDiffManager, + continueServerClientPromise, ), )) { context.subscriptions.push( diff --git a/extensions/vscode/src/extension/vscodeExtension.ts b/extensions/vscode/src/extension/vscodeExtension.ts index 78306fec30..c5b390b450 100644 --- a/extensions/vscode/src/extension/vscodeExtension.ts +++ b/extensions/vscode/src/extension/vscodeExtension.ts @@ -157,6 +157,7 @@ export class VsCodeExtension { this.configHandler, this.diffManager, this.verticalDiffManager, + this.core.continueServerClientPromise, ); registerDebugTracker(this.sidebar.webviewProtocol, this.ide);