aboutsummaryrefslogtreecommitdiff
path: root/xtask
diff options
context:
space:
mode:
Diffstat (limited to 'xtask')
-rw-r--r--xtask/src/codegen.rs13
-rw-r--r--xtask/src/codegen/gen_assists_docs.rs10
2 files changed, 20 insertions, 3 deletions
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<String> {
74} 74}
75 75
76fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> { 76fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> {
77 do_extract_comment_blocks(text, false)
78}
79
80fn extract_comment_blocks_with_empty_lines(text: &str) -> Vec<Vec<String>> {
81 do_extract_comment_blocks(text, true)
82}
83
84fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lins: bool) -> Vec<Vec<String>> {
77 let mut res = Vec::new(); 85 let mut res = Vec::new();
78 86
79 let prefix = "// "; 87 let prefix = "// ";
@@ -81,6 +89,11 @@ fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> {
81 89
82 let mut block = vec![]; 90 let mut block = vec![];
83 for line in lines { 91 for line in lines {
92 if line == "//" && allow_blocks_with_empty_lins {
93 block.push(String::new());
94 continue;
95 }
96
84 let is_comment = line.starts_with(prefix); 97 let is_comment = line.starts_with(prefix);
85 if is_comment { 98 if is_comment {
86 block.push(line[prefix.len()..].to_string()); 99 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 @@
1use std::{fs, path::Path}; 1use std::{fs, path::Path};
2 2
3use crate::{ 3use crate::{
4 codegen::{self, extract_comment_blocks, Mode}, 4 codegen::{self, extract_comment_blocks_with_empty_lines, Mode},
5 project_root, Result, 5 project_root, Result,
6}; 6};
7 7
@@ -34,7 +34,7 @@ fn collect_assists() -> Result<Vec<Assist>> {
34 34
35 fn collect_file(acc: &mut Vec<Assist>, path: &Path) -> Result<()> { 35 fn collect_file(acc: &mut Vec<Assist>, path: &Path) -> Result<()> {
36 let text = fs::read_to_string(path)?; 36 let text = fs::read_to_string(path)?;
37 let comment_blocks = extract_comment_blocks(&text); 37 let comment_blocks = extract_comment_blocks_with_empty_lines(&text);
38 38
39 for block in comment_blocks { 39 for block in comment_blocks {
40 // FIXME: doesn't support blank lines yet, need to tweak 40 // FIXME: doesn't support blank lines yet, need to tweak
@@ -45,7 +45,11 @@ fn collect_assists() -> Result<Vec<Assist>> {
45 continue; 45 continue;
46 } 46 }
47 let id = first_line["Assist: ".len()..].to_string(); 47 let id = first_line["Assist: ".len()..].to_string();
48 assert!(id.chars().all(|it| it.is_ascii_lowercase() || it == '_')); 48 assert!(
49 id.chars().all(|it| it.is_ascii_lowercase() || it == '_'),
50 "invalid assist id: {:?}",
51 id
52 );
49 53
50 let doc = take_until(lines.by_ref(), "```"); 54 let doc = take_until(lines.by_ref(), "```");
51 let before = take_until(lines.by_ref(), "```"); 55 let before = take_until(lines.by_ref(), "```");