Compare commits

...

2 Commits

Author SHA1 Message Date
Andrei Edell 4aa6c2bd16 format fix 2025-07-09 17:55:51 -07:00
Andrei Edell 903ef6edc8 Replace use of vscode.fs.writeFile with node equivalent 2025-07-09 17:51:13 -07:00
3 changed files with 24 additions and 2 deletions
+2 -1
View File
@@ -4,6 +4,7 @@ import * as path from "path"
import * as vscode from "vscode"
import { getHostBridgeProvider } from "@/hosts/host-providers"
import { ShowTextDocumentRequest, ShowTextDocumentOptions } from "@/shared/proto/host/window"
import { writeFile } from "@utils/fs"
export async function downloadTask(dateTs: number, conversationHistory: Anthropic.MessageParam[]) {
// File name
@@ -39,7 +40,7 @@ export async function downloadTask(dateTs: number, conversationHistory: Anthropi
if (saveUri) {
try {
// Write content to the selected location
await vscode.workspace.fs.writeFile(saveUri, new TextEncoder().encode(markdownContent))
await writeFile(saveUri.fsPath, markdownContent)
await getHostBridgeProvider().windowClient.showTextDocument(
ShowTextDocumentRequest.create({
path: saveUri.fsPath,
+2 -1
View File
@@ -4,6 +4,7 @@ import * as vscode from "vscode"
import { arePathsEqual } from "@utils/path"
import { getHostBridgeProvider } from "@/hosts/host-providers"
import { ShowTextDocumentRequest, ShowTextDocumentOptions } from "@/shared/proto/host/window"
import { writeFile } from "@utils/fs"
export async function openImage(dataUri: string) {
const matches = dataUri.match(/^data:image\/([a-zA-Z]+);base64,(.+)$/)
@@ -15,7 +16,7 @@ export async function openImage(dataUri: string) {
const imageBuffer = Buffer.from(base64Data, "base64")
const tempFilePath = path.join(os.tmpdir(), `temp_image_${Date.now()}.${format}`)
try {
await vscode.workspace.fs.writeFile(vscode.Uri.file(tempFilePath), new Uint8Array(imageBuffer))
await writeFile(tempFilePath, new Uint8Array(imageBuffer))
await vscode.commands.executeCommand("vscode.open", vscode.Uri.file(tempFilePath))
} catch (error) {
vscode.window.showErrorMessage(`Error opening image: ${error}`)
+20
View File
@@ -75,6 +75,26 @@ export async function getFileSizeInKB(filePath: string): Promise<number> {
}
}
/**
* Writes content to a file
* @param filePath - Absolute path to the file
* @param content - Content to write (string or Uint8Array)
* @param encoding - Text encoding (default: 'utf8')
* @returns A promise that resolves when the file is written
*/
export async function writeFile(
filePath: string,
content: string | Uint8Array,
encoding: BufferEncoding = "utf8",
): Promise<void> {
console.log("[DEBUG] writing file:", filePath, content.length, encoding)
if (content instanceof Uint8Array) {
await fs.writeFile(filePath, content)
} else {
await fs.writeFile(filePath, content, encoding)
}
}
// Common OS-generated files that would appear in an otherwise clean directory
const OS_GENERATED_FILES = [
".DS_Store", // macOS Finder