22
33//! This module is responsible for writing the output of semantic analysis.
44//!
5- //! The output can be in different formats, such as JSON compilation databases
6- //! or semantic analysis results in JSON format. The module provides functionality
7- //! to write these outputs to files, handle duplicates, and format the output
8- //! as needed.
5+ //! The output is written as JSON compilation databases.
6+ //! The module provides functionality to write these outputs to files,
7+ //! handle duplicates, and format the output as needed.
98//!
10- //! The `OutputWriter` enum represents the main entry point for writing output.
9+ //! The `OutputWriter` struct represents the main entry point for writing output.
1110//! The input to the `OutputWriter` is a stream of `semantic::Command` instances.
1211
1312mod formats;
@@ -18,7 +17,7 @@ use crate::{args, config, semantic};
1817use thiserror:: Error ;
1918use writers:: {
2019 AppendClangOutputWriter , AtomicClangOutputWriter , ClangOutputWriter ,
21- ConverterClangOutputWriter , IteratorWriter , SemanticOutputWriter , UniqueOutputWriter ,
20+ ConverterClangOutputWriter , IteratorWriter , UniqueOutputWriter ,
2221} ;
2322
2423// Re-export types for convenience.
@@ -29,18 +28,13 @@ type ClangWriterStack = ConverterClangOutputWriter<
2928 AppendClangOutputWriter < AtomicClangOutputWriter < UniqueOutputWriter < ClangOutputWriter > > > ,
3029> ;
3130
32- /// Represents the output writer, which can handle different types of outputs .
31+ /// Represents the output writer for JSON compilation databases .
3332///
34- /// This enum provides two variants:
35- /// - `Clang`: Writes output as a JSON compilation database.
36- /// - `Semantic`: Writes output as a JSON semantic analysis result.
37- ///
38- /// The variants are selected at runtime based on the configuration provided.
39- pub enum OutputWriter {
40- #[ allow( private_interfaces) ]
41- Clang ( ClangWriterStack ) ,
33+ /// The writer handles writing semantic analysis results as JSON compilation databases,
34+ /// with support for deduplication, atomic writes, and appending to existing files.
35+ pub struct OutputWriter {
4236 #[ allow( private_interfaces) ]
43- Semantic ( SemanticOutputWriter ) ,
37+ writer : ClangWriterStack ,
4438}
4539
4640impl TryFrom < ( & args:: BuildSemantic , & config:: Output ) > for OutputWriter {
@@ -64,12 +58,9 @@ impl TryFrom<(&args::BuildSemantic, &config::Output)> for OutputWriter {
6458 let formatted_writer =
6559 ConverterClangOutputWriter :: new ( append_writer, & format. entry ) ;
6660
67- Ok ( Self :: Clang ( formatted_writer) )
68- }
69- config:: Output :: Semantic { .. } => {
70- let path = std:: path:: Path :: new ( & args. path ) ;
71- let result = SemanticOutputWriter :: try_from ( path) ?;
72- Ok ( Self :: Semantic ( result) )
61+ Ok ( Self {
62+ writer : formatted_writer,
63+ } )
7364 }
7465 }
7566 }
@@ -87,10 +78,7 @@ impl OutputWriter {
8778 self ,
8879 semantics : impl Iterator < Item = semantic:: Command > ,
8980 ) -> Result < ( ) , WriterError > {
90- match self {
91- Self :: Clang ( writer) => writer. write ( semantics) ,
92- Self :: Semantic ( writer) => writer. write ( semantics) ,
93- }
81+ self . writer . write ( semantics)
9482 }
9583}
9684
0 commit comments