From dbc3244b9bd82343dce80c086cce502189331108 Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Thu, 27 Feb 2025 21:02:42 +0900 Subject: [PATCH] feat: add Hover Hint. --- crates/schema-store/src/schema/array_schema.rs | 9 +++++++++ crates/schema-store/src/schema/table_schema.rs | 10 ++++++++++ crates/server/src/hover/constraints.rs | 12 ++++++++++++ crates/server/src/hover/value/array.rs | 1 + crates/server/src/hover/value/table.rs | 1 + 5 files changed, 33 insertions(+) diff --git a/crates/schema-store/src/schema/array_schema.rs b/crates/schema-store/src/schema/array_schema.rs index 1002ba7b..24912987 100644 --- a/crates/schema-store/src/schema/array_schema.rs +++ b/crates/schema-store/src/schema/array_schema.rs @@ -25,6 +25,15 @@ pub enum ArrayValuesOrderBy { Descending, } +impl std::fmt::Display for ArrayValuesOrderBy { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Ascending => write!(f, "ascending"), + Self::Descending => write!(f, "descending"), + } + } +} + impl ArraySchema { pub fn new(object: &serde_json::Map) -> Self { Self { diff --git a/crates/schema-store/src/schema/table_schema.rs b/crates/schema-store/src/schema/table_schema.rs index 515ce4ec..3e13a000 100644 --- a/crates/schema-store/src/schema/table_schema.rs +++ b/crates/schema-store/src/schema/table_schema.rs @@ -30,6 +30,16 @@ pub enum TableKeysOrderBy { Schema, } +impl std::fmt::Display for TableKeysOrderBy { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Ascending => write!(f, "ascending"), + Self::Descending => write!(f, "descending"), + Self::Schema => write!(f, "schema"), + } + } +} + impl TableSchema { pub fn new(object: &serde_json::Map) -> Self { let mut properties = AHashMap::new(); diff --git a/crates/server/src/hover/constraints.rs b/crates/server/src/hover/constraints.rs index cfc22a7b..10553e21 100644 --- a/crates/server/src/hover/constraints.rs +++ b/crates/server/src/hover/constraints.rs @@ -1,3 +1,5 @@ +use schema_store::{ArrayValuesOrderBy, TableKeysOrderBy}; + use super::default_value::DefaultValue; #[derive(Debug, Default)] @@ -21,6 +23,7 @@ pub struct DataConstraints { pub min_items: Option, pub max_items: Option, pub unique_items: Option, + pub values_order_by: Option, // Table pub required_keys: Option>, @@ -28,6 +31,7 @@ pub struct DataConstraints { pub max_keys: Option, pub key_patterns: Option>, pub additional_keys: Option, + pub keys_order_by: Option, } impl std::fmt::Display for DataConstraints { @@ -88,6 +92,10 @@ impl std::fmt::Display for DataConstraints { write!(f, "Unique Items: `true`\n\n")?; } + if let Some(values_order_by) = &self.values_order_by { + write!(f, "Values Order By: `{}`\n\n", values_order_by)?; + } + if let Some(required_keys) = &self.required_keys { write!(f, "Required Keys:\n\n")?; for key in required_keys.iter() { @@ -114,6 +122,10 @@ impl std::fmt::Display for DataConstraints { write!(f, "Additional Keys: `true`\n\n")?; } + if let Some(keys_order_by) = &self.keys_order_by { + write!(f, "Keys Order By: `{}`\n\n", keys_order_by)?; + } + Ok(()) } } diff --git a/crates/server/src/hover/value/array.rs b/crates/server/src/hover/value/array.rs index 45772e61..2efe3e78 100644 --- a/crates/server/src/hover/value/array.rs +++ b/crates/server/src/hover/value/array.rs @@ -256,6 +256,7 @@ impl GetHoverContent for ArraySchema { min_items: self.min_items, max_items: self.max_items, unique_items: self.unique_items, + values_order_by: self.values_order_by.clone(), ..Default::default() }), schema_url: schema_url.cloned(), diff --git a/crates/server/src/hover/value/table.rs b/crates/server/src/hover/value/table.rs index 41c975de..f02769f0 100644 --- a/crates/server/src/hover/value/table.rs +++ b/crates/server/src/hover/value/table.rs @@ -456,6 +456,7 @@ impl GetHoverContent for TableSchema { // NOTE: key_patterns are output for keys, not this tables. key_patterns: None, additional_keys: Some(self.additional_properties), + keys_order_by: self.keys_order_by.clone(), ..Default::default() }), schema_url: schema_url.cloned(),