mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Added competition for unstable features
Added xtask for download unstable book from rust repository and codegene for it. Also small changes from lint
This commit is contained in:
parent
020a40335b
commit
1a43a0f63e
8 changed files with 90 additions and 10 deletions
55
xtask/src/codegen/gen_unstable_future_descriptor.rs
Normal file
55
xtask/src/codegen/gen_unstable_future_descriptor.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
//! Generates descriptors structure for unstable feature from Unstable Book
|
||||
|
||||
use crate::{
|
||||
codegen::{self, project_root, Mode, Result},
|
||||
};
|
||||
use std::process::Command;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use walkdir::{DirEntry, WalkDir};
|
||||
use quote::{format_ident, quote};
|
||||
use crate::codegen::update;
|
||||
|
||||
pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> {
|
||||
let path = project_root().join(codegen::STORAGE);
|
||||
fs::create_dir_all(path.clone())?;
|
||||
|
||||
Command::new("git").current_dir(path.clone()).arg("init").output()?;
|
||||
Command::new("git").current_dir(path.clone()).args(&["remote", "add", "-f", "origin", codegen::REPOSITORY_URL]).output()?;
|
||||
Command::new("git").current_dir(path.clone()).args(&["sparse-checkout", "set", "/src/doc/unstable-book/src/"]).output()?;
|
||||
Command::new("git").current_dir(path.clone()).args(&["pull", "origin", "master"]).output()?;
|
||||
//TODO: check git, and do pull
|
||||
|
||||
let src_dir = path.join("src/doc/unstable-book/src");
|
||||
let files = WalkDir::new(src_dir.join("language-features"))
|
||||
.into_iter()
|
||||
.chain(WalkDir::new(src_dir.join("library-features")))
|
||||
.filter_map(|e| e.ok())
|
||||
.filter(|entry| {
|
||||
// Get all `.md ` files
|
||||
entry.file_type().is_file() && entry.path().extension().map(|ext| ext == "md").unwrap_or(false)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let definitions = files.iter().map(|entry| {
|
||||
let path = entry.path();
|
||||
let feature_ident = format!("{}", path.file_stem().unwrap().to_str().unwrap().replace("-", "_"));
|
||||
let doc = format!("{}", std::fs::read_to_string(path).unwrap() );
|
||||
|
||||
quote!{ LintCompletion { label: #feature_ident, description: #doc } }
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
let ts = quote! {
|
||||
use crate::completion::LintCompletion;
|
||||
|
||||
const UNSTABLE_FEATURE_DESCRIPTOR: &[LintCompletion] = &[
|
||||
#(#definitions),*
|
||||
];
|
||||
};
|
||||
|
||||
let destination = project_root().join(codegen::UNSTABLE_FEATURE);
|
||||
let contents = crate::reformat(ts.to_string())?;
|
||||
update(destination.as_path(), &contents, mode)?;
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue