diff --git a/ruby/extractor/src/diagnostics.rs b/ruby/extractor/src/diagnostics.rs index 25b998d958c..ce13d70afdf 100644 --- a/ruby/extractor/src/diagnostics.rs +++ b/ruby/extractor/src/diagnostics.rs @@ -35,7 +35,7 @@ pub struct Visibility { pub telemetry: bool, } -#[derive(Serialize)] +#[derive(Serialize, Clone)] #[serde(rename_all = "camelCase")] pub struct Location { #[serde(skip_serializing_if = "Option::is_none")] @@ -176,7 +176,7 @@ impl DiagnosticLoggers { source: Source { id: id.to_owned(), name: name.to_owned(), - extractor_name: Some(self.extractor), + extractor_name: Some(self.extractor.to_owned()), }, markdown_message: String::new(), plaintext_message: String::new(), @@ -233,23 +233,31 @@ impl DiagnosticMessage { self } pub fn file<'a>(&'a mut self, path: &str) -> &'a mut Self { - self.location.get_or_insert(EMPTY_LOCATION).file = Some(path.to_owned()); + self.location.get_or_insert(EMPTY_LOCATION.to_owned()).file = Some(path.to_owned()); self } pub fn start_line<'a>(&'a mut self, start_line: i32) -> &'a mut Self { - self.location.get_or_insert(EMPTY_LOCATION).start_line = Some(start_line); + self.location + .get_or_insert(EMPTY_LOCATION.to_owned()) + .start_line = Some(start_line); self } pub fn start_column<'a>(&'a mut self, start_column: i32) -> &'a mut Self { - self.location.get_or_insert(EMPTY_LOCATION).start_column = Some(start_column); + self.location + .get_or_insert(EMPTY_LOCATION.to_owned()) + .start_column = Some(start_column); self } pub fn end_line<'a>(&'a mut self, end_line: i32) -> &'a mut Self { - self.location.get_or_insert(EMPTY_LOCATION).end_line = Some(end_line); + self.location + .get_or_insert(EMPTY_LOCATION.to_owned()) + .end_line = Some(end_line); self } pub fn end_column<'a>(&'a mut self, end_column: i32) -> &'a mut Self { - self.location.get_or_insert(EMPTY_LOCATION).end_column = Some(end_column); + self.location + .get_or_insert(EMPTY_LOCATION.to_owned()) + .end_column = Some(end_column); self } } diff --git a/ruby/extractor/src/extractor.rs b/ruby/extractor/src/extractor.rs index 327c405481a..f4a2b249a21 100644 --- a/ruby/extractor/src/extractor.rs +++ b/ruby/extractor/src/extractor.rs @@ -1,3 +1,4 @@ +use crate::diagnostics; use crate::trap; use node_types::{EntryKind, Field, NodeTypeMap, Storage, TypeName}; use std::collections::BTreeMap as Map; @@ -114,6 +115,7 @@ pub fn extract( language: Language, language_prefix: &str, schema: &NodeTypeMap, + diagnostics_writer: &mut diagnostics::LogWriter, trap_writer: &mut trap::Writer, path: &Path, source: &[u8], @@ -138,6 +140,7 @@ pub fn extract( let file_label = populate_file(trap_writer, path); let mut visitor = Visitor::new( source, + diagnostics_writer, trap_writer, // TODO: should we handle path strings that are not valid UTF8 better? &path_str, @@ -204,6 +207,8 @@ struct Visitor<'a> { file_label: trap::Label, /// The source code as a UTF-8 byte array source: &'a [u8], + /// A diagnostics::LogWriter to write diagnostic messages + diagnostics_writer: &'a mut diagnostics::LogWriter, /// A trap::Writer to accumulate trap entries trap_writer: &'a mut trap::Writer, /// A counter for top-level child nodes @@ -226,6 +231,7 @@ struct Visitor<'a> { impl<'a> Visitor<'a> { fn new( source: &'a [u8], + diagnostics_writer: &'a mut diagnostics::LogWriter, trap_writer: &'a mut trap::Writer, path: &'a str, file_label: trap::Label, @@ -236,6 +242,7 @@ impl<'a> Visitor<'a> { path, file_label, source, + diagnostics_writer, trap_writer, toplevel_child_counter: 0, ast_node_info_table_name: format!("{}_ast_node_info", language_prefix), diff --git a/ruby/extractor/src/main.rs b/ruby/extractor/src/main.rs index 3f69a67d043..c172e92ab91 100644 --- a/ruby/extractor/src/main.rs +++ b/ruby/extractor/src/main.rs @@ -1,3 +1,4 @@ +mod diagnostics; mod extractor; mod trap; @@ -59,6 +60,7 @@ fn encoding_from_name(encoding_name: &str) -> Option<&(dyn encoding::Encoding + } fn main() -> std::io::Result<()> { + let diagnostics = diagnostics::DiagnosticLoggers::new("ruby"); tracing_subscriber::fmt() .with_target(false) .without_time() @@ -119,6 +121,7 @@ fn main() -> std::io::Result<()> { lines .par_iter() .try_for_each(|line| { + let mut diagnostics_writer = diagnostics.logger(); let path = PathBuf::from(line).canonicalize()?; let src_archive_file = path_for(&src_archive_dir, &path, ""); let mut source = std::fs::read(&path)?; @@ -131,6 +134,7 @@ fn main() -> std::io::Result<()> { erb, "erb", &erb_schema, + &mut diagnostics_writer, &mut trap_writer, &path, &source, @@ -194,6 +198,7 @@ fn main() -> std::io::Result<()> { language, "ruby", &schema, + &mut diagnostics_writer, &mut trap_writer, &path, &source,