Skip to content

Commit

Permalink
Merge pull request #58 from tombi-toml/add_hover_hint
Browse files Browse the repository at this point in the history
feat: add Hover Hint.
  • Loading branch information
yassun7010 authored Feb 27, 2025
2 parents 54a576b + 3cc85d7 commit 2921529
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/schema-store/src/schema/array_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, serde_json::Value>) -> Self {
Self {
Expand Down
10 changes: 10 additions & 0 deletions crates/schema-store/src/schema/table_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, serde_json::Value>) -> Self {
let mut properties = AHashMap::new();
Expand Down
12 changes: 12 additions & 0 deletions crates/server/src/hover/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use schema_store::{ArrayValuesOrderBy, TableKeysOrderBy};

use super::default_value::DefaultValue;

#[derive(Debug, Default)]
Expand All @@ -21,13 +23,15 @@ pub struct DataConstraints {
pub min_items: Option<usize>,
pub max_items: Option<usize>,
pub unique_items: Option<bool>,
pub values_order_by: Option<ArrayValuesOrderBy>,

// Table
pub required_keys: Option<Vec<String>>,
pub min_keys: Option<usize>,
pub max_keys: Option<usize>,
pub key_patterns: Option<Vec<String>>,
pub additional_keys: Option<bool>,
pub keys_order_by: Option<TableKeysOrderBy>,
}

impl std::fmt::Display for DataConstraints {
Expand Down Expand Up @@ -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() {
Expand All @@ -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(())
}
}
1 change: 1 addition & 0 deletions crates/server/src/hover/value/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions crates/server/src/hover/value/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 2921529

Please sign in to comment.