Add new RPCs to the host bridge diff service (#4997)
* Add truncate document to the hostbridge diff service. # Conflicts: # src/standalone/ExternalDiffviewProvider.ts * Fix typo * Add host bridge rpcs for the diff service * Add saveDocument and closeDiff to the host bridge. * Formatting * Use the host bridge in ExternalDiffviewProvider * Make comments less verbose
This commit is contained in:
1 parent
45241fcccf
commit
b3fa3ad0d3
9 files changed
+75
-16
No files matched your search
+29
-2
@@ -10,7 +10,14 @@ import "common.proto";
|
||||
service DiffService {
|
||||
// Open the diff view/editor.
|
||||
rpc openDiff(OpenDiffRequest) returns (OpenDiffResponse);
|
||||
// Replace a text selection in the diff.
|
||||
rpc replaceText(ReplaceTextRequest) returns (ReplaceTextResponse);
|
||||
// Truncate the diff document.
|
||||
rpc truncateDocument(TruncateDocumentRequest) returns (TruncateDocumentResponse);
|
||||
// Save the diff document.
|
||||
rpc saveDocument(SaveDocumentRequest) returns (SaveDocumentResponse);
|
||||
// Close the diff editor UI.
|
||||
rpc closeDiff(CloseDiffRequest) returns (CloseDiffResponse);
|
||||
}
|
||||
|
||||
message OpenDiffRequest {
|
||||
@@ -34,6 +41,26 @@ message ReplaceTextRequest {
|
||||
optional int32 end_line = 5;
|
||||
}
|
||||
|
||||
message ReplaceTextResponse {
|
||||
// TBD
|
||||
message ReplaceTextResponse {}
|
||||
|
||||
message TruncateDocumentRequest {
|
||||
optional cline.Metadata metadata = 1;
|
||||
optional string diff_id = 2;
|
||||
optional int32 end_line = 5;
|
||||
}
|
||||
|
||||
message TruncateDocumentResponse {}
|
||||
|
||||
message CloseDiffRequest {
|
||||
optional cline.Metadata metadata = 1;
|
||||
optional string diff_id = 2;
|
||||
}
|
||||
|
||||
message CloseDiffResponse {}
|
||||
|
||||
message SaveDocumentRequest {
|
||||
optional cline.Metadata metadata = 1;
|
||||
optional string diff_id = 2;
|
||||
}
|
||||
|
||||
message SaveDocumentResponse {}
|
||||
@@ -6,6 +6,10 @@ option java_multiple_files = true;
|
||||
|
||||
import "common.proto";
|
||||
|
||||
/**
|
||||
* The watch service is only here as example of a streaming rpc in the host bridge.
|
||||
* This being replaced with a native JS file watcher.
|
||||
*/
|
||||
// WatchService provides methods for watching files in the IDE
|
||||
service WatchService {
|
||||
// Subscribe to file changes
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { CloseDiffRequest, CloseDiffResponse } from "@/shared/proto/index.host"
|
||||
|
||||
export async function closeDiff(_request: CloseDiffRequest): Promise<CloseDiffResponse> {
|
||||
throw new Error("diffService is not supported. Use the VscodeDiffViewProvider.")
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { OpenDiffRequest, OpenDiffResponse } from "@/shared/proto/index.host"
|
||||
|
||||
export async function openDiff(_request: OpenDiffRequest): Promise<OpenDiffResponse> {
|
||||
throw new Error("diffService.openDiff is not supported. Use the VscodeDiffViewProvider.")
|
||||
throw new Error("diffService is not supported. Use the VscodeDiffViewProvider.")
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ReplaceTextRequest, ReplaceTextResponse } from "@/shared/proto/index.host"
|
||||
|
||||
export async function replaceText(_request: ReplaceTextRequest): Promise<ReplaceTextResponse> {
|
||||
throw new Error("diffService.replaceText is not supported. Use the VscodeDiffViewProvider.")
|
||||
throw new Error("diffService is not supported. Use the VscodeDiffViewProvider.")
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { ReplaceTextRequest, ReplaceTextResponse, SaveDocumentRequest, SaveDocumentResponse } from "@/shared/proto/index.host"
|
||||
|
||||
export async function saveDocument(_request: SaveDocumentRequest): Promise<SaveDocumentResponse> {
|
||||
throw new Error("diffService is not supported. Use the VscodeDiffViewProvider.")
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { TruncateDocumentRequest, TruncateDocumentResponse } from "@/shared/proto/index.host"
|
||||
|
||||
export async function truncateDocument(_request: TruncateDocumentRequest): Promise<TruncateDocumentResponse> {
|
||||
throw new Error("diffService is not supported. Use the VscodeDiffViewProvider.")
|
||||
}
|
||||
@@ -66,10 +66,6 @@ export abstract class DiffViewProvider {
|
||||
/**
|
||||
* Opens a diff editor or viewer for the current file.
|
||||
*
|
||||
* This abstract method must be implemented by subclasses to create and display
|
||||
* a diff editor or viewer that shows the difference between the original and
|
||||
* modified content.
|
||||
*
|
||||
* Called automatically by the `open` method after ensuring the file exists and
|
||||
* creating any necessary directories.
|
||||
*
|
||||
@@ -80,9 +76,7 @@ export abstract class DiffViewProvider {
|
||||
/**
|
||||
* Scrolls the diff editor to reveal a specific line.
|
||||
*
|
||||
* This abstract method must be implemented by subclasses to handle scrolling
|
||||
* the diff editor view to ensure a specific line is visible. It's used during
|
||||
* streaming updates to keep the user's view focused on the changing content.
|
||||
* It's used during streaming updates to keep the user's view focused on the changing content.
|
||||
*
|
||||
* @param line The 0-based line number to scroll to
|
||||
*/
|
||||
@@ -91,9 +85,7 @@ export abstract class DiffViewProvider {
|
||||
/**
|
||||
* Creates a smooth scrolling animation between two lines in the diff editor.
|
||||
*
|
||||
* This abstract method must be implemented by subclasses to provide a visual
|
||||
* animation effect when scrolling through large changes. It's typically used
|
||||
* when updates contain many lines, to help the user visually track the flow
|
||||
* It's typically used when updates contain many lines, to help the user visually track the flow
|
||||
* of significant changes in the document.
|
||||
*
|
||||
* @param startLine The 0-based line number to begin the animation from
|
||||
|
||||
@@ -3,6 +3,7 @@ import { DiffViewProvider } from "@/integrations/editor/DiffViewProvider"
|
||||
|
||||
export class ExternalDiffViewProvider extends DiffViewProvider {
|
||||
private activeDiffEditorId: string | undefined
|
||||
|
||||
override async openDiffEditor(): Promise<void> {
|
||||
if (!this.absolutePath) {
|
||||
return
|
||||
@@ -19,6 +20,9 @@ export class ExternalDiffViewProvider extends DiffViewProvider {
|
||||
rangeToReplace: { startLine: number; endLine: number },
|
||||
_currentLine: number,
|
||||
): Promise<void> {
|
||||
if (!this.activeDiffEditor) {
|
||||
return
|
||||
}
|
||||
await getHostBridgeProvider().diffClient.replaceText({
|
||||
diffId: this.activeDiffEditorId,
|
||||
content: content,
|
||||
@@ -28,7 +32,20 @@ export class ExternalDiffViewProvider extends DiffViewProvider {
|
||||
}
|
||||
|
||||
protected override async truncateDocument(lineNumber: number): Promise<void> {
|
||||
console.log(`Called ExternalDiffViewProvider.truncateDocument(${lineNumber}) stub`)
|
||||
if (!this.activeDiffEditor) {
|
||||
return
|
||||
}
|
||||
await getHostBridgeProvider().diffClient.truncateDocument({
|
||||
diffId: this.activeDiffEditorId,
|
||||
endLine: lineNumber,
|
||||
})
|
||||
}
|
||||
|
||||
protected async saveDocument(): Promise<void> {
|
||||
if (!this.activeDiffEditor) {
|
||||
return
|
||||
}
|
||||
await getHostBridgeProvider().diffClient.saveDocument({ diffId: this.activeDiffEditorId })
|
||||
}
|
||||
|
||||
protected override async scrollEditorToLine(line: number): Promise<void> {
|
||||
@@ -39,7 +56,11 @@ export class ExternalDiffViewProvider extends DiffViewProvider {
|
||||
console.log(`Called ExternalDiffViewProvider.scrollAnimation(${startLine}, ${endLine}) stub`)
|
||||
}
|
||||
protected override async closeDiffView(): Promise<void> {
|
||||
console.log(`Called ExternalDiffViewProvider.closeDiffView() stub`)
|
||||
if (!this.activeDiffEditor) {
|
||||
return
|
||||
}
|
||||
await getHostBridgeProvider().diffClient.closeDiff({ diffId: this.activeDiffEditorId })
|
||||
this.activeDiffEditorId = undefined
|
||||
}
|
||||
|
||||
protected override async resetDiffView(): Promise<void> {
|
||||
|
||||
Reference in new issue
Block a user