]> git.lizzy.rs Git - rust.git/commitdiff
Add simplistic config validation
authorLukas Wirth <lukastw97@gmail.com>
Mon, 11 Apr 2022 11:10:43 +0000 (13:10 +0200)
committerLukas Wirth <lukastw97@gmail.com>
Mon, 11 Apr 2022 11:10:43 +0000 (13:10 +0200)
crates/rust-analyzer/src/config.rs

index 4d02e896534fcdcfa7647f8ba76e8b98df3ead37..ab9ad4a54312ba504dbcc33603c3817400f76d20 100644 (file)
@@ -571,6 +571,9 @@ pub fn update(&mut self, mut json: serde_json::Value) -> Result<(), ConfigUpdate
                 None => tracing::info!("Invalid snippet {}", name),
             }
         }
+
+        self.validate(&mut errors);
+
         if errors.is_empty() {
             Ok(())
         } else {
@@ -578,6 +581,16 @@ pub fn update(&mut self, mut json: serde_json::Value) -> Result<(), ConfigUpdate
         }
     }
 
+    fn validate(&self, error_sink: &mut Vec<(String, serde_json::Error)>) {
+        use serde::de::Error;
+        if self.data.checkOnSave_command.is_empty() {
+            error_sink.push((
+                "/checkOnSave/command".to_string(),
+                serde_json::Error::custom("expected a non-empty string"),
+            ));
+        }
+    }
+
     pub fn json_schema() -> serde_json::Value {
         ConfigData::json_schema()
     }