mirror of
https://github.com/github/codeql.git
synced 2026-02-19 16:33:40 +01:00
Add TrapWriter::comment
This commit is contained in:
@@ -6,13 +6,20 @@ use std::path::Path;
|
||||
use tracing::{error, info, span, Level};
|
||||
use tree_sitter::{Language, Node, Parser, Tree};
|
||||
|
||||
pub struct TrapWriter {
|
||||
struct TrapWriter {
|
||||
/// The accumulated trap entries
|
||||
trap_output: Vec<TrapEntry>,
|
||||
/// A counter for generating fresh labels
|
||||
counter: i32,
|
||||
}
|
||||
|
||||
fn new_trap_writer() -> TrapWriter {
|
||||
TrapWriter {
|
||||
counter: -1,
|
||||
trap_output: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
impl TrapWriter {
|
||||
/// Gets a label that will hold the unique ID of the passed string at import time.
|
||||
/// This can be used for incrementally importable TRAP files -- use globally unique
|
||||
@@ -97,6 +104,10 @@ impl TrapWriter {
|
||||
);
|
||||
loc_label
|
||||
}
|
||||
|
||||
fn comment(&mut self, text: String) {
|
||||
self.trap_output.push(TrapEntry::Comment(text));
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Extractor {
|
||||
@@ -129,13 +140,8 @@ impl Extractor {
|
||||
.parser
|
||||
.parse(&source, None)
|
||||
.expect("Failed to parse file");
|
||||
let mut trap_writer = TrapWriter {
|
||||
counter: -1,
|
||||
trap_output: vec![TrapEntry::Comment(format!(
|
||||
"Auto-generated TRAP file for {}",
|
||||
path.display()
|
||||
))],
|
||||
};
|
||||
let mut trap_writer = new_trap_writer();
|
||||
trap_writer.comment(format!("Auto-generated TRAP file for {}", path.display()));
|
||||
let file_label = &trap_writer.populate_file(path);
|
||||
let mut visitor = Visitor {
|
||||
source: &source,
|
||||
|
||||
Reference in New Issue
Block a user