Skip to content

Commit 46ad2ee

Browse files
authored
Merge pull request #10889 from gitbutlerapp/normalize-file-paths-to-workspace-root
Fixes an issue where the cursor hooks would not work
2 parents 8ffdfec + 1b8ad19 commit 46ad2ee

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

crates/but-cursor/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub struct StopEvent {
106106
}
107107

108108
pub async fn handle_after_edit() -> anyhow::Result<CursorHookOutput> {
109-
let input: FileEditEvent = serde_json::from_str(&stdin()?)
109+
let mut input: FileEditEvent = serde_json::from_str(&stdin()?)
110110
.map_err(|e| anyhow::anyhow!("Failed to parse input JSON: {}", e))?;
111111
let hook_headers = input
112112
.edits
@@ -120,6 +120,14 @@ pub async fn handle_after_edit() -> anyhow::Result<CursorHookOutput> {
120120
.first()
121121
.ok_or_else(|| anyhow::anyhow!("No workspace roots provided"))
122122
.map(std::path::Path::new)?;
123+
124+
// Convert file_path from absolute to relative
125+
let absolute_path = std::path::Path::new(&input.file_path);
126+
input.file_path = absolute_path
127+
.strip_prefix(dir)
128+
.map(|p| p.to_string_lossy().to_string())
129+
.unwrap_or(input.file_path);
130+
123131
let repo = gix::discover(dir)?;
124132
let project = Project::from_path(
125133
repo.workdir()

0 commit comments

Comments
 (0)