aboutsummaryrefslogtreecommitdiff
path: root/xtask
diff options
context:
space:
mode:
Diffstat (limited to 'xtask')
-rw-r--r--xtask/src/codegen.rs15
-rw-r--r--xtask/src/codegen/gen_unstable_future_descriptor.rs62
-rw-r--r--xtask/src/main.rs1
-rw-r--r--xtask/tests/tidy.rs2
4 files changed, 77 insertions, 3 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index 78a84f68d..950dd61b2 100644
--- a/xtask/src/codegen.rs
+++ b/xtask/src/codegen.rs
@@ -9,6 +9,7 @@ mod gen_syntax;
9mod gen_parser_tests; 9mod gen_parser_tests;
10mod gen_assists_docs; 10mod gen_assists_docs;
11mod gen_feature_docs; 11mod gen_feature_docs;
12mod gen_unstable_future_descriptor;
12 13
13use std::{ 14use std::{
14 fmt, mem, 15 fmt, mem,
@@ -22,11 +23,15 @@ pub use self::{
22 gen_feature_docs::generate_feature_docs, 23 gen_feature_docs::generate_feature_docs,
23 gen_parser_tests::generate_parser_tests, 24 gen_parser_tests::generate_parser_tests,
24 gen_syntax::generate_syntax, 25 gen_syntax::generate_syntax,
26 gen_unstable_future_descriptor::generate_unstable_future_descriptor,
25}; 27};
26 28
27const GRAMMAR_DIR: &str = "crates/parser/src/grammar"; 29// Directory used by xtask
28const OK_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/ok"; 30const STORAGE: &str = ".xtask";
29const ERR_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/err"; 31
32const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar";
33const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/ok";
34const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err";
30 35
31const SYNTAX_KINDS: &str = "crates/parser/src/syntax_kind/generated.rs"; 36const SYNTAX_KINDS: &str = "crates/parser/src/syntax_kind/generated.rs";
32const AST_NODES: &str = "crates/syntax/src/ast/generated/nodes.rs"; 37const AST_NODES: &str = "crates/syntax/src/ast/generated/nodes.rs";
@@ -35,6 +40,10 @@ const AST_TOKENS: &str = "crates/syntax/src/ast/generated/tokens.rs";
35const ASSISTS_DIR: &str = "crates/assists/src/handlers"; 40const ASSISTS_DIR: &str = "crates/assists/src/handlers";
36const ASSISTS_TESTS: &str = "crates/assists/src/tests/generated.rs"; 41const ASSISTS_TESTS: &str = "crates/assists/src/tests/generated.rs";
37 42
43const REPOSITORY_URL: &str = "https://github.com/rust-lang/rust";
44const UNSTABLE_FEATURE: &str = "crates/ra_ide/src/completion/unstable_feature_descriptor.rs";
45const REPO_PATH: &str = "src/doc/unstable-book/src";
46
38#[derive(Debug, PartialEq, Eq, Clone, Copy)] 47#[derive(Debug, PartialEq, Eq, Clone, Copy)]
39pub enum Mode { 48pub enum Mode {
40 Overwrite, 49 Overwrite,
diff --git a/xtask/src/codegen/gen_unstable_future_descriptor.rs b/xtask/src/codegen/gen_unstable_future_descriptor.rs
new file mode 100644
index 000000000..3f3beb591
--- /dev/null
+++ b/xtask/src/codegen/gen_unstable_future_descriptor.rs
@@ -0,0 +1,62 @@
1//! Generates descriptors structure for unstable feature from Unstable Book
2
3use crate::codegen::update;
4use crate::codegen::{self, project_root, Mode, Result};
5use crate::not_bash::{fs2, pushd, run};
6use proc_macro2::TokenStream;
7use quote::quote;
8use std::path::PathBuf;
9use walkdir::WalkDir;
10
11fn generate_descriptor(src_dir: PathBuf) -> Result<TokenStream> {
12 let files = WalkDir::new(src_dir.join("language-features"))
13 .into_iter()
14 .chain(WalkDir::new(src_dir.join("library-features")))
15 .filter_map(|e| e.ok())
16 .filter(|entry| {
17 // Get all `.md ` files
18 entry.file_type().is_file()
19 && entry.path().extension().unwrap_or_default() == "md"
20 })
21 .collect::<Vec<_>>();
22
23 let definitions = files
24 .iter()
25 .map(|entry| {
26 let path = entry.path();
27 let feature_ident =
28 format!("{}", path.file_stem().unwrap().to_str().unwrap().replace("-", "_"));
29 let doc = format!("{}", std::fs::read_to_string(path).unwrap());
30
31 quote! { LintCompletion { label: #feature_ident, description: #doc } }
32 })
33 .collect::<Vec<_>>();
34
35 let ts = quote! {
36 use crate::completion::LintCompletion;
37
38 pub(crate) const UNSTABLE_FEATURE_DESCRIPTOR: &[LintCompletion] = &[
39 #(#definitions),*
40 ];
41 };
42 Ok(ts)
43}
44
45pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> {
46 let path = project_root().join(codegen::STORAGE);
47 fs2::create_dir_all(path.clone())?;
48
49 let _d = pushd(path.clone());
50 run!("git init")?;
51 run!("git remote add -f origin {}", codegen::REPOSITORY_URL)?;
52 run!("git pull origin master")?;
53
54 let src_dir = path.join(codegen::REPO_PATH);
55 let content = generate_descriptor(src_dir)?.to_string();
56
57 let contents = crate::reformat(content)?;
58 let destination = project_root().join(codegen::UNSTABLE_FEATURE);
59 update(destination.as_path(), &contents, mode)?;
60
61 Ok(())
62}
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index b69b884e5..71caff248 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -76,6 +76,7 @@ FLAGS:
76 "codegen" => { 76 "codegen" => {
77 args.finish()?; 77 args.finish()?;
78 codegen::generate_syntax(Mode::Overwrite)?; 78 codegen::generate_syntax(Mode::Overwrite)?;
79 codegen::generate_unstable_future_descriptor(Mode::Overwrite)?;
79 codegen::generate_parser_tests(Mode::Overwrite)?; 80 codegen::generate_parser_tests(Mode::Overwrite)?;
80 codegen::generate_assists_tests(Mode::Overwrite)?; 81 codegen::generate_assists_tests(Mode::Overwrite)?;
81 codegen::generate_assists_docs(Mode::Overwrite)?; 82 codegen::generate_assists_docs(Mode::Overwrite)?;
diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs
index 76895aeca..ca9749ed4 100644
--- a/xtask/tests/tidy.rs
+++ b/xtask/tests/tidy.rs
@@ -112,6 +112,8 @@ fn check_todo(path: &Path, text: &str) {
112 // To support generating `todo!()` in assists, we have `expr_todo()` in 112 // To support generating `todo!()` in assists, we have `expr_todo()` in
113 // `ast::make`. 113 // `ast::make`.
114 "ast/make.rs", 114 "ast/make.rs",
115 // The documentation in string literals may contain anything for its own purposes
116 "completion/unstable_feature_descriptor.rs",
115 ]; 117 ];
116 if need_todo.iter().any(|p| path.ends_with(p)) { 118 if need_todo.iter().any(|p| path.ends_with(p)) {
117 return; 119 return;