diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-31 11:50:11 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-31 11:50:11 +0100 |
commit | 09df51dab89340bcf4b8ede95c02c32b0c8eb2bc (patch) | |
tree | 0240c629fe96243e1a1c91ccd679947bfb1ecb03 /xtask/src/codegen.rs | |
parent | 5f7225446e75509ae0d971a6f3e2b9d3e37d6f2a (diff) | |
parent | 13a996f3b68c175f6e6ad8d89081e45850dc5583 (diff) |
Merge #4664
4664: Generate feature documentation from code r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'xtask/src/codegen.rs')
-rw-r--r-- | xtask/src/codegen.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index b4907f4b2..f47d54125 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs | |||
@@ -8,14 +8,15 @@ | |||
8 | mod gen_syntax; | 8 | mod gen_syntax; |
9 | mod gen_parser_tests; | 9 | mod gen_parser_tests; |
10 | mod gen_assists_docs; | 10 | mod gen_assists_docs; |
11 | mod gen_feature_docs; | ||
11 | 12 | ||
12 | use std::{mem, path::Path}; | 13 | use std::{mem, path::Path}; |
13 | 14 | ||
14 | use crate::{not_bash::fs2, Result}; | 15 | use crate::{not_bash::fs2, Result}; |
15 | 16 | ||
16 | pub use self::{ | 17 | pub use self::{ |
17 | gen_assists_docs::generate_assists_docs, gen_parser_tests::generate_parser_tests, | 18 | gen_assists_docs::generate_assists_docs, gen_feature_docs::generate_feature_docs, |
18 | gen_syntax::generate_syntax, | 19 | gen_parser_tests::generate_parser_tests, gen_syntax::generate_syntax, |
19 | }; | 20 | }; |
20 | 21 | ||
21 | const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; | 22 | const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; |
@@ -40,7 +41,7 @@ pub enum Mode { | |||
40 | /// With verify = false, | 41 | /// With verify = false, |
41 | fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { | 42 | fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { |
42 | match fs2::read_to_string(path) { | 43 | match fs2::read_to_string(path) { |
43 | Ok(ref old_contents) if normalize(old_contents) == normalize(contents) => { | 44 | Ok(old_contents) if normalize(&old_contents) == normalize(contents) => { |
44 | return Ok(()); | 45 | return Ok(()); |
45 | } | 46 | } |
46 | _ => (), | 47 | _ => (), |
@@ -61,8 +62,24 @@ fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> { | |||
61 | do_extract_comment_blocks(text, false) | 62 | do_extract_comment_blocks(text, false) |
62 | } | 63 | } |
63 | 64 | ||
64 | fn extract_comment_blocks_with_empty_lines(text: &str) -> Vec<Vec<String>> { | 65 | fn extract_comment_blocks_with_empty_lines(tag: &str, text: &str) -> Vec<CommentBlock> { |
65 | do_extract_comment_blocks(text, true) | 66 | assert!(tag.starts_with(char::is_uppercase)); |
67 | let tag = format!("{}:", tag); | ||
68 | let mut res = Vec::new(); | ||
69 | for mut block in do_extract_comment_blocks(text, true) { | ||
70 | let first = block.remove(0); | ||
71 | if first.starts_with(&tag) { | ||
72 | let id = first[tag.len()..].trim().to_string(); | ||
73 | let block = CommentBlock { id, contents: block }; | ||
74 | res.push(block); | ||
75 | } | ||
76 | } | ||
77 | res | ||
78 | } | ||
79 | |||
80 | struct CommentBlock { | ||
81 | id: String, | ||
82 | contents: Vec<String>, | ||
66 | } | 83 | } |
67 | 84 | ||
68 | fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lines: bool) -> Vec<Vec<String>> { | 85 | fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lines: bool) -> Vec<Vec<String>> { |