33import json
44import logging
55from pathlib import Path
6- from typing import Any , TypedDict
6+ from typing import Any , TypedDict , cast
77
88from lark import UnexpectedInput
99from tree_sitter import Node as TreeSitterNode
@@ -56,6 +56,8 @@ class AnalyseWarning:
5656
5757
5858class SourceAnalyse :
59+ """Analyse source files from a single project."""
60+
5961 def __init__ (
6062 self ,
6163 analyse_config : SourceAnalyseConfig ,
@@ -427,6 +429,11 @@ def extract_marked_content(self) -> None:
427429 logger .info (f"Oneline needs extracted: { len (self .oneline_needs )} " )
428430 if self .analyse_config .get_rst :
429431 logger .info (f"Marked rst extracted: { len (self .marked_rst )} " )
432+ cnt_resolved = 0
433+ for rst in self .marked_rst :
434+ if rst .need :
435+ cnt_resolved += 1
436+ logger .info (f"Marked rst valid to need: { cnt_resolved } " )
430437
431438 def merge_marked_content (self ) -> None :
432439 self .all_marked_content .extend (self .need_id_refs )
@@ -438,6 +445,10 @@ def merge_marked_content(self) -> None:
438445 )
439446
440447 def dump_marked_content (self , outdir : Path ) -> None :
448+ """Dump marked content to the given output directory.
449+
450+ This function is mainly for API users who want to dump marked content separately.
451+ """
441452 output_path = outdir / "marked_content.json"
442453 if not output_path .parent .exists ():
443454 output_path .parent .mkdir (parents = True )
@@ -448,6 +459,25 @@ def dump_marked_content(self, outdir: Path) -> None:
448459 json .dump (to_dump , f )
449460 logger .info (f"Marked content dumped to { output_path } " )
450461
462+ def dump_warnings (self , outdir : Path ) -> None :
463+ """Dump warnings to the given output directory.
464+
465+ This function is mainly for API users who want to dump warnings separately.
466+ """
467+ output_path = outdir / "analyse_warnings.json"
468+ if not output_path .parent .exists ():
469+ output_path .parent .mkdir (parents = True )
470+ current_warnings : list [AnalyseWarningType ] = [
471+ cast (AnalyseWarningType , _warning .__dict__ )
472+ for _warning in list (self .rst_warnings ) + list (self .oneline_warnings )
473+ ]
474+ with output_path .open ("w" ) as f :
475+ json .dump (
476+ current_warnings ,
477+ f ,
478+ )
479+ logger .info (f"Warnings dumped to { output_path } " )
480+
451481 def run (self ) -> None :
452482 self .create_src_objects ()
453483 self .extract_marked_content ()
0 commit comments