From fb2bff513749ffb780fc9b238bd6201349a5ea60 Mon Sep 17 00:00:00 2001 From: druskus20 Date: Thu, 26 Aug 2021 02:26:40 +0200 Subject: [PATCH] Deprecation warning for EWW_CPU_USAGE --- crates/eww/src/config/inbuilt.rs | 8 -------- crates/yuck/src/format_diagnostic.rs | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/eww/src/config/inbuilt.rs b/crates/eww/src/config/inbuilt.rs index 8d489d8..7f0a668 100644 --- a/crates/eww/src/config/inbuilt.rs +++ b/crates/eww/src/config/inbuilt.rs @@ -45,14 +45,6 @@ pub fn get_inbuilt_vars() -> HashMap { // @desc EWW_CPU - Information on the CPU cores: frequency and usage (No MacOS support) "EWW_CPU" => || Ok(DynVal::from(get_cpus())), - // TODO: Change this eventually, maybe implement an error system - // @desc EWW_CPU_USAGE - Outdated, use `EWW_CPU` instead - "EWW_CPU_USAGE" => { - log::warn!("EWW_CPU_BATTERY is deprecated, use EWW_CPU instead"); - || Ok(DynVal::from(get_cpus())) - }, - - // @desc EWW_NET - Bytes up/down on all interfaces "EWW_NET" => || Ok(DynVal::from(net())), } diff --git a/crates/yuck/src/format_diagnostic.rs b/crates/yuck/src/format_diagnostic.rs index d3b0ae4..b6a28c1 100644 --- a/crates/yuck/src/format_diagnostic.rs +++ b/crates/yuck/src/format_diagnostic.rs @@ -184,15 +184,25 @@ impl ToDiagnostic for ValidationError { "Hint: Define it as a global variable" } }; - diag.with_notes(vec![format!( - "Hint: If you meant to use the literal value \"{}\", surround the value in quotes", - name - )]) + + let mut extra_notes = + vec![format!("Hint: If you meant to use the literal value \"{}\", surround the value in quotes", name)]; + + if let Some(deprecation_note) = variable_deprecation_note(name.to_string()) { + extra_notes.push(deprecation_note) + }; + + diag.with_notes(extra_notes) } } } } +fn variable_deprecation_note(var_name: String) -> Option { + (var_name == "EWW_CPU_USAGE") + .then(|| "Note: EWW_CPU_USAGE has recently been removed, and has now been renamed to EWW_CPU".to_string()) +} + fn lalrpop_error_to_diagnostic( error: &lalrpop_util::ParseError, file_id: usize,