From f75d710ec623f18082e2940e1038e36fd053810c Mon Sep 17 00:00:00 2001 From: WillLillis Date: Sun, 21 Sep 2025 13:55:44 -0400 Subject: [PATCH] fix(rust): pass correct fd to C lib's ts_tree_print_dot_graph Co-authored-by: Amaan Qureshi (cherry picked from commit 92678f0fc58f8b3055f2c26abb81c8ccc4bece5c) --- cli/src/tests/parser_test.rs | 1 - lib/binding_rust/lib.rs | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/src/tests/parser_test.rs b/cli/src/tests/parser_test.rs index d8b9767d..1a1bf94e 100644 --- a/cli/src/tests/parser_test.rs +++ b/cli/src/tests/parser_test.rs @@ -87,7 +87,6 @@ fn test_parsing_with_logging() { } #[test] -#[cfg(unix)] fn test_parsing_with_debug_graph_enabled() { use std::io::{BufRead, BufReader, Seek}; diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index 5272f22a..72c2d5c9 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -1441,6 +1441,11 @@ impl Drop for Parser { } } +#[cfg(windows)] +extern "C" { + fn _open_osfhandle(osfhandle: isize, flags: core::ffi::c_int) -> core::ffi::c_int; +} + impl Tree { /// Get the root node of the syntax tree. #[doc(alias = "ts_tree_root_node")] @@ -1550,7 +1555,8 @@ impl Tree { #[cfg(windows)] { let handle = file.as_raw_handle(); - unsafe { ffi::ts_tree_print_dot_graph(self.0.as_ptr(), handle as i32) } + let fd = unsafe { _open_osfhandle(handle as isize, 0) }; + unsafe { ffi::ts_tree_print_dot_graph(self.0.as_ptr(), fd) } } } }