diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-25 21:38:46 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-25 21:38:46 +0100 |
commit | 54d1a582812e01691ecb2f8ed11e8df9dda1530c (patch) | |
tree | d57842c6462f4921976d6d9642ce7751681cf0bd /xtask | |
parent | e6cb06d2850b9b9c38c0c13d6948ab39adcd652e (diff) | |
parent | d385438bcc8d302fbcb91114e19ac0cc30528822 (diff) |
Merge #2071
2071: generate more assists docs r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/src/codegen.rs | 13 | ||||
-rw-r--r-- | xtask/src/codegen/gen_assists_docs.rs | 10 |
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 | ||
76 | fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> { | 76 | fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> { |
77 | do_extract_comment_blocks(text, false) | ||
78 | } | ||
79 | |||
80 | fn extract_comment_blocks_with_empty_lines(text: &str) -> Vec<Vec<String>> { | ||
81 | do_extract_comment_blocks(text, true) | ||
82 | } | ||
83 | |||
84 | fn 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 @@ | |||
1 | use std::{fs, path::Path}; | 1 | use std::{fs, path::Path}; |
2 | 2 | ||
3 | use crate::{ | 3 | use 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(), "```"); |