(context: vscode.ExtensionContext)
| 44 | |
| 45 | |
| 46 | function initWs(context: vscode.ExtensionContext) { |
| 47 | // change to something else |
| 48 | const ws = new WebSocket(process.env.WS_RELAYER_URL || "ws://localhost:9093"); |
| 49 | |
| 50 | ws.onerror = (e: any) => { |
| 51 | console.log("error", ); |
| 52 | console.log(e); |
| 53 | console.log(JSON.stringify(e)); |
| 54 | } |
| 55 | |
| 56 | ws.onopen = () => { |
| 57 | ws.send(JSON.stringify({ |
| 58 | event: "subscribe", |
| 59 | data: null |
| 60 | })); |
| 61 | } |
| 62 | |
| 63 | ws.onmessage = async (e: any) => { |
| 64 | const data: AdminMessage = JSON.parse(e.data); |
| 65 | console.log('data'); |
| 66 | console.log(data); |
| 67 | if (data.type === "command") { |
| 68 | vscode.commands.executeCommand('extension.sendToAiTerminal', data.content); |
| 69 | } |
| 70 | |
| 71 | if (data.type === "update-file") { |
| 72 | const fileUri = await ensureFileExists(data.path!, data.content); |
| 73 | |
| 74 | const document = await vscode.workspace.openTextDocument(fileUri); |
| 75 | await vscode.window.showTextDocument(document); |
| 76 | |
| 77 | const edit = new vscode.WorkspaceEdit(); |
| 78 | const range = new vscode.Range( |
| 79 | new vscode.Position(0, 0), |
| 80 | new vscode.Position(document.lineCount, 0) |
| 81 | ); |
| 82 | |
| 83 | edit.replace(document.uri, range, data.content); |
| 84 | await vscode.workspace.applyEdit(edit); |
| 85 | } |
| 86 | |
| 87 | if (data.type === "prompt-start") { |
| 88 | const terminals = vscode.window.terminals; |
| 89 | if (terminals.length > 0) { |
| 90 | const activeTerminal = vscode.window.activeTerminal; |
| 91 | activeTerminal?.sendText('\x03'); |
| 92 | } |
| 93 | // get response from git diff command silently and forward it via ws to the server |
| 94 | const diff = await vscode.commands.executeCommand('git diff'); |
| 95 | ws.send(JSON.stringify({ |
| 96 | event: "vscode_diff", |
| 97 | diff: diff, |
| 98 | callbackId: data.callbackId |
| 99 | })); |
| 100 | } |
| 101 | |
| 102 | if (data.type === "prompt-end") { |
| 103 | vscode.commands.executeCommand('git add .'); |
no test coverage detected