Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
docs: Add table of all actions (#36642)
Ben Kunkle3dd362978a2b
diff --git a/crates/docs_preprocessor/src/main.rs b/crates/docs_preprocessor/src/main.rsindex 33158577c4e..c900eb692ae 100644--- a/crates/docs_preprocessor/src/main.rs+++ b/crates/docs_preprocessor/src/main.rs@@ -99,6 +99,7 @@ fn handle_preprocessing() -> Result<()> {let mut errors = HashSet::<PreprocessorError>::new();handle_frontmatter(&mut book, &mut errors);+ template_big_table_of_actions(&mut book);template_and_validate_keybindings(&mut book, &mut errors);template_and_validate_actions(&mut book, &mut errors);@@ -147,6 +148,18 @@ fn handle_frontmatter(book: &mut Book, errors: &mut HashSet<PreprocessorError>)});}+fn template_big_table_of_actions(book: &mut Book) {+ for_each_chapter_mut(book, |chapter| {+ let needle = "{#ACTIONS_TABLE#}";+ if let Some(start) = chapter.content.rfind(needle) {+ chapter.content.replace_range(+ start..start + needle.len(),+ &generate_big_table_of_actions(),+ );+ }+ });+}+fn template_and_validate_keybindings(book: &mut Book, errors: &mut HashSet<PreprocessorError>) {let regex = Regex::new(r"\{#kb (.*?)\}").unwrap();@@ -277,6 +290,7 @@ struct ActionDef {name: &'static str,human_name: String,deprecated_aliases: &'static [&'static str],+ docs: Option<&'static str>,}fn dump_all_gpui_actions() -> Vec<ActionDef> {@@ -285,6 +299,7 @@ fn dump_all_gpui_actions() -> Vec<ActionDef> {name: action.name,human_name: command_palette::humanize_action_name(action.name),deprecated_aliases: action.deprecated_aliases,+ docs: action.documentation,}).collect::<Vec<ActionDef>>();@@ -418,3 +433,54 @@ fn title_regex() -> &'static Regex {static TITLE_REGEX: OnceLock<Regex> = OnceLock::new();TITLE_REGEX.get_or_init(|| Regex::new(r"<title>\s*(.*?)\s*</title>").unwrap())}++fn generate_big_table_of_actions() -> String {+ let actions = &*ALL_ACTIONS;+ let mut output = String::new();++ let mut actions_sorted = actions.iter().collect::<Vec<_>>();+ actions_sorted.sort_by_key(|a| a.name);++ // Start the definition list with custom styling for better spacing+ output.push_str("<dl style=\"line-height: 1.8;\">\n");++ for action in actions_sorted.into_iter() {+ // Add the humanized action name as the term with margin+ output.push_str(+ "<dt style=\"margin-top: 1.5em; margin-bottom: 0.5em; font-weight: bold;\"><code>",+ );+ output.push_str(&action.human_name);+ output.push_str("</code></dt>\n");++ // Add the definition with keymap name and description+ output.push_str("<dd style=\"margin-left: 2em; margin-bottom: 1em;\">\n");++ // Add the description, escaping HTML if needed+ if let Some(description) = action.docs {+ output.push_str(+ &description+ .replace("&", "&")+ .replace("<", "<")+ .replace(">", ">"),+ );+ output.push_str("<br>\n");+ }+ output.push_str("Keymap Name: <code>");+ output.push_str(action.name);+ output.push_str("</code><br>\n");+ if !action.deprecated_aliases.is_empty() {+ output.push_str("Deprecated Aliases:");+ for alias in action.deprecated_aliases.iter() {+ output.push_str("<code>");+ output.push_str(alias);+ output.push_str("</code>, ");+ }+ }+ output.push_str("\n</dd>\n");+ }++ // Close the definition list+ output.push_str("</dl>\n");++ output+}diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.mdindex c7af36f4310..251cad6234f 100644--- a/docs/src/SUMMARY.md+++ b/docs/src/SUMMARY.md@@ -16,6 +16,7 @@- [Configuring Zed](./configuring-zed.md)- [Configuring Languages](./configuring-languages.md)- [Key bindings](./key-bindings.md)+ - [All Actions](./all-actions.md)- [Snippets](./snippets.md)- [Themes](./themes.md)- [Icon Themes](./icon-themes.md)diff --git a/docs/src/all-actions.md b/docs/src/all-actions.mdnew file mode 100644index 00000000000..d20f7cfd63c--- /dev/null+++ b/docs/src/all-actions.md@@ -0,0 +1,3 @@+## All Actions++{#ACTIONS_TABLE#}