[PROTOBUS] showTextDocument host bridge (#4586)

* showTextDocument host bridge

* format fix

* sjf review cleanups

* prefer paths over URI based on chats with sjf

* also document_uri -> document_path

* remove unused metadata import

---------

Co-authored-by: Andrei Edell <andrei@nugbase.com>
This commit is contained in:
Andrei EternalandAndrei Edell authored and GitHub committed 2025-06-30 18:39:09 -07:00
1 parent dcf91b081e
commit c013b4f329
13 files changed
+125 -18

No files matched your search

+8 -1
View File
@@ -2,6 +2,8 @@ import { Anthropic } from "@anthropic-ai/sdk"
import os from "os"
import * as path from "path"
import * as vscode from "vscode"
import { getHostBridgeProvider } from "@/hosts/host-providers"
import { ShowTextDocumentRequest, ShowTextDocumentOptions } from "@/shared/proto/host/window"
export async function downloadTask(dateTs: number, conversationHistory: Anthropic.MessageParam[]) {
// File name
@@ -38,7 +40,12 @@ export async function downloadTask(dateTs: number, conversationHistory: Anthropi
try {
// Write content to the selected location
await vscode.workspace.fs.writeFile(saveUri, new TextEncoder().encode(markdownContent))
vscode.window.showTextDocument(saveUri, { preview: true })
await getHostBridgeProvider().windowClient.showTextDocument(
ShowTextDocumentRequest.create({
path: saveUri.fsPath,
options: ShowTextDocumentOptions.create({ preview: true }),
}),
)
} catch (error) {
vscode.window.showErrorMessage(
`Failed to save markdown file: ${error instanceof Error ? error.message : String(error)}`,
+8 -1
View File
@@ -2,6 +2,8 @@ import * as path from "path"
import * as os from "os"
import * as vscode from "vscode"
import { arePathsEqual } from "@utils/path"
import { getHostBridgeProvider } from "@/hosts/host-providers"
import { ShowTextDocumentRequest, ShowTextDocumentOptions } from "@/shared/proto/host/window"
export async function openImage(dataUri: string) {
const matches = dataUri.match(/^data:image\/([a-zA-Z]+);base64,(.+)$/)
@@ -42,7 +44,12 @@ export async function openFile(absolutePath: string) {
} catch {} // not essential, sometimes tab operations fail
const document = await vscode.workspace.openTextDocument(uri)
await vscode.window.showTextDocument(document, { preview: false })
await getHostBridgeProvider().windowClient.showTextDocument(
ShowTextDocumentRequest.create({
path: document.uri.fsPath,
options: ShowTextDocumentOptions.create({ preview: false }),
}),
)
} catch (error) {
vscode.window.showErrorMessage(`Could not open file!`)
}