Skip to content

Commit

Permalink
Save output buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinMcNeil committed Oct 28, 2024
1 parent 3f27824 commit e30779f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/commands/runPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getCredential } from "../utils/credential";
import { setProjectDir } from "./setProjectDir";
import { postToBackendSocket } from "../utils/ddSocket";
import { extensionOutput } from "../extension";
import { randomUUID } from "crypto";

type PromptOption = 'local-dir' | 'local-file' | 'remote';

Expand Down Expand Up @@ -133,13 +134,15 @@ export const runPrompt: (secrets: vscode.SecretStorage, mode: PromptOption) => v
return vscode.window.showErrorMessage("No project path set. Please set the project path in settings or run a local prompt from a workspace.");
}

const hostDir = runningLocal ? inputWorkspace! : workspaceFolder!.uri.fsPath;

progress.report({ increment: 5, message: "Checking for project path..." });

progress.report({ increment: 5, message: "Writing prompt output file..." });

const apiKey = await secrets.get("openAIKey");

const { editor, doc } = await createOutputBuffer();
const { editor, doc } = await createOutputBuffer('prompt-output' + randomUUID() + '.md', hostDir);

if (!editor || !doc) {
postToBackendSocket({ event: 'eventLabsPromptError', properties: { error: 'No editor or document found' } });
Expand Down Expand Up @@ -169,7 +172,7 @@ export const runPrompt: (secrets: vscode.SecretStorage, mode: PromptOption) => v
progress.report({ increment: 5, message: "Running..." });
const ranges: Record<string, vscode.Range> = {};
const getBaseFunctionRange = () => new vscode.Range(doc.lineCount, 0, doc.lineCount, 0);
await spawnPromptImage(promptOption.id, runningLocal ? inputWorkspace! : workspaceFolder!.uri.fsPath, Username || 'vscode-user', Password, process.platform, async (json) => {
await spawnPromptImage(promptOption.id, hostDir, Username || 'vscode-user', Password, process.platform, async (json) => {
extensionOutput.appendLine(JSON.stringify(json))

Check warning on line 176 in src/commands/runPrompt.ts

View workflow job for this annotation

GitHub Actions / test

Missing semicolon
switch (json.method) {
case 'functions':
Expand Down Expand Up @@ -225,6 +228,7 @@ export const runPrompt: (secrets: vscode.SecretStorage, mode: PromptOption) => v
await writeToEditor(JSON.stringify(json, null, 2));
}
}, token);
await doc.save();
} catch (e: unknown) {
void vscode.window.showErrorMessage("Error running prompt");
await writeToEditor('```json\n' + (e as Error).toString() + '\n```');
Expand Down
12 changes: 10 additions & 2 deletions src/utils/promptFilename.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import * as vscode from "vscode";

export const createOutputBuffer = async () => {
const doc = await vscode.workspace.openTextDocument({ language: 'markdown' });
export const createOutputBuffer = async (fileName: string, hostDir: string) => {
const edit = new vscode.WorkspaceEdit();

const newURI = vscode.Uri.file(`${hostDir}/${fileName}`);

edit.createFile(newURI, { ignoreIfExists: true });

await vscode.workspace.applyEdit(edit);

const doc = await vscode.workspace.openTextDocument(newURI);

const editor = await vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside);

Expand Down

0 comments on commit e30779f

Please sign in to comment.