Use serde's default annotation for Document

This commit is contained in:
Joscha 2023-04-27 20:11:16 +02:00
parent d29441bf02
commit 458025b8bf
7 changed files with 194 additions and 67 deletions

View file

@ -5,6 +5,15 @@ use std::path::PathBuf;
use cove_input::KeyBinding;
pub use cove_macro::Document;
use serde::Serialize;
pub(crate) fn toml_value_as_markdown<T: Serialize>(value: &T) -> String {
let mut result = String::new();
value
.serialize(toml::ser::ValueSerializer::new(&mut result))
.expect("not a valid toml value");
format!("`{result}`")
}
#[derive(Clone, Default)]
pub struct ValueInfo {
@ -118,7 +127,7 @@ impl Doc {
entries
}
pub fn format_as_markdown(&self) -> String {
pub fn as_markdown(&self) -> String {
// Print entries in alphabetical order to make generated documentation
// format more stable.
let mut entries = self.entries();

View file

@ -29,7 +29,6 @@ impl Document for RoomsSortOrder {
pub struct EuphRoom {
/// Whether to automatically join this room on startup.
#[serde(default)]
#[document(default = "`false`")]
pub autojoin: bool,
/// If set, cove will set this username upon joining if there is no username
@ -40,7 +39,6 @@ pub struct EuphRoom {
/// username even if there is already a different username associated with
/// the current session.
#[serde(default)]
#[document(default = "`false`")]
pub force_username: bool,
/// If set, cove will try once to use this password to authenticate, should

View file

@ -256,8 +256,11 @@ impl Default for EditorOp {
#[derive(Debug, Default, Deserialize, Document)]
pub struct Editor {
#[serde(default)]
#[document(no_default)]
pub cursor: EditorCursor,
#[serde(default)]
#[document(no_default)]
pub action: EditorOp,
}
@ -346,21 +349,33 @@ impl Default for TreeOp {
#[derive(Debug, Default, Deserialize, Document)]
pub struct Tree {
#[serde(default)]
#[document(no_default)]
pub cursor: TreeCursor,
#[serde(default)]
#[document(no_default)]
pub action: TreeOp,
}
#[derive(Debug, Default, Deserialize, Document)]
pub struct Keys {
#[serde(default)]
#[document(no_default)]
pub general: General,
#[serde(default)]
#[document(no_default)]
pub scroll: Scroll,
#[serde(default)]
#[document(no_default)]
pub cursor: Cursor,
#[serde(default)]
#[document(no_default)]
pub editor: Editor,
#[serde(default)]
#[document(no_default)]
pub tree: Tree,
}

View file

@ -80,9 +80,12 @@ pub struct Config {
#[document(default = "`alphabet`")]
pub rooms_sort_order: RoomsSortOrder,
#[serde(default)]
#[document(no_default)]
pub euph: Euph,
#[serde(default)]
#[document(no_default)]
pub keys: Keys,
}