From 1b30a6e86ac859ef92510c3398190cc423c4acbc Mon Sep 17 00:00:00 2001 From: Cameron Mulhern Date: Tue, 3 Feb 2026 20:19:30 +0000 Subject: [PATCH] Fixes rust-analyzer include_dirs for crates with generated sources --- rust/private/rust_analyzer.bzl | 5 ++++- .../generated_srcs_test/rust_project_json_test.rs | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/rust/private/rust_analyzer.bzl b/rust/private/rust_analyzer.bzl index da41867985..d8c98d0625 100644 --- a/rust/private/rust_analyzer.bzl +++ b/rust/private/rust_analyzer.bzl @@ -256,7 +256,10 @@ def _create_single_crate(ctx, attrs, info): src_map = {src.short_path: src for src in srcs if src.is_source} if info.crate.root.short_path in src_map: crate["root_module"] = _WORKSPACE_TEMPLATE + src_map[info.crate.root.short_path].path - crate["source"]["include_dirs"].append(path_prefix + info.crate.root.dirname) + crate["source"]["include_dirs"].extend([ + _WORKSPACE_TEMPLATE + src_map[info.crate.root.short_path].dirname, + path_prefix + info.crate.root.dirname, + ]) if info.build_info != None and info.build_info.out_dir != None: out_dir_path = info.build_info.out_dir.path diff --git a/test/rust_analyzer/generated_srcs_test/rust_project_json_test.rs b/test/rust_analyzer/generated_srcs_test/rust_project_json_test.rs index d9ce7579c5..707664a7dd 100644 --- a/test/rust_analyzer/generated_srcs_test/rust_project_json_test.rs +++ b/test/rust_analyzer/generated_srcs_test/rust_project_json_test.rs @@ -50,7 +50,12 @@ mod tests { assert!(with_gen.root_module.ends_with("/lib.rs")); let include_dirs = &with_gen.source.as_ref().unwrap().include_dirs; - assert!(include_dirs.len() == 1); - assert!(include_dirs[0].starts_with(output_base)); + assert_eq!(include_dirs.len(), 2); + + // The first entry is the workspace directory. + assert!(!include_dirs[0].starts_with(output_base)); + + // The second entry is the output base, where the generated files are located. + assert!(include_dirs[1].starts_with(output_base)); } }