diff options
Diffstat (limited to 'xtask/src/codegen/gen_assists_docs.rs')
-rw-r--r-- | xtask/src/codegen/gen_assists_docs.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index c469b388d..158680993 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs | |||
@@ -2,22 +2,25 @@ | |||
2 | 2 | ||
3 | use std::{fmt, path::Path}; | 3 | use std::{fmt, path::Path}; |
4 | 4 | ||
5 | use xshell::write_file; | ||
6 | |||
5 | use crate::{ | 7 | use crate::{ |
6 | codegen::{self, extract_comment_blocks_with_empty_lines, reformat, Location, Mode, PREAMBLE}, | 8 | codegen::{self, extract_comment_blocks_with_empty_lines, reformat, Location, PREAMBLE}, |
7 | project_root, rust_files_in, Result, | 9 | project_root, rust_files_in, Result, |
8 | }; | 10 | }; |
9 | 11 | ||
10 | pub(crate) fn generate_assists_tests(mode: Mode) -> Result<()> { | 12 | pub(crate) fn generate_assists_tests() -> Result<()> { |
11 | let assists = Assist::collect()?; | 13 | let assists = Assist::collect()?; |
12 | generate_tests(&assists, mode) | 14 | generate_tests(&assists) |
13 | } | 15 | } |
14 | 16 | ||
15 | pub(crate) fn generate_assists_docs(mode: Mode) -> Result<()> { | 17 | pub(crate) fn generate_assists_docs() -> Result<()> { |
16 | let assists = Assist::collect()?; | 18 | let assists = Assist::collect()?; |
17 | let contents = assists.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n"); | 19 | let contents = assists.into_iter().map(|it| it.to_string()).collect::<Vec<_>>().join("\n\n"); |
18 | let contents = format!("//{}\n{}\n", PREAMBLE, contents.trim()); | 20 | let contents = format!("//{}\n{}\n", PREAMBLE, contents.trim()); |
19 | let dst = project_root().join("docs/user/generated_assists.adoc"); | 21 | let dst = project_root().join("docs/user/generated_assists.adoc"); |
20 | codegen::update(&dst, &contents, mode) | 22 | write_file(dst, &contents)?; |
23 | Ok(()) | ||
21 | } | 24 | } |
22 | 25 | ||
23 | #[derive(Debug)] | 26 | #[derive(Debug)] |
@@ -111,7 +114,7 @@ impl fmt::Display for Assist { | |||
111 | } | 114 | } |
112 | } | 115 | } |
113 | 116 | ||
114 | fn generate_tests(assists: &[Assist], mode: Mode) -> Result<()> { | 117 | fn generate_tests(assists: &[Assist]) -> Result<()> { |
115 | let mut buf = String::from("use super::check_doc_test;\n"); | 118 | let mut buf = String::from("use super::check_doc_test;\n"); |
116 | 119 | ||
117 | for assist in assists.iter() { | 120 | for assist in assists.iter() { |
@@ -135,7 +138,10 @@ r#####" | |||
135 | buf.push_str(&test) | 138 | buf.push_str(&test) |
136 | } | 139 | } |
137 | let buf = reformat(&buf)?; | 140 | let buf = reformat(&buf)?; |
138 | codegen::update(&project_root().join("crates/ide_assists/src/tests/generated.rs"), &buf, mode) | 141 | codegen::ensure_file_contents( |
142 | &project_root().join("crates/ide_assists/src/tests/generated.rs"), | ||
143 | &buf, | ||
144 | ) | ||
139 | } | 145 | } |
140 | 146 | ||
141 | fn hide_hash_comments(text: &str) -> String { | 147 | fn hide_hash_comments(text: &str) -> String { |