Skip to content

Commit e9ce384

Browse files
authored
[PROTOBUS] Move commitSearch to protobus (RooCodeInc#3229)
* commitSearch protobus migration * rename * one small change to comments * moved GitCommmit proto mapping to proto-conversions
1 parent 5802b68 commit e9ce384

File tree

8 files changed

+309
-31
lines changed

8 files changed

+309
-31
lines changed

.changeset/funny-numbers-trade.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
searchCommits protobus migration

proto/file.proto

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import "common.proto";
1010
service FileService {
1111
// Opens a file in the editor
1212
rpc openFile(StringRequest) returns (Empty);
13-
13+
1414
// Opens an image in the system viewer
1515
rpc openImage(StringRequest) returns (Empty);
1616

@@ -19,6 +19,23 @@ service FileService {
1919

2020
// Creates a rule file from either global or workspace rules directory
2121
rpc createRuleFile(RuleFileRequest) returns (RuleFile);
22+
23+
// Search git commits in the workspace
24+
rpc searchCommits(StringRequest) returns (GitCommits);
25+
}
26+
27+
// Response for searchCommits
28+
message GitCommits {
29+
repeated GitCommit commits = 1;
30+
}
31+
32+
// Represents a Git commit
33+
message GitCommit {
34+
string hash = 1;
35+
string short_hash = 2;
36+
string subject = 3;
37+
string author = 4;
38+
string date = 5;
2239
}
2340

2441
// Unified request for all rule file operations

src/core/controller/file/methods.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { createRuleFile } from "./createRuleFile"
77
import { deleteRuleFile } from "./deleteRuleFile"
88
import { openFile } from "./openFile"
99
import { openImage } from "./openImage"
10+
import { searchCommits } from "./searchCommits"
1011

1112
// Register all file service methods
1213
export function registerAllMethods(): void {
@@ -15,4 +16,5 @@ export function registerAllMethods(): void {
1516
registerMethod("deleteRuleFile", deleteRuleFile)
1617
registerMethod("openFile", openFile)
1718
registerMethod("openImage", openImage)
19+
registerMethod("searchCommits", searchCommits)
1820
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Controller } from ".."
2+
import { GitCommits } from "@shared/proto/file"
3+
import { StringRequest } from "@shared/proto/common"
4+
import { searchCommits as searchCommitsUtil } from "@utils/git"
5+
import { getWorkspacePath } from "@utils/path"
6+
import { FileMethodHandler } from "./index"
7+
import { convertGitCommitsToProtoGitCommits } from "@shared/proto-conversions/file/git-commit-conversion"
8+
9+
/**
10+
* Searches for git commits in the workspace repository
11+
* @param controller The controller instance
12+
* @param request The request message containing the search query in the 'value' field
13+
* @returns GitCommits containing the matching commits
14+
*/
15+
export const searchCommits: FileMethodHandler = async (controller: Controller, request: StringRequest): Promise<GitCommits> => {
16+
const cwd = getWorkspacePath()
17+
if (!cwd) {
18+
return GitCommits.create({ commits: [] })
19+
}
20+
21+
try {
22+
const commits = await searchCommitsUtil(request.value || "", cwd)
23+
24+
const protoCommits = convertGitCommitsToProtoGitCommits(commits)
25+
26+
return GitCommits.create({ commits: protoCommits })
27+
} catch (error) {
28+
console.error(`Error searching commits: ${JSON.stringify(error)}`)
29+
return GitCommits.create({ commits: [] })
30+
}
31+
}

src/core/controller/index.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -538,21 +538,6 @@ export class Controller {
538538
this.mcpHub?.sendLatestMcpServers()
539539
break
540540
}
541-
case "searchCommits": {
542-
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
543-
if (cwd) {
544-
try {
545-
const commits = await searchCommits(message.text || "", cwd)
546-
await this.postMessageToWebview({
547-
type: "commitSearchResults",
548-
commits,
549-
})
550-
} catch (error) {
551-
console.error(`Error searching commits: ${JSON.stringify(error)}`)
552-
}
553-
}
554-
break
555-
}
556541
case "openExtensionSettings": {
557542
const settingsFilter = message.text || ""
558543
await vscode.commands.executeCommand(
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { GitCommit as ProtoGitCommit } from "@shared/proto/file"
2+
import { GitCommit } from "@utils/git"
3+
4+
/**
5+
* Converts domain GitCommit objects to proto GitCommit objects
6+
*/
7+
export function convertGitCommitsToProtoGitCommits(commits: GitCommit[]): ProtoGitCommit[] {
8+
return commits.map((commit) => ({
9+
hash: commit.hash,
10+
shortHash: commit.shortHash,
11+
subject: commit.subject,
12+
author: commit.author,
13+
date: commit.date,
14+
}))
15+
}
16+
17+
/**
18+
* Converts proto GitCommit objects to domain GitCommit objects
19+
*/
20+
export function convertProtoGitCommitsToGitCommits(protoCommits: ProtoGitCommit[]): GitCommit[] {
21+
return protoCommits.map((protoCommit) => ({
22+
hash: protoCommit.hash,
23+
shortHash: protoCommit.shortHash,
24+
subject: protoCommit.subject,
25+
author: protoCommit.author,
26+
date: protoCommit.date,
27+
}))
28+
}

src/shared/proto/file.ts

Lines changed: 207 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)