1 //! Generates descriptors structure for unstable feature from Unstable Book
2 use std::path::{Path, PathBuf};
8 codegen::{project_root, reformat, update, Mode, Result},
12 pub fn generate_features(mode: Mode) -> Result<()> {
13 if !Path::new("./target/rust").exists() {
14 run!("git clone https://github.com/rust-lang/rust ./target/rust")?;
17 let contents = generate_descriptor("./target/rust/src/doc/unstable-book/src".into())?;
19 let destination = project_root().join("crates/ide/src/completion/generated_features.rs");
20 update(destination.as_path(), &contents, mode)?;
25 fn generate_descriptor(src_dir: PathBuf) -> Result<String> {
26 let definitions = ["language-features", "library-features"]
28 .flat_map(|it| WalkDir::new(src_dir.join(it)))
29 .filter_map(|e| e.ok())
31 // Get all `.md ` files
32 entry.file_type().is_file() && entry.path().extension().unwrap_or_default() == "md"
35 let path = entry.path();
36 let feature_ident = path.file_stem().unwrap().to_str().unwrap().replace("-", "_");
37 let doc = fs2::read_to_string(path).unwrap();
39 quote! { LintCompletion { label: #feature_ident, description: #doc } }
43 use crate::completion::complete_attribute::LintCompletion;
45 pub(super) const FEATURES: &[LintCompletion] = &[