Skip to content

Commit 76034d1

Browse files
committed
refactor: env to args
1 parent c630f90 commit 76034d1

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/doc_loader.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub struct Document {
3838
/// then loads and parses the HTML documents.
3939
/// Extracts text content from the main content area of rustdoc generated HTML.
4040
pub fn load_documents(crate_name: &str, _crate_version: &str) -> Result<Vec<Document>, DocLoaderError> { // Mark version as unused for now
41+
println!("[DEBUG] load_documents called with crate_name: '{}', crate_version: '{}'", crate_name, _crate_version);
4142
let mut documents = Vec::new();
4243

4344
let temp_dir = tempdir().map_err(DocLoaderError::TempDirCreationFailed)?;
@@ -51,27 +52,42 @@ pub fn load_documents(crate_name: &str, _crate_version: &str) -> Result<Vec<Docu
5152

5253
// Execute `cargo doc` using std::process::Command
5354
// --- Use Cargo API ---
54-
let config = GlobalContext::default()?;
55+
let mut config = GlobalContext::default()?; // Make mutable
56+
// Configure context for quiet operation
57+
config.configure(
58+
0, // verbose
59+
true, // quiet
60+
None, // color
61+
false, // frozen
62+
false, // locked
63+
false, // offline
64+
&None, // target_dir (Using ws.set_target_dir instead)
65+
&[], // unstable_flags
66+
&[], // cli_config
67+
)?;
5568
// config.shell().set_verbosity(Verbosity::Quiet); // Keep commented
5669

5770
let current_dir = std::env::current_dir()?;
5871
let mut ws = Workspace::new(&current_dir.join("Cargo.toml"), &config)?; // Make ws mutable
72+
println!("[DEBUG] Workspace target dir before set: {}", ws.target_dir().as_path_unlocked().display());
5973
// Set target_dir directly on Workspace
6074
ws.set_target_dir(cargo::util::Filesystem::new(temp_dir_path.to_path_buf()));
75+
println!("[DEBUG] Workspace target dir after set: {}", ws.target_dir().as_path_unlocked().display());
6176

6277
// Create CompileOptions, relying on ::new for BuildConfig
6378
let mut compile_opts = CompileOptions::new(&config, cargo::core::compiler::CompileMode::Doc { deps: false, json: false })?;
6479
// Specify the package explicitly
6580
let package_spec = crate_name.replace('-', "_"); // Just use name (with underscores)
6681
compile_opts.cli_features = CliFeatures::new_all(false); // Use new_all(false)
67-
compile_opts.spec = Packages::Packages(vec![package_spec]);
82+
compile_opts.spec = Packages::Packages(vec![package_spec.clone()]); // Clone spec
6883

6984
// Create DocOptions: Pass compile options
7085
let doc_opts = DocOptions {
7186
compile_opts,
7287
open_result: false, // Don't open in browser
7388
output_format: ops::OutputFormat::Html,
7489
};
90+
println!("[DEBUG] package_spec for CompileOptions: '{}'", package_spec);
7591

7692
ops::doc(&ws, &doc_opts).map_err(DocLoaderError::CargoLib)?; // Use ws
7793
// --- End Cargo API ---
@@ -80,6 +96,11 @@ pub fn load_documents(crate_name: &str, _crate_version: &str) -> Result<Vec<Docu
8096
let crate_name_underscores = crate_name.replace('-', "_");
8197
let docs_path = temp_dir_path.join("doc").join(&crate_name_underscores);
8298

99+
// Debug print relevant options before calling ops::doc
100+
println!("[DEBUG] CompileOptions spec: {:?}", doc_opts.compile_opts.spec);
101+
println!("[DEBUG] CompileOptions cli_features: {:?}", doc_opts.compile_opts.cli_features);
102+
println!("[DEBUG] CompileOptions build_config mode: {:?}", doc_opts.compile_opts.build_config.mode);
103+
println!("[DEBUG] DocOptions output_format: {:?}", doc_opts.output_format);
83104
if !docs_path.exists() || !docs_path.is_dir() {
84105
return Err(DocLoaderError::CargoLib(anyhow::anyhow!(
85106
"Generated documentation not found at expected path: {}. Check crate name and cargo doc output.",
@@ -88,13 +109,16 @@ pub fn load_documents(crate_name: &str, _crate_version: &str) -> Result<Vec<Docu
88109
}
89110
println!("Generated documentation path: {}", docs_path.display());
90111

112+
println!("[DEBUG] ops::doc called successfully.");
91113

92114
// Define the CSS selector for the main content area in rustdoc HTML
93115
// This might need adjustment based on the exact rustdoc version/theme
94116
let content_selector = Selector::parse("section#main-content.content")
95117
.map_err(|e| DocLoaderError::Selector(e.to_string()))?;
118+
println!("[DEBUG] Calculated final docs_path: {}", docs_path.display());
96119

97120
println!("Starting document loading from: {}", docs_path.display());
121+
println!("[DEBUG] docs_path does not exist or is not a directory.");
98122

99123
for entry in WalkDir::new(docs_path)
100124
.into_iter()

0 commit comments

Comments
 (0)