summaryrefslogtreecommitdiff
path: root/extension/src/diffs.ts
diff options
context:
space:
mode:
authorNate Sesti <sestinj@gmail.com>2023-07-17 13:33:29 -0700
committerNate Sesti <sestinj@gmail.com>2023-07-17 13:33:29 -0700
commit1a647a7321a31d7ccf29f27e56c3df0828c3e9c8 (patch)
tree3e20e038d06449d6dff677566e1bdf6ed148eb96 /extension/src/diffs.ts
parent062b0872797fb4734ed36ea3a14f653dc685a86a (diff)
parentd0dc7811eb71d9d53055a1aa684827502748b794 (diff)
downloadsncontinue-1a647a7321a31d7ccf29f27e56c3df0828c3e9c8.tar.gz
sncontinue-1a647a7321a31d7ccf29f27e56c3df0828c3e9c8.tar.bz2
sncontinue-1a647a7321a31d7ccf29f27e56c3df0828c3e9c8.zip
Merge branch 'main' of https://github.com/continuedev/continue into anthropic
Diffstat (limited to 'extension/src/diffs.ts')
-rw-r--r--extension/src/diffs.ts46
1 files changed, 45 insertions, 1 deletions
diff --git a/extension/src/diffs.ts b/extension/src/diffs.ts
index 2860258d..0bab326a 100644
--- a/extension/src/diffs.ts
+++ b/extension/src/diffs.ts
@@ -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);