mirror of
https://github.com/helix-editor/helix.git
synced 2025-04-03 19:07:44 +03:00
Add static commands to documentation (#11950)
Co-authored-by: Adam Perkowski <adas1per@protonmail.com>
This commit is contained in:
parent
fd3e889927
commit
cd1f6e8239
4 changed files with 379 additions and 3 deletions
|
@ -1,12 +1,18 @@
|
|||
use crate::helpers;
|
||||
use crate::path;
|
||||
use crate::DynError;
|
||||
|
||||
use helix_term::commands::MappableCommand;
|
||||
use helix_term::commands::TYPABLE_COMMAND_LIST;
|
||||
use helix_term::health::TsFeature;
|
||||
use helix_term::ui::EditorView;
|
||||
use helix_view::document::Mode;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
|
||||
pub const TYPABLE_COMMANDS_MD_OUTPUT: &str = "typable-cmd.md";
|
||||
pub const STATIC_COMMANDS_MD_OUTPUT: &str = "static-cmd.md";
|
||||
pub const LANG_SUPPORT_MD_OUTPUT: &str = "lang-support.md";
|
||||
|
||||
fn md_table_heading(cols: &[String]) -> String {
|
||||
|
@ -48,6 +54,68 @@ pub fn typable_commands() -> Result<String, DynError> {
|
|||
Ok(md)
|
||||
}
|
||||
|
||||
pub fn static_commands() -> Result<String, DynError> {
|
||||
let mut md = String::new();
|
||||
let keymap = EditorView::default().keymaps.map();
|
||||
let keymaps = [
|
||||
("normal", keymap[&Mode::Normal].reverse_map()),
|
||||
("select", keymap[&Mode::Select].reverse_map()),
|
||||
("insert", keymap[&Mode::Insert].reverse_map()),
|
||||
];
|
||||
|
||||
md.push_str(&md_table_heading(&[
|
||||
"Name".to_owned(),
|
||||
"Description".to_owned(),
|
||||
"Default keybinds".to_owned(),
|
||||
]));
|
||||
|
||||
for cmd in MappableCommand::STATIC_COMMAND_LIST {
|
||||
let keymap_strings: Vec<_> = keymaps
|
||||
.iter()
|
||||
.map(|(mode, keymap)| {
|
||||
let bindings = keymap
|
||||
.get(cmd.name())
|
||||
.map(|bindings| {
|
||||
let mut bind_strings: Vec<_> = bindings
|
||||
.iter()
|
||||
.map(|bind| {
|
||||
let keys = &bind
|
||||
.iter()
|
||||
.map(|key| key.key_sequence_format())
|
||||
.collect::<String>()
|
||||
// escape | so it doesn't get rendered as a column separator
|
||||
.replace('|', "\\|");
|
||||
format!("`` {} ``", keys)
|
||||
})
|
||||
.collect();
|
||||
// sort for stable output. sorting by length puts simple
|
||||
// keybindings first and groups similar keys together
|
||||
bind_strings.sort_by_key(|s| (s.len(), s.to_owned()));
|
||||
bind_strings.join(", ")
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
(mode, bindings)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let keymap_string = keymap_strings
|
||||
.iter()
|
||||
.filter(|(_, bindings)| !bindings.is_empty())
|
||||
.map(|(mode, bindings)| format!("{}: {}", mode, bindings))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
|
||||
md.push_str(&md_table_row(&[
|
||||
md_mono(cmd.name()),
|
||||
cmd.doc().to_owned(),
|
||||
keymap_string,
|
||||
]));
|
||||
}
|
||||
|
||||
Ok(md)
|
||||
}
|
||||
|
||||
pub fn lang_features() -> Result<String, DynError> {
|
||||
let mut md = String::new();
|
||||
let ts_features = TsFeature::all();
|
||||
|
|
|
@ -9,14 +9,17 @@ use std::{env, error::Error};
|
|||
type DynError = Box<dyn Error>;
|
||||
|
||||
pub mod tasks {
|
||||
use crate::docgen::{lang_features, typable_commands, write};
|
||||
use crate::docgen::{LANG_SUPPORT_MD_OUTPUT, TYPABLE_COMMANDS_MD_OUTPUT};
|
||||
use crate::docgen::{lang_features, static_commands, typable_commands, write};
|
||||
use crate::docgen::{
|
||||
LANG_SUPPORT_MD_OUTPUT, STATIC_COMMANDS_MD_OUTPUT, TYPABLE_COMMANDS_MD_OUTPUT,
|
||||
};
|
||||
use crate::querycheck::query_check;
|
||||
use crate::theme_check::theme_check;
|
||||
use crate::DynError;
|
||||
|
||||
pub fn docgen() -> Result<(), DynError> {
|
||||
write(TYPABLE_COMMANDS_MD_OUTPUT, &typable_commands()?);
|
||||
write(STATIC_COMMANDS_MD_OUTPUT, &static_commands()?);
|
||||
write(LANG_SUPPORT_MD_OUTPUT, &lang_features()?);
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue