Merge pull request #16451 from hvitved/treesitter/codeql-verbosity

Tree-sitter: Respect verbosity defined in `CODEQL_VERBOSITY`
This commit is contained in:
Tom Hvitved
2024-05-24 11:24:01 +02:00
committed by GitHub
13 changed files with 738 additions and 3075 deletions

View File

@@ -9,6 +9,7 @@ flate2 = "1.0"
globset = "0.4"
tree-sitter = ">= 0.22.6"
tracing = "0.1"
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
rayon = "1.5.0"
regex = "1.7.1"
encoding = "0.2"

View File

@@ -2,6 +2,6 @@
# extractor. It is set to the lowest version of Rust we want to support.
[toolchain]
channel = "1.70"
channel = "1.74"
profile = "minimal"
components = [ "clippy", "rustfmt" ]

View File

@@ -4,12 +4,44 @@ use crate::node_types::{self, EntryKind, Field, NodeTypeMap, Storage, TypeName};
use crate::trap;
use std::collections::BTreeMap as Map;
use std::collections::BTreeSet as Set;
use std::env;
use std::path::Path;
use tree_sitter::{Language, Node, Parser, Range, Tree};
pub mod simple;
/// Sets the tracing level based on the environment variables
/// `RUST_LOG` and `CODEQL_VERBOSITY` (prioritized in that order),
/// falling back to `warn` if neither is set.
pub fn set_tracing_level(language: &str) {
tracing_subscriber::fmt()
.with_target(false)
.without_time()
.with_level(true)
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(
|_| -> tracing_subscriber::EnvFilter {
let verbosity = env::var("CODEQL_VERBOSITY")
.map(|v| match v.to_lowercase().as_str() {
"off" | "errors" => "error",
"warnings" => "warn",
"info" | "progress" => "info",
"debug" | "progress+" => "debug",
"trace" | "progress++" | "progress+++" => "trace",
_ => "warn",
})
.unwrap_or_else(|_| "warn");
tracing_subscriber::EnvFilter::new(format!(
"{}_extractor={}",
language, verbosity
))
},
),
)
.init();
}
pub fn populate_file(writer: &mut trap::Writer, absolute_path: &Path) -> trap::Label {
let (file_label, fresh) = writer.global_id(&trap::full_id_for_file(
&file_paths::normalize_path(absolute_path),