Skip to content

Commit ac7693c

Browse files
committed
refactor: address PR review comments
- Change build_refresh_config from pub to pub(crate) to avoid expanding API surface - Use tempfile::TempDir in test for deterministic is_dir() behavior
1 parent d611162 commit ac7693c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

crates/pet/src/jsonrpc.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ pub fn handle_clear_cache(_context: Arc<Context>, id: u32, _params: Value) {
472472
/// This is extracted from handle_refresh to enable unit testing.
473473
///
474474
/// Returns (modified_config, search_scope)
475-
pub fn build_refresh_config(
475+
pub(crate) fn build_refresh_config(
476476
refresh_options: &RefreshOptions,
477477
mut config: Configuration,
478478
) -> (Configuration, Option<SearchScope>) {
@@ -560,24 +560,27 @@ mod tests {
560560
/// Test that when searchPaths is provided, workspace_directories ARE replaced.
561561
#[test]
562562
fn test_search_paths_replaces_workspace_directories() {
563+
let temp_dir = tempfile::tempdir().unwrap();
564+
let search_dir = temp_dir.path().join("search_path");
565+
std::fs::create_dir(&search_dir).unwrap();
566+
563567
let original_workspace = PathBuf::from("/original/workspace");
564568
let config = Configuration {
565569
workspace_directories: Some(vec![original_workspace]),
566570
..Default::default()
567571
};
568572

569-
// Note: search_paths won't exist as directories in tests, so expanded result will be empty
570573
let refresh_options = RefreshOptions {
571574
search_kind: None,
572-
search_paths: Some(vec![PathBuf::from("/search/path")]),
575+
search_paths: Some(vec![search_dir.clone()]),
573576
};
574577

575578
let (result_config, search_scope) = build_refresh_config(&refresh_options, config);
576579

577-
// workspace_directories should be replaced (empty since paths don't exist)
580+
// workspace_directories should be replaced with the search_paths directory
578581
assert_eq!(
579582
result_config.workspace_directories,
580-
Some(vec![]),
583+
Some(vec![search_dir]),
581584
"workspace_directories should be replaced by search_paths"
582585
);
583586

0 commit comments

Comments
 (0)