Skip to content

Commit 9eea9d0

Browse files
authored
getRelativePaths protobus migration (RooCodeInc#3259)
1 parent c839576 commit 9eea9d0

File tree

9 files changed

+235
-53
lines changed

9 files changed

+235
-53
lines changed

.changeset/curly-fireants-work.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+
getRelativePaths protobus migration

proto/file.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ service FileService {
2222

2323
// Search git commits in the workspace
2424
rpc searchCommits(StringRequest) returns (GitCommits);
25+
26+
// Convert URIs to workspace-relative paths
27+
rpc getRelativePaths(RelativePathsRequest) returns (RelativePaths);
28+
}
29+
30+
// Request to convert a list of URIs to relative paths
31+
message RelativePathsRequest {
32+
Metadata metadata = 1;
33+
repeated string uris = 2;
34+
}
35+
36+
// Response containing the converted relative paths
37+
message RelativePaths {
38+
repeated string paths = 1;
2539
}
2640

2741
// Response for searchCommits
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Controller } from ".."
2+
import { RelativePathsRequest, RelativePaths } from "@shared/proto/file"
3+
import { FileMethodHandler } from "./index"
4+
import * as vscode from "vscode"
5+
import * as path from "path"
6+
7+
/**
8+
* Converts a list of URIs to workspace-relative paths
9+
* @param controller The controller instance
10+
* @param request The request containing URIs to convert
11+
* @returns Response with resolved relative paths
12+
*/
13+
export const getRelativePaths: FileMethodHandler = async (
14+
controller: Controller,
15+
request: RelativePathsRequest,
16+
): Promise<RelativePaths> => {
17+
const resolvedPaths = await Promise.all(
18+
request.uris.map(async (uriString) => {
19+
try {
20+
const fileUri = vscode.Uri.parse(uriString, true)
21+
const relativePathToGet = vscode.workspace.asRelativePath(fileUri, false)
22+
23+
// If the path is still absolute, it's outside the workspace
24+
if (path.isAbsolute(relativePathToGet)) {
25+
console.warn(`Dropped file ${relativePathToGet} is outside the workspace. Sending original path.`)
26+
return fileUri.fsPath.replace(/\\/g, "/")
27+
} else {
28+
let finalPath = "/" + relativePathToGet.replace(/\\/g, "/")
29+
try {
30+
const stat = await vscode.workspace.fs.stat(fileUri)
31+
if (stat.type === vscode.FileType.Directory) {
32+
finalPath += "/"
33+
}
34+
} catch (statError) {
35+
console.error(`Error stating file ${fileUri.fsPath}:`, statError)
36+
}
37+
return finalPath
38+
}
39+
} catch (error) {
40+
console.error(`Error calculating relative path for ${uriString}:`, error)
41+
return null
42+
}
43+
}),
44+
)
45+
46+
// Filter out any null values from errors
47+
const validPaths = resolvedPaths.filter((path): path is string => path !== null)
48+
49+
return RelativePaths.create({ paths: validPaths })
50+
}

