diff options
author | Ty Dunn <ty@tydunn.com> | 2023-06-29 19:48:14 -0700 |
---|---|---|
committer | Ty Dunn <ty@tydunn.com> | 2023-06-29 19:48:14 -0700 |
commit | 505bf4f6c10058bfe63de76648cc215f71205197 (patch) | |
tree | 9dfe62c06328162050f0746d71bcba762dd23ec9 /extension | |
parent | df602177766f643fd4fe0dbed34ffdd91bc50590 (diff) | |
download | sncontinue-505bf4f6c10058bfe63de76648cc215f71205197.tar.gz sncontinue-505bf4f6c10058bfe63de76648cc215f71205197.tar.bz2 sncontinue-505bf4f6c10058bfe63de76648cc215f71205197.zip |
missing things from data collection
Diffstat (limited to 'extension')
-rw-r--r-- | extension/package.json | 5 | ||||
-rw-r--r-- | extension/src/debugPanel.ts | 9 | ||||
-rw-r--r-- | extension/src/suggestions.ts | 42 |
3 files changed, 55 insertions, 1 deletions
diff --git a/extension/package.json b/extension/package.json index e34af438..91e285f8 100644 --- a/extension/package.json +++ b/extension/package.json @@ -62,6 +62,11 @@ "type": "password", "default": "", "description": "The Hugging Face API token to use for code generation." + }, + "continue.dataSwitch": { + "type": "boolean", + "default": false, + "description": "If true, collect data on accepted and rejected suggestions." } } }, diff --git a/extension/src/debugPanel.ts b/extension/src/debugPanel.ts index 79719a3b..4f3d097c 100644 --- a/extension/src/debugPanel.ts +++ b/extension/src/debugPanel.ts @@ -231,6 +231,7 @@ export function setupDebugPanel( apiUrl: getContinueServerUrl(), sessionId, vscMediaUrl, + dataSwitchOn: vscode.workspace.getConfiguration("continue").get<boolean>("dataSwitch") }); // // Listen for changes to server URL in settings @@ -247,7 +248,13 @@ export function setupDebugPanel( break; } - + case "toggleDataSwitch": { + // Set the setting in vscode + await vscode.workspace + .getConfiguration("continue") + .update("dataSwitch", data.on, vscode.ConfigurationTarget.Global); + break; + } case "websocketForwardingOpen": { let url = data.url; if (typeof websocketConnections[url] === "undefined") { diff --git a/extension/src/suggestions.ts b/extension/src/suggestions.ts index c36b9b34..52fff196 100644 --- a/extension/src/suggestions.ts +++ b/extension/src/suggestions.ts @@ -2,11 +2,15 @@ import * as vscode from "vscode"; import { sendTelemetryEvent, TelemetryEvent } from "./telemetry"; import { openEditorAndRevealRange } from "./util/vscode"; import { translate, readFileAtRange } from "./util/vscode"; +import * as fs from 'fs'; +import * as path from 'path'; + export interface SuggestionRanges { oldRange: vscode.Range; newRange: vscode.Range; newSelected: boolean; + newContent: string; } /* Keyed by editor.document.uri.toString() */ @@ -204,6 +208,41 @@ function selectSuggestion( : suggestion.newRange; } + let workspaceDir = vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders[0]?.uri.fsPath : undefined; + + let collectOn = vscode.workspace.getConfiguration("continue").get<boolean>("dataSwitch") + + if (workspaceDir && collectOn) { + + let continueDir = path.join(workspaceDir, ".continue"); + + // Check if .continue directory doesn't exists + if(!fs.existsSync(continueDir)) { + fs.mkdirSync(continueDir); + } + + let suggestionsPath = path.join(continueDir, "suggestions.json"); + + // Initialize suggestions list + let suggestions = []; + + // Check if suggestions.json exists + if(fs.existsSync(suggestionsPath)) { + let rawData = fs.readFileSync(suggestionsPath, 'utf-8'); + suggestions = JSON.parse(rawData); + } + + if (accept === "new" || (accept === "selected" && suggestion.newSelected)) { + suggestions.push({ accepted: true, timestamp: Date.now(), suggestion: suggestion.newContent }); + } else { + suggestions.push({ accepted: false, timestamp: Date.now(), suggestion: suggestion.newContent }); + } + + // Write the updated suggestions back to the file + fs.writeFileSync(suggestionsPath, JSON.stringify(suggestions, null, 4), 'utf-8'); + + } + rangeToDelete = new vscode.Range( rangeToDelete.start, new vscode.Position(rangeToDelete.end.line, 0) @@ -332,6 +371,7 @@ export async function showSuggestion( new vscode.Position(range.end.line, 0), new vscode.Position(range.end.line + suggestionLinesLength, 0) ); + let content = editor!.document.getText(suggestionRange); const filename = editor!.document.uri.toString(); if (editorToSuggestions.has(filename)) { @@ -340,6 +380,7 @@ export async function showSuggestion( oldRange: range, newRange: suggestionRange, newSelected: true, + newContent: content }); editorToSuggestions.set(filename, suggestions); currentSuggestion.set(filename, suggestions.length - 1); @@ -349,6 +390,7 @@ export async function showSuggestion( oldRange: range, newRange: suggestionRange, newSelected: true, + newContent: content }, ]); currentSuggestion.set(filename, 0); |