diff options
-rw-r--r-- | xtask/src/codegen/gen_features.rs | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/xtask/src/codegen/gen_features.rs b/xtask/src/codegen/gen_features.rs deleted file mode 100644 index 3cf15ce02..000000000 --- a/xtask/src/codegen/gen_features.rs +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | //! Generates descriptors structure for unstable feature from Unstable Book | ||
2 | use std::path::{Path, PathBuf}; | ||
3 | |||
4 | use quote::quote; | ||
5 | use walkdir::WalkDir; | ||
6 | use xshell::{cmd, read_file}; | ||
7 | |||
8 | use crate::codegen::{project_root, reformat, update, Mode, Result}; | ||
9 | |||
10 | pub fn generate_features(mode: Mode) -> Result<()> { | ||
11 | if !Path::new("./target/rust").exists() { | ||
12 | cmd!("git clone https://github.com/rust-lang/rust ./target/rust").run()?; | ||
13 | } | ||
14 | |||
15 | let contents = generate_descriptor("./target/rust/src/doc/unstable-book/src".into())?; | ||
16 | |||
17 | let destination = project_root().join("crates/ide/src/completion/generated_features.rs"); | ||
18 | update(destination.as_path(), &contents, mode)?; | ||
19 | |||
20 | Ok(()) | ||
21 | } | ||
22 | |||
23 | fn generate_descriptor(src_dir: PathBuf) -> Result<String> { | ||
24 | let definitions = ["language-features", "library-features"] | ||
25 | .iter() | ||
26 | .flat_map(|it| WalkDir::new(src_dir.join(it))) | ||
27 | .filter_map(|e| e.ok()) | ||
28 | .filter(|entry| { | ||
29 | // Get all `.md ` files | ||
30 | entry.file_type().is_file() && entry.path().extension().unwrap_or_default() == "md" | ||
31 | }) | ||
32 | .map(|entry| { | ||
33 | let path = entry.path(); | ||
34 | let feature_ident = path.file_stem().unwrap().to_str().unwrap().replace("-", "_"); | ||
35 | let doc = read_file(path).unwrap(); | ||
36 | |||
37 | quote! { LintCompletion { label: #feature_ident, description: #doc } } | ||
38 | }); | ||
39 | |||
40 | let ts = quote! { | ||
41 | use crate::completion::complete_attribute::LintCompletion; | ||
42 | |||
43 | pub(super) const FEATURES: &[LintCompletion] = &[ | ||
44 | #(#definitions),* | ||
45 | ]; | ||
46 | }; | ||
47 | reformat(&ts.to_string()) | ||
48 | } | ||