|
1 | 1 | //! Generates `assists.md` documentation. |
2 | 2 |
|
| 3 | +#[cfg(not(feature = "in-rust-tree"))] |
3 | 4 | use std::{fmt, fs, path::Path}; |
4 | 5 |
|
| 6 | +#[cfg(not(feature = "in-rust-tree"))] |
5 | 7 | use test_utils::project_root; |
6 | 8 |
|
| 9 | +#[cfg(not(feature = "in-rust-tree"))] |
7 | 10 | #[test] |
8 | 11 | fn sourcegen_assists_docs() { |
9 | 12 | let assists = Assist::collect(); |
@@ -59,20 +62,24 @@ r#####" |
59 | 62 | fs::write(dst, contents).unwrap(); |
60 | 63 | } |
61 | 64 | } |
| 65 | + |
| 66 | +#[cfg(not(feature = "in-rust-tree"))] |
62 | 67 | #[derive(Debug)] |
63 | 68 | struct Section { |
64 | 69 | doc: String, |
65 | 70 | before: String, |
66 | 71 | after: String, |
67 | 72 | } |
68 | 73 |
|
| 74 | +#[cfg(not(feature = "in-rust-tree"))] |
69 | 75 | #[derive(Debug)] |
70 | 76 | struct Assist { |
71 | 77 | id: String, |
72 | 78 | location: sourcegen::Location, |
73 | 79 | sections: Vec<Section>, |
74 | 80 | } |
75 | 81 |
|
| 82 | +#[cfg(not(feature = "in-rust-tree"))] |
76 | 83 | impl Assist { |
77 | 84 | fn collect() -> Vec<Assist> { |
78 | 85 | let handlers_dir = project_root().join("crates/ide-assists/src/handlers"); |
@@ -104,9 +111,11 @@ impl Assist { |
104 | 111 | while lines.peek().is_some() { |
105 | 112 | let doc = take_until(lines.by_ref(), "```").trim().to_string(); |
106 | 113 | assert!( |
107 | | - (doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with('.')) || assist.sections.len() > 0, |
| 114 | + (doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with('.')) |
| 115 | + || assist.sections.len() > 0, |
108 | 116 | "\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n", |
109 | | - &assist.id, doc, |
| 117 | + &assist.id, |
| 118 | + doc, |
110 | 119 | ); |
111 | 120 |
|
112 | 121 | let before = take_until(lines.by_ref(), "```"); |
@@ -135,6 +144,7 @@ impl Assist { |
135 | 144 | } |
136 | 145 | } |
137 | 146 |
|
| 147 | +#[cfg(not(feature = "in-rust-tree"))] |
138 | 148 | impl fmt::Display for Assist { |
139 | 149 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
140 | 150 | let _ = writeln!( |
@@ -169,13 +179,15 @@ impl fmt::Display for Assist { |
169 | 179 | } |
170 | 180 | } |
171 | 181 |
|
| 182 | +#[cfg(not(feature = "in-rust-tree"))] |
172 | 183 | fn hide_hash_comments(text: &str) -> String { |
173 | 184 | text.split('\n') // want final newline |
174 | 185 | .filter(|&it| !(it.starts_with("# ") || it == "#")) |
175 | 186 | .map(|it| format!("{}\n", it)) |
176 | 187 | .collect() |
177 | 188 | } |
178 | 189 |
|
| 190 | +#[cfg(not(feature = "in-rust-tree"))] |
179 | 191 | fn reveal_hash_comments(text: &str) -> String { |
180 | 192 | text.split('\n') // want final newline |
181 | 193 | .map(|it| { |
|
0 commit comments