From 7003523b922b07dc76a77b5cfa8ad408e72d651f Mon Sep 17 00:00:00 2001 From: harehare Date: Sun, 24 May 2026 13:57:01 +0900 Subject: [PATCH] feat: include builtin and standard modules by default When -M is specified, automatically include the built-in module and all standard modules (ast, cbor, csv, fuzzy, hcl, json, section, table, test, toml, toon, xml, yaml) alongside user-specified modules. The same set is also shown when no arguments are given, replacing the previous built-in-only default. --- src/lib.rs | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 91466b7..bfb1307 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -204,6 +204,11 @@ pub fn generate_docs( } } +const STANDARD_MODULE_NAMES: &[&str] = &[ + "ast", "cbor", "csv", "fuzzy", "hcl", "json", "section", "table", "test", "toml", "toon", + "xml", "yaml", +]; + /// Build the list of `ModuleDoc` from the given parameters. fn build_module_docs( module_names: &Option>, @@ -216,7 +221,7 @@ fn build_module_docs( let module_docs = if has_files || has_modules { let mut docs = Vec::new(); - if include_builtin { + if include_builtin || has_modules { let mut hir = mq_hir::Hir::default(); hir.add_code(None, ""); docs.push(ModuleDoc { @@ -226,6 +231,42 @@ fn build_module_docs( }); } + if has_modules { + let specified: Vec<&str> = module_names + .as_deref() + .unwrap_or_default() + .iter() + .map(|s| s.as_str()) + .collect(); + + for &std_name in STANDARD_MODULE_NAMES { + if specified.contains(&std_name) { + continue; + } + let mut hir = mq_hir::Hir::default(); + hir.builtin.disabled = true; + hir.add_code(None, &format!("include \"{std_name}\"")); + + let source_id = hir.symbols().find_map(|(_, symbol)| { + if let mq_hir::Symbol { + kind: mq_hir::SymbolKind::Include(module_source_id), + .. + } = &symbol + { + Some(module_source_id) + } else { + None + } + }); + + docs.push(ModuleDoc { + name: std_name.to_string(), + symbols: extract_symbols(&hir, source_id), + selectors: extract_selectors(&hir), + }); + } + } + if let Some(file_contents) = files { for (filename, content) in file_contents { let mut hir = mq_hir::Hir::default(); @@ -268,13 +309,41 @@ fn build_module_docs( docs } else { + let mut docs = Vec::new(); + let mut hir = mq_hir::Hir::default(); hir.add_code(None, ""); - vec![ModuleDoc { - name: "Built-in functions and macros".to_string(), + docs.push(ModuleDoc { + name: "Built-in".to_string(), symbols: extract_symbols(&hir, None), selectors: extract_selectors(&hir), - }] + }); + + for &std_name in STANDARD_MODULE_NAMES { + let mut hir = mq_hir::Hir::default(); + hir.builtin.disabled = true; + hir.add_code(None, &format!("include \"{std_name}\"")); + + let source_id = hir.symbols().find_map(|(_, symbol)| { + if let mq_hir::Symbol { + kind: mq_hir::SymbolKind::Include(module_source_id), + .. + } = &symbol + { + Some(module_source_id) + } else { + None + } + }); + + docs.push(ModuleDoc { + name: std_name.to_string(), + symbols: extract_symbols(&hir, source_id), + selectors: extract_selectors(&hir), + }); + } + + docs }; Ok(module_docs)