From d385438bcc8d302fbcb91114e19ac0cc30528822 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Oct 2019 23:38:15 +0300 Subject: generate more assists docs --- xtask/src/codegen.rs | 13 +++++++++++++ xtask/src/codegen/gen_assists_docs.rs | 10 +++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'xtask') diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 44729cd57..4ec8ab75a 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs @@ -74,6 +74,14 @@ fn reformat(text: impl std::fmt::Display) -> Result { } fn extract_comment_blocks(text: &str) -> Vec> { + do_extract_comment_blocks(text, false) +} + +fn extract_comment_blocks_with_empty_lines(text: &str) -> Vec> { + do_extract_comment_blocks(text, true) +} + +fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lins: bool) -> Vec> { let mut res = Vec::new(); let prefix = "// "; @@ -81,6 +89,11 @@ fn extract_comment_blocks(text: &str) -> Vec> { let mut block = vec![]; for line in lines { + if line == "//" && allow_blocks_with_empty_lins { + block.push(String::new()); + continue; + } + let is_comment = line.starts_with(prefix); if is_comment { block.push(line[prefix.len()..].to_string()); diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index 654ae09d6..e313820d1 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs @@ -1,7 +1,7 @@ use std::{fs, path::Path}; use crate::{ - codegen::{self, extract_comment_blocks, Mode}, + codegen::{self, extract_comment_blocks_with_empty_lines, Mode}, project_root, Result, }; @@ -34,7 +34,7 @@ fn collect_assists() -> Result> { fn collect_file(acc: &mut Vec, path: &Path) -> Result<()> { let text = fs::read_to_string(path)?; - let comment_blocks = extract_comment_blocks(&text); + let comment_blocks = extract_comment_blocks_with_empty_lines(&text); for block in comment_blocks { // FIXME: doesn't support blank lines yet, need to tweak @@ -45,7 +45,11 @@ fn collect_assists() -> Result> { continue; } let id = first_line["Assist: ".len()..].to_string(); - assert!(id.chars().all(|it| it.is_ascii_lowercase() || it == '_')); + assert!( + id.chars().all(|it| it.is_ascii_lowercase() || it == '_'), + "invalid assist id: {:?}", + id + ); let doc = take_until(lines.by_ref(), "```"); let before = take_until(lines.by_ref(), "```"); -- cgit v1.2.3