From 489e0cc096f4b16c0ee0b5637f7e2170390e7a49 Mon Sep 17 00:00:00 2001 From: Brendan Maginnis Date: Tue, 8 Aug 2023 15:36:34 +0100 Subject: [PATCH] feat: Add opt in webview that is shown prior to enabling the coding assistant (#200) --- package.json | 16 ++++++--- src/chat.ts | 52 ++++++++++++++--------------- src/code-review.ts | 76 +++++++++++++++++++++--------------------- src/extension.ts | 20 +++++++++++ src/opt-in.ts | 82 ++++++++++++++++++++++++++++++++++++++++++++++ src/recipes.ts | 40 +++++++++++----------- 6 files changed, 198 insertions(+), 88 deletions(-) create mode 100644 src/opt-in.ts diff --git a/package.json b/package.json index d8c9481..3b733d0 100644 --- a/package.json +++ b/package.json @@ -51,13 +51,21 @@ }, "views": { "sourcery-explorer": [ + { + "id": "sourcery.coding_assistant_opt_in", + "name": "Coding Assistant", + "type": "webview", + "icon": "sourcery-icon.png", + "contextualTitle": "Coding Assistant", + "when": "sourcery.features.coding_assistant && !sourcery.config.coding_assistant.enabled" + }, { "id": "sourcery.chat", "name": "Coding Assistant", "type": "webview", "icon": "sourcery-icon.png", "contextualTitle": "Coding Assistant", - "when": "sourcery.features.coding_assistant" + "when": "sourcery.features.coding_assistant && sourcery.config.coding_assistant.enabled === true" }, { "id": "sourcery.troubleshooting", @@ -65,7 +73,7 @@ "type": "webview", "icon": "sourcery-icon.png", "contextualTitle": "Troubleshooting", - "when": "sourcery.features.coding_assistant && sourcery.features.coding_assistant_troubleshooting && sourcery.features.semantic_search" + "when": "sourcery.features.coding_assistant && sourcery.config.coding_assistant.enabled === true && sourcery.features.coding_assistant_troubleshooting && sourcery.features.semantic_search" }, { "id": "sourcery.recipes", @@ -73,7 +81,7 @@ "type": "webview", "icon": "sourcery-icon.png", "contextualTitle": "Recipes", - "when": "sourcery.features.coding_assistant" + "when": "sourcery.features.coding_assistant && sourcery.config.coding_assistant.enabled === true" }, { "id": "sourcery.code_review", @@ -81,7 +89,7 @@ "type": "webview", "icon": "sourcery-icon.png", "contextualTitle": "Code Review", - "when": "sourcery.features.coding_assistant && sourcery.features.code_review" + "when": "sourcery.features.coding_assistant && sourcery.config.coding_assistant.enabled === true && sourcery.features.code_review" }, { "id": "sourcery.rules", diff --git a/src/chat.ts b/src/chat.ts index b32d9c9..17728c1 100644 --- a/src/chat.ts +++ b/src/chat.ts @@ -284,36 +284,36 @@ export class ChatProvider implements vscode.WebviewViewProvider { /* eslint-enable @typescript-eslint/naming-convention */ return ` - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - `; + + + `; } } diff --git a/src/code-review.ts b/src/code-review.ts index 772c885..0f6d958 100644 --- a/src/code-review.ts +++ b/src/code-review.ts @@ -224,53 +224,53 @@ export class CodeReviewProvider implements vscode.WebviewViewProvider { /* eslint-enable @typescript-eslint/naming-convention */ return ` - - - - - - - - - + + + + + + + + + - + - - + +
- -
- + +
+ +
- - - - `; + + + + `; } } diff --git a/src/extension.ts b/src/extension.ts index 55e5793..3ff8350 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -32,6 +32,7 @@ import { import { getHubSrc } from "./hub"; import { RuleInputProvider } from "./rule-search"; import { ScanResultProvider } from "./rule-search-results"; +import { CodingAssistantOptInProvider } from "./opt-in"; import { ChatProvider, ChatRequest } from "./chat"; import { RecipeProvider } from "./recipes"; import { CodeReviewProvider } from "./code-review"; @@ -238,6 +239,16 @@ function registerCommands( }) ); + context.subscriptions.push( + commands.registerCommand("sourcery.coding_assistant.opt_in", () => { + let request: ExecuteCommandParams = { + command: "sourcery.coding_assistant.opt_in", + arguments: [], + }; + languageClient.sendRequest(ExecuteCommandRequest.type, request); + }) + ); + context.subscriptions.push( commands.registerCommand("sourcery.chat.clearChat", () => { let request: ExecuteCommandParams = { @@ -654,6 +665,15 @@ export function activate(context: ExtensionContext) { const riProvider = new RuleInputProvider(context); + const codingAssistantOptInProvider = new CodingAssistantOptInProvider(); + context.subscriptions.push( + vscode.window.registerWebviewViewProvider( + CodingAssistantOptInProvider.viewType, + codingAssistantOptInProvider, + { webviewOptions: { retainContextWhenHidden: true } } + ) + ); + const chatProvider = new ChatProvider(context); context.subscriptions.push( diff --git a/src/opt-in.ts b/src/opt-in.ts new file mode 100644 index 0000000..e3e5eb0 --- /dev/null +++ b/src/opt-in.ts @@ -0,0 +1,82 @@ +"use strict"; + +import { commands, WebviewView, WebviewViewProvider } from "vscode"; + +type OptInMessage = { + command: "opt-in"; +}; + +export class CodingAssistantOptInProvider implements WebviewViewProvider { + public static readonly viewType = "sourcery.coding_assistant_opt_in"; + + public async resolveWebviewView(webviewView: WebviewView) { + webviewView.webview.options = { + enableScripts: true, + }; + + webviewView.webview.onDidReceiveMessage(async (_message: OptInMessage) => + commands.executeCommand("sourcery.coding_assistant.opt_in") + ); + + webviewView.webview.html = ` + + + Opt-In Form + + + + +
+

Sourcery Coding Assistant

+

By enabling the Sourcery coding assistant, you agree that Sourcery can send your code to third party LLMs for analysis (OpenAI, Anthropic).

+

None of your code is ever stored on our servers.

+
+ +
+
+ + +`; + } +} diff --git a/src/recipes.ts b/src/recipes.ts index 7308358..6ff34c2 100644 --- a/src/recipes.ts +++ b/src/recipes.ts @@ -90,25 +90,25 @@ export class RecipeProvider implements vscode.WebviewViewProvider { /* eslint-enable @typescript-eslint/naming-convention */ return ` - - - - - - - - - - - - -
-
- - - `; + + + + + + + + + + + + +
+
+ + + `; } }