src/core/controller/file/methods.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { registerMethod } from "./index"
66
import { createRuleFile } from "./createRuleFile"
77
import { deleteRuleFile } from "./deleteRuleFile"
8+
import { getRelativePaths } from "./getRelativePaths"
89
import { openFile } from "./openFile"
910
import { openImage } from "./openImage"
1011
import { searchCommits } from "./searchCommits"
@@ -14,6 +15,7 @@ export function registerAllMethods(): void {
1415
// Register each method with the registry
1516
registerMethod("createRuleFile", createRuleFile)
1617
registerMethod("deleteRuleFile", deleteRuleFile)
18+
registerMethod("getRelativePaths", getRelativePaths)
1719
registerMethod("openFile", openFile)
1820
registerMethod("openImage", openImage)
1921
registerMethod("searchCommits", searchCommits)

src/core/controller/index.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -642,42 +642,6 @@ export class Controller {
642642
this.postMessageToWebview({ type: "relinquishControl" })
643643
break
644644
}
645-
case "getRelativePaths": {
646-
if (message.uris && message.uris.length > 0) {
647-
const resolvedPaths = await Promise.all(
648-
message.uris.map(async (uriString) => {
649-
try {
650-
const fileUri = vscode.Uri.parse(uriString, true)
651-
const relativePath = vscode.workspace.asRelativePath(fileUri, false)
652-
653-
if (path.isAbsolute(relativePath)) {
654-
console.warn(`Dropped file ${relativePath} is outside the workspace. Sending original path.`)
655-
return fileUri.fsPath.replace(/\\/g, "/")
656-
} else {
657-
let finalPath = "/" + relativePath.replace(/\\/g, "/")
658-
try {
659-
const stat = await vscode.workspace.fs.stat(fileUri)
660-
if (stat.type === vscode.FileType.Directory) {
661-
finalPath += "/"
662-
}
663-
} catch (statError) {
664-
console.error(`Error stating file ${fileUri.fsPath}:`, statError)
665-
}
666-
return finalPath
667-
}
668-
} catch (error) {
669-
console.error(`Error calculating relative path for ${uriString}:`, error)
670-
return null
671-
}
672-
}),
673-
)
674-
await this.postMessageToWebview({
675-
type: "relativePathsResponse",
676-
paths: resolvedPaths,
677-
})
678-
}
679-
break
680-
}
681645
case "searchFiles": {
682646
const workspacePath = getWorkspacePath()
683647

src/shared/ExtensionMessage.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ export interface ExtensionMessage {
4444
| "browserConnectionResult"
4545
| "scrollToSettings"
4646
| "browserRelaunchResult"
47-
| "relativePathsResponse" // Handles single and multiple path responses
4847
| "fileSearchResults"
4948
| "grpc_response" // New type for gRPC responses
5049
| "setActiveQuote"
5150
text?: string
52-
paths?: (string | null)[] // Used for relativePathsResponse
5351
action?:
5452
| "chatButtonClicked"
5553
| "mcpButtonClicked"

src/shared/WebviewMessage.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export interface WebviewMessage {
6161
| "relaunchChromeDebugMode"
6262
| "taskFeedback"
6363
| "scrollToSettings"
64-
| "getRelativePaths" // Handles single and multiple URI resolution
6564
| "searchFiles"
6665
| "toggleFavoriteModel"
6766
| "grpc_request"
@@ -75,7 +74,6 @@ export interface WebviewMessage {
7574

7675
// | "relaunchChromeDebugMode"
7776
text?: string
78-
uris?: string[] // Used for getRelativePaths
7977
disabled?: boolean
8078
askResponse?: ClineAskResponse
8179
apiConfiguration?: ApiConfiguration

src/shared/proto/file.ts

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

webview-ui/src/components/chat/ChatTextArea.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,6 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
309309
const handleMessage = useCallback((event: MessageEvent) => {
310310
const message: ExtensionMessage = event.data
311311
switch (message.type) {
312-
case "relativePathsResponse": {
313-
// New case for batch response
314-
const validPaths = message.paths?.filter((path): path is string => !!path) || []
315-
if (validPaths.length > 0) {
316-
setPendingInsertions((prev) => [...prev, ...validPaths])
317-
}
318-
break
319-
}
320-
321312
case "fileSearchResults": {
322313
// Only update results if they match the current query or if there's no mentionsRequestId - better UX
323314
if (!message.mentionsRequestId || message.mentionsRequestId === currentSearchQueryRef.current) {
@@ -1154,10 +1145,15 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
11541145
}
11551146
setIntendedCursorPosition(initialCursorPos)
11561147

1157-
vscode.postMessage({
1158-
type: "getRelativePaths",
1159-
uris: validUris,
1160-
})
1148+
FileServiceClient.getRelativePaths({ uris: validUris })
1149+
.then((response) => {
1150+
if (response.paths.length > 0) {
1151+
setPendingInsertions((prev) => [...prev, ...response.paths])
1152+
}
1153+
})
1154+
.catch((error) => {
1155+
console.error("Error getting relative paths:", error)
1156+
})
11611157
return
11621158
}
11631159

0 commit comments

Comments
 (0)