[PROTOBUS] Move commitSearch to protobus (#3229)
* commitSearch protobus migration * rename * one small change to comments * moved GitCommmit proto mapping to proto-conversions
This commit is contained in:
1 parent
5802b6847e
commit
e9ce38472f
8 files changed
+309
-31
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
searchCommits protobus migration
|
||||
+18
-1
@@ -10,7 +10,7 @@ import "common.proto";
|
||||
service FileService {
|
||||
// Opens a file in the editor
|
||||
rpc openFile(StringRequest) returns (Empty);
|
||||
|
||||
|
||||
// Opens an image in the system viewer
|
||||
rpc openImage(StringRequest) returns (Empty);
|
||||
|
||||
@@ -19,6 +19,23 @@ service FileService {
|
||||
|
||||
// Creates a rule file from either global or workspace rules directory
|
||||
rpc createRuleFile(RuleFileRequest) returns (RuleFile);
|
||||
|
||||
// Search git commits in the workspace
|
||||
rpc searchCommits(StringRequest) returns (GitCommits);
|
||||
}
|
||||
|
||||
// Response for searchCommits
|
||||
message GitCommits {
|
||||
repeated GitCommit commits = 1;
|
||||
}
|
||||
|
||||
// Represents a Git commit
|
||||
message GitCommit {
|
||||
string hash = 1;
|
||||
string short_hash = 2;
|
||||
string subject = 3;
|
||||
string author = 4;
|
||||
string date = 5;
|
||||
}
|
||||
|
||||
// Unified request for all rule file operations
|
||||
|
||||
@@ -7,6 +7,7 @@ import { createRuleFile } from "./createRuleFile"
|
||||
import { deleteRuleFile } from "./deleteRuleFile"
|
||||
import { openFile } from "./openFile"
|
||||
import { openImage } from "./openImage"
|
||||
import { searchCommits } from "./searchCommits"
|
||||
|
||||
// Register all file service methods
|
||||
export function registerAllMethods(): void {
|
||||
@@ -15,4 +16,5 @@ export function registerAllMethods(): void {
|
||||
registerMethod("deleteRuleFile", deleteRuleFile)
|
||||
registerMethod("openFile", openFile)
|
||||
registerMethod("openImage", openImage)
|
||||
registerMethod("searchCommits", searchCommits)
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Controller } from ".."
|
||||
import { GitCommits } from "@shared/proto/file"
|
||||
import { StringRequest } from "@shared/proto/common"
|
||||
import { searchCommits as searchCommitsUtil } from "@utils/git"
|
||||
import { getWorkspacePath } from "@utils/path"
|
||||
import { FileMethodHandler } from "./index"
|
||||
import { convertGitCommitsToProtoGitCommits } from "@shared/proto-conversions/file/git-commit-conversion"
|
||||
|
||||
/**
|
||||
* Searches for git commits in the workspace repository
|
||||
* @param controller The controller instance
|
||||
* @param request The request message containing the search query in the 'value' field
|
||||
* @returns GitCommits containing the matching commits
|
||||
*/
|
||||
export const searchCommits: FileMethodHandler = async (controller: Controller, request: StringRequest): Promise<GitCommits> => {
|
||||
const cwd = getWorkspacePath()
|
||||
if (!cwd) {
|
||||
return GitCommits.create({ commits: [] })
|
||||
}
|
||||
|
||||
try {
|
||||
const commits = await searchCommitsUtil(request.value || "", cwd)
|
||||
|
||||
const protoCommits = convertGitCommitsToProtoGitCommits(commits)
|
||||
|
||||
return GitCommits.create({ commits: protoCommits })
|
||||
} catch (error) {
|
||||
console.error(`Error searching commits: ${JSON.stringify(error)}`)
|
||||
return GitCommits.create({ commits: [] })
|
||||
}
|
||||
}
|
||||
@@ -538,21 +538,6 @@ export class Controller {
|
||||
this.mcpHub?.sendLatestMcpServers()
|
||||
break
|
||||
}
|
||||
case "searchCommits": {
|
||||
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
|
||||
if (cwd) {
|
||||
try {
|
||||
const commits = await searchCommits(message.text || "", cwd)
|
||||
await this.postMessageToWebview({
|
||||
type: "commitSearchResults",
|
||||
commits,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(`Error searching commits: ${JSON.stringify(error)}`)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
case "openExtensionSettings": {
|
||||
const settingsFilter = message.text || ""
|
||||
await vscode.commands.executeCommand(
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { GitCommit as ProtoGitCommit } from "@shared/proto/file"
|
||||
import { GitCommit } from "@utils/git"
|
||||
|
||||
/**
|
||||
* Converts domain GitCommit objects to proto GitCommit objects
|
||||
*/
|
||||
export function convertGitCommitsToProtoGitCommits(commits: GitCommit[]): ProtoGitCommit[] {
|
||||
return commits.map((commit) => ({
|
||||
hash: commit.hash,
|
||||
shortHash: commit.shortHash,
|
||||
subject: commit.subject,
|
||||
author: commit.author,
|
||||
date: commit.date,
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts proto GitCommit objects to domain GitCommit objects
|
||||
*/
|
||||
export function convertProtoGitCommitsToGitCommits(protoCommits: ProtoGitCommit[]): GitCommit[] {
|
||||
return protoCommits.map((protoCommit) => ({
|
||||
hash: protoCommit.hash,
|
||||
shortHash: protoCommit.shortHash,
|
||||
subject: protoCommit.subject,
|
||||
author: protoCommit.author,
|
||||
date: protoCommit.date,
|
||||
}))
|
||||
}
|
||||
@@ -10,6 +10,20 @@ import { Empty, Metadata, StringRequest } from "./common"
|
||||
|
||||
export const protobufPackage = "cline"
|
||||
|
||||
/** Response for searchCommits */
|
||||
export interface GitCommits {
|
||||
commits: GitCommit[]
|
||||
}
|
||||
|
||||
/** Represents a Git commit */
|
||||
export interface GitCommit {
|
||||
hash: string
|
||||
shortHash: string
|
||||
subject: string
|
||||
author: string
|
||||
date: string
|
||||
}
|
||||
|
||||
/** Unified request for all rule file operations */
|
||||
export interface RuleFileRequest {
|
||||
metadata?: Metadata | undefined
|
||||
@@ -31,6 +45,190 @@ export interface RuleFile {
|
||||
alreadyExists: boolean
|
||||
}
|
||||
|
||||
function createBaseGitCommits(): GitCommits {
|
||||
return { commits: [] }
|
||||
}
|
||||
|
||||
export const GitCommits: MessageFns<GitCommits> = {
|
||||
encode(message: GitCommits, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
||||
for (const v of message.commits) {
|
||||
GitCommit.encode(v!, writer.uint32(10).fork()).join()
|
||||
}
|
||||
return writer
|
||||
},
|
||||
|
||||
decode(input: BinaryReader | Uint8Array, length?: number): GitCommits {
|
||||
const reader = input instanceof BinaryReader ? input : new BinaryReader(input)
|
||||
let end = length === undefined ? reader.len : reader.pos + length
|
||||
const message = createBaseGitCommits()
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32()
|
||||
switch (tag >>> 3) {
|
||||
case 1: {
|
||||
if (tag !== 10) {
|
||||
break
|
||||
}
|
||||
|
||||
message.commits.push(GitCommit.decode(reader, reader.uint32()))
|
||||
continue
|
||||
}
|
||||
}
|
||||
if ((tag & 7) === 4 || tag === 0) {
|
||||
break
|
||||
}
|
||||
reader.skip(tag & 7)
|
||||
}
|
||||
return message
|
||||
},
|
||||
|
||||
fromJSON(object: any): GitCommits {
|
||||
return {
|
||||
commits: globalThis.Array.isArray(object?.commits) ? object.commits.map((e: any) => GitCommit.fromJSON(e)) : [],
|
||||
}
|
||||
},
|
||||
|
||||
toJSON(message: GitCommits): unknown {
|
||||
const obj: any = {}
|
||||
if (message.commits?.length) {
|
||||
obj.commits = message.commits.map((e) => GitCommit.toJSON(e))
|
||||
}
|
||||
return obj
|
||||
},
|
||||
|
||||
create<I extends Exact<DeepPartial<GitCommits>, I>>(base?: I): GitCommits {
|
||||
return GitCommits.fromPartial(base ?? ({} as any))
|
||||
},
|
||||
fromPartial<I extends Exact<DeepPartial<GitCommits>, I>>(object: I): GitCommits {
|
||||
const message = createBaseGitCommits()
|
||||
message.commits = object.commits?.map((e) => GitCommit.fromPartial(e)) || []
|
||||
return message
|
||||
},
|
||||
}
|
||||
|
||||
function createBaseGitCommit(): GitCommit {
|
||||
return { hash: "", shortHash: "", subject: "", author: "", date: "" }
|
||||
}
|
||||
|
||||
export const GitCommit: MessageFns<GitCommit> = {
|
||||
encode(message: GitCommit, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
||||
if (message.hash !== "") {
|
||||
writer.uint32(10).string(message.hash)
|
||||
}
|
||||
if (message.shortHash !== "") {
|
||||
writer.uint32(18).string(message.shortHash)
|
||||
}
|
||||
if (message.subject !== "") {
|
||||
writer.uint32(26).string(message.subject)
|
||||
}
|
||||
if (message.author !== "") {
|
||||
writer.uint32(34).string(message.author)
|
||||
}
|
||||
if (message.date !== "") {
|
||||
writer.uint32(42).string(message.date)
|
||||
}
|
||||
return writer
|
||||
},
|
||||
|
||||
decode(input: BinaryReader | Uint8Array, length?: number): GitCommit {
|
||||
const reader = input instanceof BinaryReader ? input : new BinaryReader(input)
|
||||
let end = length === undefined ? reader.len : reader.pos + length
|
||||
const message = createBaseGitCommit()
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32()
|
||||
switch (tag >>> 3) {
|
||||
case 1: {
|
||||
if (tag !== 10) {
|
||||
break
|
||||
}
|
||||
|
||||
message.hash = reader.string()
|
||||
continue
|
||||
}
|
||||
case 2: {
|
||||
if (tag !== 18) {
|
||||
break
|
||||
}
|
||||
|
||||
message.shortHash = reader.string()
|
||||
continue
|
||||
}
|
||||
case 3: {
|
||||
if (tag !== 26) {
|
||||
break
|
||||
}
|
||||
|
||||
message.subject = reader.string()
|
||||
continue
|
||||
}
|
||||
case 4: {
|
||||
if (tag !== 34) {
|
||||
break
|
||||
}
|
||||
|
||||
message.author = reader.string()
|
||||
continue
|
||||
}
|
||||
case 5: {
|
||||
if (tag !== 42) {
|
||||
break
|
||||
}
|
||||
|
||||
message.date = reader.string()
|
||||
continue
|
||||
}
|
||||
}
|
||||
if ((tag & 7) === 4 || tag === 0) {
|
||||
break
|
||||
}
|
||||
reader.skip(tag & 7)
|
||||
}
|
||||
return message
|
||||
},
|
||||
|
||||
fromJSON(object: any): GitCommit {
|
||||
return {
|
||||
hash: isSet(object.hash) ? globalThis.String(object.hash) : "",
|
||||
shortHash: isSet(object.shortHash) ? globalThis.String(object.shortHash) : "",
|
||||
subject: isSet(object.subject) ? globalThis.String(object.subject) : "",
|
||||
author: isSet(object.author) ? globalThis.String(object.author) : "",
|
||||
date: isSet(object.date) ? globalThis.String(object.date) : "",
|
||||
}
|
||||
},
|
||||
|
||||
toJSON(message: GitCommit): unknown {
|
||||
const obj: any = {}
|
||||
if (message.hash !== "") {
|
||||
obj.hash = message.hash
|
||||
}
|
||||
if (message.shortHash !== "") {
|
||||
obj.shortHash = message.shortHash
|
||||
}
|
||||
if (message.subject !== "") {
|
||||
obj.subject = message.subject
|
||||
}
|
||||
if (message.author !== "") {
|
||||
obj.author = message.author
|
||||
}
|
||||
if (message.date !== "") {
|
||||
obj.date = message.date
|
||||
}
|
||||
return obj
|
||||
},
|
||||
|
||||
create<I extends Exact<DeepPartial<GitCommit>, I>>(base?: I): GitCommit {
|
||||
return GitCommit.fromPartial(base ?? ({} as any))
|
||||
},
|
||||
fromPartial<I extends Exact<DeepPartial<GitCommit>, I>>(object: I): GitCommit {
|
||||
const message = createBaseGitCommit()
|
||||
message.hash = object.hash ?? ""
|
||||
message.shortHash = object.shortHash ?? ""
|
||||
message.subject = object.subject ?? ""
|
||||
message.author = object.author ?? ""
|
||||
message.date = object.date ?? ""
|
||||
return message
|
||||
},
|
||||
}
|
||||
|
||||
function createBaseRuleFileRequest(): RuleFileRequest {
|
||||
return { metadata: undefined, isGlobal: false, rulePath: undefined, filename: undefined }
|
||||
}
|
||||
@@ -274,6 +472,15 @@ export const FileServiceDefinition = {
|
||||
responseStream: false,
|
||||
options: {},
|
||||
},
|
||||
/** Search git commits in the workspace */
|
||||
searchCommits: {
|
||||
name: "searchCommits",
|
||||
requestType: StringRequest,
|
||||
requestStream: false,
|
||||
responseType: GitCommits,
|
||||
responseStream: false,
|
||||
options: {},
|
||||
},
|
||||
},
|
||||
} as const
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
import { useMetaKeyDetection, useShortcut } from "@/utils/hooks"
|
||||
import { validateApiConfiguration, validateModelId } from "@/utils/validate"
|
||||
import { vscode } from "@/utils/vscode"
|
||||
import { FileServiceClient } from "@/services/grpc-client"
|
||||
import { CODE_BLOCK_BG_COLOR } from "@/components/common/CodeBlock"
|
||||
import Thumbnails from "@/components/common/Thumbnails"
|
||||
import Tooltip from "@/components/common/Tooltip"
|
||||
@@ -282,27 +283,29 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
|
||||
// Fetch git commits when Git is selected or when typing a hash
|
||||
useEffect(() => {
|
||||
if (selectedType === ContextMenuOptionType.Git || /^[a-f0-9]+$/i.test(searchQuery)) {
|
||||
vscode.postMessage({
|
||||
type: "searchCommits",
|
||||
text: searchQuery || "",
|
||||
})
|
||||
FileServiceClient.searchCommits({ value: searchQuery || "" })
|
||||
.then((response) => {
|
||||
if (response.commits) {
|
||||
const commits: GitCommit[] = response.commits.map(
|
||||
(commit: { hash: string; shortHash: string; subject: string; author: string; date: string }) => ({
|
||||
type: ContextMenuOptionType.Git,
|
||||
value: commit.hash,
|
||||
label: commit.subject,
|
||||
description: `${commit.shortHash} by ${commit.author} on ${commit.date}`,
|
||||
}),
|
||||
)
|
||||
setGitCommits(commits)
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error searching commits:", error)
|
||||
})
|
||||
}
|
||||
}, [selectedType, searchQuery])
|
||||
|
||||
const handleMessage = useCallback((event: MessageEvent) => {
|
||||
const message: ExtensionMessage = event.data
|
||||
switch (message.type) {
|
||||
case "commitSearchResults": {
|
||||
const commits: GitCommit[] =
|
||||
message.commits?.map((commit) => ({
|
||||
type: ContextMenuOptionType.Git,
|
||||
value: commit.hash,
|
||||
label: commit.subject,
|
||||
description: `${commit.shortHash} by ${commit.author} on ${commit.date}`,
|
||||
})) || []
|
||||
setGitCommits(commits)
|
||||
break
|
||||
}
|
||||
case "relativePathsResponse": {
|
||||
// New case for batch response
|
||||
const validPaths = message.paths?.filter((path): path is string => !!path) || []
|
||||
|
||||
Reference in new issue
Block a user