track when suggestion is accepted or rejected
This commit is contained in:
parent
a86933aec5
commit
321ba3f949
4 changed files with 21 additions and 17 deletions
|
|
@ -7,6 +7,7 @@ import uuid
|
|||
from fastapi import WebSocket, Body, APIRouter
|
||||
from uvicorn.main import Server
|
||||
|
||||
from ..libs.util.telemetry import capture_event
|
||||
from ..libs.util.queue import AsyncSubscriptionQueue
|
||||
from ..models.filesystem import FileSystem, RangeInFile, EditDiff, RealFileSystem
|
||||
from ..models.filesystem_edit import AddDirectory, AddFile, DeleteDirectory, DeleteFile, FileSystemEdit, FileEdit, FileEditWithFullContents, RenameDirectory, RenameFile, SequentialFileSystemEdit
|
||||
|
|
@ -142,6 +143,8 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
|
|||
elif message_type == "commandOutput":
|
||||
output = data["output"]
|
||||
self.onCommandOutput(output)
|
||||
elif message_type == "acceptRejectSuggestion":
|
||||
self.onAcceptRejectSuggestion(data["accepted"])
|
||||
elif message_type in ["highlightedCode", "openFiles", "readFile", "editFile", "workspaceDirectory", "getUserSecret", "runCommand", "uniqueId"]:
|
||||
self.sub_queue.post(message_type, data)
|
||||
else:
|
||||
|
|
@ -202,8 +205,10 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
|
|||
# This is where you might have triggers: plugins can subscribe to certian events
|
||||
# like file changes, tracebacks, etc...
|
||||
|
||||
def onAcceptRejectSuggestion(self, suggestionId: str, accepted: bool):
|
||||
pass
|
||||
def onAcceptRejectSuggestion(self, accepted: bool):
|
||||
capture_event(self.unique_id, "accept_reject_suggestion", {
|
||||
"accepted": accepted
|
||||
})
|
||||
|
||||
def onFileSystemUpdate(self, update: FileSystemEdit):
|
||||
# Access to Autopilot (so SessionManager)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class AbstractIdeProtocolServer(ABC):
|
|||
"""Show suggestions to the user and wait for a response"""
|
||||
|
||||
@abstractmethod
|
||||
def onAcceptRejectSuggestion(self, suggestionId: str, accepted: bool):
|
||||
def onAcceptRejectSuggestion(self, accepted: bool):
|
||||
"""Called when the user accepts or rejects a suggestion"""
|
||||
|
||||
@abstractmethod
|
||||
|
|
|
|||
|
|
@ -375,6 +375,10 @@ class IdeProtocolClient {
|
|||
sendCommandOutput(output: string) {
|
||||
this.messenger?.send("commandOutput", { output });
|
||||
}
|
||||
|
||||
sendAcceptRejectSuggestion(accepted: boolean) {
|
||||
this.messenger?.send("acceptRejectSuggestion", { accepted });
|
||||
}
|
||||
}
|
||||
|
||||
export default IdeProtocolClient;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { translate, readFileAtRange } from "./util/vscode";
|
|||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import { registerAllCodeLensProviders } from "./lang-server/codeLens";
|
||||
import { extensionContext } from "./activation/activate";
|
||||
import { extensionContext, ideProtocolClient } from "./activation/activate";
|
||||
|
||||
export interface SuggestionRanges {
|
||||
oldRange: vscode.Range;
|
||||
|
|
@ -241,19 +241,14 @@ function selectSuggestion(
|
|||
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,
|
||||
});
|
||||
}
|
||||
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(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue