record accept/reject

This commit is contained in:
Nate Sesti 2023-07-16 16:10:50 -07:00
parent b3ef903bea
commit 06cd33b8ba
3 changed files with 54 additions and 60 deletions

View file

@ -400,6 +400,14 @@ function serverPath(): string {
return sPath;
}
export function devDataPath(): string {
const sPath = path.join(getContinueGlobalPath(), "dev_data");
if (!fs.existsSync(sPath)) {
fs.mkdirSync(sPath);
}
return sPath;
}
function serverVersionPath(): string {
return path.join(serverPath(), "server_version.txt");
}

View file

@ -4,6 +4,7 @@ import * as fs from "fs";
import * as vscode from "vscode";
import { extensionContext, ideProtocolClient } from "./activation/activate";
import { getMetaKeyLabel } from "./util/util";
import { devDataPath } from "./activation/environmentSetup";
interface DiffInfo {
originalFilepath: string;
@ -13,7 +14,9 @@ interface DiffInfo {
range: vscode.Range;
}
export const DIFF_DIRECTORY = path.join(os.homedir(), ".continue", "diffs").replace(/^C:/, "c:");
export const DIFF_DIRECTORY = path
.join(os.homedir(), ".continue", "diffs")
.replace(/^C:/, "c:");
class DiffManager {
// Create a temporary file in the global .continue directory which displays the updated version
@ -222,6 +225,8 @@ class DiffManager {
);
this.cleanUpDiff(diffInfo);
});
recordAcceptReject(true, diffInfo);
}
rejectDiff(newFilepath?: string) {
@ -251,11 +256,50 @@ class DiffManager {
.then(() => {
this.cleanUpDiff(diffInfo);
});
recordAcceptReject(false, diffInfo);
}
}
export const diffManager = new DiffManager();
function recordAcceptReject(accepted: boolean, diffInfo: DiffInfo) {
const collectOn = vscode.workspace
.getConfiguration("continue")
.get<boolean>("dataSwitch");
if (collectOn) {
const devDataDir = devDataPath();
const suggestionsPath = path.join(devDataDir, "suggestions.json");
// Initialize suggestions list
let suggestions = [];
// Check if suggestions.json exists
if (fs.existsSync(suggestionsPath)) {
const rawData = fs.readFileSync(suggestionsPath, "utf-8");
suggestions = JSON.parse(rawData);
}
// Add the new suggestion to the list
suggestions.push({
accepted,
timestamp: Date.now(),
suggestion: diffInfo.originalFilepath,
});
// Send the suggestion to the server
ideProtocolClient.sendAcceptRejectSuggestion(accepted);
// Write the updated suggestions back to the file
fs.writeFileSync(
suggestionsPath,
JSON.stringify(suggestions, null, 4),
"utf-8"
);
}
}
export async function acceptDiffCommand(newFilepath?: string) {
diffManager.acceptDiff(newFilepath);
ideProtocolClient.sendAcceptRejectDiff(true);

View file

@ -1,9 +1,7 @@
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";
import { translate } from "./util/vscode";
import { registerAllCodeLensProviders } from "./lang-server/codeLens";
import { extensionContext, ideProtocolClient } from "./activation/activate";
@ -214,62 +212,6 @@ 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);
}
const accepted =
accept === "new" || (accept === "selected" && suggestion.newSelected);
suggestions.push({
accepted,
timestamp: Date.now(),
suggestion: suggestion.newContent,
});
ideProtocolClient.sendAcceptRejectSuggestion(accepted);
// Write the updated suggestions back to the file
fs.writeFileSync(
suggestionsPath,
JSON.stringify(suggestions, null, 4),
"utf-8"
);
// If it's not already there, add .continue to .gitignore
const gitignorePath = path.join(workspaceDir, ".gitignore");
if (fs.existsSync(gitignorePath)) {
const gitignoreData = fs.readFileSync(gitignorePath, "utf-8");
const gitIgnoreLines = gitignoreData.split("\n");
if (!gitIgnoreLines.includes(".continue")) {
fs.appendFileSync(gitignorePath, "\n.continue\n");
}
} else {
fs.writeFileSync(gitignorePath, ".continue\n");
}
}
rangeToDelete = new vscode.Range(
rangeToDelete.start,
new vscode.Position(rangeToDelete.end.line, 0)