Compare commits

...

1 Commits

Author SHA1 Message Date
celestial-vault 085a7efd34 migrate save textDocument 2025-07-21 22:10:26 -07:00
3 changed files with 26 additions and 7 deletions
+9
View File
@@ -4,10 +4,14 @@ package host;
option java_package = "bot.cline.host.proto";
option java_multiple_files = true;
import "common.proto";
// Provides methods for working with workspaces/projects.
service WorkspaceService {
// Returns a list of the top level directories of the workspace.
rpc getWorkspacePaths(GetWorkspacePathsRequest) returns (GetWorkspacePathsResponse);
// Saves an open document if it's dirty
rpc saveOpenDocumentIfDirty(SaveOpenDocumentIfDirtyRequest) returns (cline.Empty);
}
message GetWorkspacePathsRequest {
@@ -22,3 +26,8 @@ message GetWorkspacePathsResponse {
optional string id = 1;
repeated string paths = 2;
}
message SaveOpenDocumentIfDirtyRequest {
cline.Metadata metadata = 1;
string file_path = 2;
}
@@ -0,0 +1,14 @@
import { SaveOpenDocumentIfDirtyRequest } from "@/shared/proto/index.host"
import { Empty } from "@/shared/proto/common"
import * as vscode from "vscode"
import { arePathsEqual } from "@utils/path"
export async function saveOpenDocumentIfDirty(request: SaveOpenDocumentIfDirtyRequest): Promise<Empty> {
const existingDocument = vscode.workspace.textDocuments.find((doc) => arePathsEqual(doc.uri.fsPath, request.filePath))
if (existingDocument && existingDocument.isDirty) {
await existingDocument.save()
}
return Empty.create({})
}
+3 -7
View File
@@ -1,4 +1,3 @@
import * as vscode from "vscode"
import * as path from "path"
import * as fs from "fs/promises"
import { createDirectoriesForFile } from "@utils/fs"
@@ -31,12 +30,9 @@ export abstract class DiffViewProvider {
// if the file is already open, ensure it's not dirty before getting its contents
if (fileExists) {
const existingDocument = vscode.workspace.textDocuments.find((doc) =>
arePathsEqual(doc.uri.fsPath, this.absolutePath),
)
if (existingDocument && existingDocument.isDirty) {
await existingDocument.save()
}
await HostProvider.workspace.saveOpenDocumentIfDirty({
filePath: this.absolutePath!,
})
const fileBuffer = await fs.readFile(this.absolutePath)
this.fileEncoding = await detectEncoding(fileBuffer)