@@ -75,20 +75,15 @@ impl LspServerInfo {
7575 }
7676}
7777
78- #[ allow( unused_variables, clippy :: too_many_arguments ) ]
78+ #[ allow( unused_variables) ]
7979pub fn generate_docs (
8080 path : & Utf8PathBuf ,
8181 output : Option < & Utf8PathBuf > ,
82- json : bool ,
83- serve_docs : bool ,
84- port : u16 ,
85- static_site : bool ,
86- markdown_pages : bool ,
8782 builtins : bool ,
88- base_url : & str ,
83+ action : Option < & crate :: DocAction > ,
8984) {
9085 // First, check if there's a running LSP with docs server
91- if serve_docs {
86+ if matches ! ( action , Some ( crate :: DocAction :: Serve { .. } ) ) {
9287 let canonical_path = path. canonicalize_utf8 ( ) . ok ( ) ;
9388 let start_dir = canonical_path. as_ref ( ) . and_then ( |p| {
9489 if p. is_file ( ) {
@@ -192,107 +187,96 @@ pub fn generate_docs(
192187 // This enriches rich_signature fields and produces JSON for embedding.
193188 let scip_json = generate_scip_json_for_doc ( & mut db, path, & mut index, builtins) ;
194189
195- if static_site {
196- let output_dir = output
197- . map ( |p| p. as_std_path ( ) . to_path_buf ( ) )
198- . unwrap_or_else ( || std:: path:: PathBuf :: from ( "docs" ) ) ;
199-
200- // Auto-detect git source link base for GitHub links
201- let source_link_base = detect_source_link_base ( path. as_std_path ( ) ) ;
202-
203- if let Err ( e) = fe_web:: static_site:: StaticSiteGenerator :: generate_full (
204- & index,
205- & output_dir,
206- scip_json. as_deref ( ) ,
207- source_link_base. as_deref ( ) ,
208- ) {
209- eprintln ! ( "Error generating static docs: {e}" ) ;
210- std:: process:: exit ( 1 ) ;
211- }
212-
213- // When --json is also set, write docs.json alongside index.html
214- if json {
215- let merged = build_merged_json ( & index, scip_json. as_deref ( ) ) ;
216- let json_path = output_dir. join ( "docs.json" ) ;
217- std:: fs:: write ( & json_path, & merged) . unwrap_or_else ( |e| {
218- eprintln ! ( "Error writing docs.json: {e}" ) ;
219- std:: process:: exit ( 1 ) ;
220- } ) ;
221- }
222-
223- let suffix = match ( scip_json. is_some ( ) , json) {
224- ( true , true ) => " (with SCIP + docs.json)" ,
225- ( true , false ) => " (with SCIP)" ,
226- ( false , true ) => " (with docs.json)" ,
227- ( false , false ) => "" ,
228- } ;
229- println ! ( "Static docs written to {}{suffix}" , output_dir. display( ) ) ;
230- return ;
231- }
232-
233- if markdown_pages {
234- let output_dir = output
235- . map ( |p| p. as_std_path ( ) . to_path_buf ( ) )
236- . unwrap_or_else ( || std:: path:: PathBuf :: from ( "docs" ) ) ;
237- if let Err ( e) = fe_web:: starlight:: generate ( & index, & output_dir, base_url) {
238- eprintln ! ( "Error generating markdown pages: {e}" ) ;
239- std:: process:: exit ( 1 ) ;
240- }
241- println ! ( "Markdown pages written to {}" , output_dir. display( ) ) ;
242- return ;
243- }
244-
245- #[ cfg( feature = "doc-server" ) ]
246- if serve_docs {
247- use crate :: doc_serve:: { DocServeConfig , serve_docs as serve} ;
248-
249- let config = DocServeConfig {
250- port,
251- host : "127.0.0.1" . to_string ( ) ,
252- } ;
253-
254- println ! ( "Starting documentation server..." ) ;
255- println ! ( "Open http://127.0.0.1:{port} in your browser" ) ;
256- println ! ( "Press Ctrl+C to stop" ) ;
190+ match action {
191+ Some ( crate :: DocAction :: Static ) => {
192+ let output_dir = output
193+ . map ( |p| p. as_std_path ( ) . to_path_buf ( ) )
194+ . unwrap_or_else ( || std:: path:: PathBuf :: from ( "docs" ) ) ;
257195
258- let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
259- rt. block_on ( async {
260196 let source_link_base = detect_source_link_base ( path. as_std_path ( ) ) ;
261- if let Err ( e) = serve ( index, config, scip_json, source_link_base) . await {
262- eprintln ! ( "Server error: {e}" ) ;
197+
198+ if let Err ( e) = fe_web:: static_site:: StaticSiteGenerator :: generate_full (
199+ & index,
200+ & output_dir,
201+ scip_json. as_deref ( ) ,
202+ source_link_base. as_deref ( ) ,
203+ ) {
204+ eprintln ! ( "Error generating static docs: {e}" ) ;
263205 std:: process:: exit ( 1 ) ;
264206 }
265- } ) ;
266- return ;
267- }
268207
269- #[ cfg( not( feature = "doc-server" ) ) ]
270- if serve_docs {
271- eprintln ! ( "Error: doc-server feature not enabled. Rebuild with --features doc-server" ) ;
272- std:: process:: exit ( 1 ) ;
273- }
274-
275- if json {
276- // Produce merged docs.json (DocIndex + SCIP) for web component consumption
277- let merged = build_merged_json ( & index, scip_json. as_deref ( ) ) ;
278- if let Some ( output_path) = output {
279- let output_dir = output_path. as_std_path ( ) ;
280- std:: fs:: create_dir_all ( output_dir) . unwrap_or_else ( |e| {
281- eprintln ! ( "Error creating output directory {output_path}: {e}" ) ;
208+ let suffix = if scip_json. is_some ( ) {
209+ " (with SCIP)"
210+ } else {
211+ ""
212+ } ;
213+ println ! ( "Static docs written to {}{suffix}" , output_dir. display( ) ) ;
214+ }
215+ Some ( crate :: DocAction :: Json ) => {
216+ let merged = build_merged_json ( & index, scip_json. as_deref ( ) ) ;
217+ if let Some ( output_path) = output {
218+ let output_dir = output_path. as_std_path ( ) ;
219+ std:: fs:: create_dir_all ( output_dir) . unwrap_or_else ( |e| {
220+ eprintln ! ( "Error creating output directory {output_path}: {e}" ) ;
221+ std:: process:: exit ( 1 ) ;
222+ } ) ;
223+ let json_path = output_dir. join ( "docs.json" ) ;
224+ std:: fs:: write ( & json_path, & merged) . unwrap_or_else ( |e| {
225+ eprintln ! ( "Error writing docs.json: {e}" ) ;
226+ std:: process:: exit ( 1 ) ;
227+ } ) ;
228+ println ! ( "Wrote docs.json to {output_path}" ) ;
229+ } else {
230+ println ! ( "{merged}" ) ;
231+ }
232+ }
233+ Some ( crate :: DocAction :: Pages { base_url } ) => {
234+ let output_dir = output
235+ . map ( |p| p. as_std_path ( ) . to_path_buf ( ) )
236+ . unwrap_or_else ( || std:: path:: PathBuf :: from ( "docs" ) ) ;
237+ if let Err ( e) = fe_web:: starlight:: generate ( & index, & output_dir, base_url) {
238+ eprintln ! ( "Error generating markdown pages: {e}" ) ;
282239 std:: process:: exit ( 1 ) ;
283- } ) ;
284- let json_path = output_dir. join ( "docs.json" ) ;
285- std:: fs:: write ( & json_path, & merged) . unwrap_or_else ( |e| {
286- eprintln ! ( "Error writing docs.json: {e}" ) ;
240+ }
241+ println ! ( "Markdown pages written to {}" , output_dir. display( ) ) ;
242+ }
243+ Some ( crate :: DocAction :: Serve { port } ) => {
244+ #[ cfg( feature = "doc-server" ) ]
245+ {
246+ use crate :: doc_serve:: { DocServeConfig , serve_docs as serve} ;
247+
248+ let config = DocServeConfig {
249+ port : * port,
250+ host : "127.0.0.1" . to_string ( ) ,
251+ } ;
252+
253+ println ! ( "Starting documentation server..." ) ;
254+ println ! ( "Open http://127.0.0.1:{port} in your browser" ) ;
255+ println ! ( "Press Ctrl+C to stop" ) ;
256+
257+ let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
258+ rt. block_on ( async {
259+ let source_link_base = detect_source_link_base ( path. as_std_path ( ) ) ;
260+ if let Err ( e) = serve ( index, config, scip_json, source_link_base) . await {
261+ eprintln ! ( "Server error: {e}" ) ;
262+ std:: process:: exit ( 1 ) ;
263+ }
264+ } ) ;
265+ }
266+ #[ cfg( not( feature = "doc-server" ) ) ]
267+ {
268+ eprintln ! (
269+ "Error: doc-server feature not enabled. Rebuild with --features doc-server"
270+ ) ;
287271 std:: process:: exit ( 1 ) ;
288- } ) ;
289- println ! ( "Wrote docs.json to {output_path}" ) ;
290- } else {
291- println ! ( "{merged}" ) ;
272+ }
273+ }
274+ Some ( crate :: DocAction :: Bundle ) => {
275+ unreachable ! ( "Bundle is handled before generate_docs is called" )
276+ }
277+ None => {
278+ print_doc_summary ( & index) ;
292279 }
293- } else {
294- // Print summary
295- print_doc_summary ( & index) ;
296280 }
297281}
298282
0 commit comments