aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide/src/completion.rs3
-rw-r--r--crates/ra_ide/src/completion/complete_attribute.rs11
-rw-r--r--xtask/src/codegen.rs2
-rw-r--r--xtask/src/codegen/gen_unstable_future_descriptor.rs49
4 files changed, 39 insertions, 26 deletions
diff --git a/crates/ra_ide/src/completion.rs b/crates/ra_ide/src/completion.rs
index 7b96902fb..a537b68b1 100644
--- a/crates/ra_ide/src/completion.rs
+++ b/crates/ra_ide/src/completion.rs
@@ -21,12 +21,13 @@ mod complete_trait_impl;
21mod unstable_feature_descriptor; 21mod unstable_feature_descriptor;
22use ra_ide_db::RootDatabase; 22use ra_ide_db::RootDatabase;
23 23
24#[rustfmt::skip]
24use crate::{ 25use crate::{
25 completion::{ 26 completion::{
26 completion_context::CompletionContext, 27 completion_context::CompletionContext,
27 completion_item::{CompletionKind, Completions}, 28 completion_item::{CompletionKind, Completions},
28 29
29 //TODO: rework 30 //TODO: cyclic imports caused by xtask generation, this should be better
30 unstable_feature_descriptor::UNSTABLE_FEATURE_DESCRIPTOR, 31 unstable_feature_descriptor::UNSTABLE_FEATURE_DESCRIPTOR,
31 complete_attribute::LintCompletion, 32 complete_attribute::LintCompletion,
32 }, 33 },
diff --git a/crates/ra_ide/src/completion/complete_attribute.rs b/crates/ra_ide/src/completion/complete_attribute.rs
index 50b0b3ff6..2161cdfd2 100644
--- a/crates/ra_ide/src/completion/complete_attribute.rs
+++ b/crates/ra_ide/src/completion/complete_attribute.rs
@@ -19,9 +19,7 @@ pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
19 (Some(path), Some(token_tree)) if path.to_string() == "derive" => { 19 (Some(path), Some(token_tree)) if path.to_string() == "derive" => {
20 complete_derive(acc, ctx, token_tree) 20 complete_derive(acc, ctx, token_tree)
21 } 21 }
22 (Some(path), Some(token_tree)) 22 (Some(path), Some(token_tree)) if path.to_string() == "feature" => {
23 if path.to_string() == "feature" =>
24 {
25 complete_lint(acc, ctx, token_tree, UNSTABLE_FEATURE_DESCRIPTOR); 23 complete_lint(acc, ctx, token_tree, UNSTABLE_FEATURE_DESCRIPTOR);
26 } 24 }
27 (Some(path), Some(token_tree)) 25 (Some(path), Some(token_tree))
@@ -169,7 +167,12 @@ fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input:
169 } 167 }
170} 168}
171 169
172fn complete_lint(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree, lints_completions: &[LintCompletion]) { 170fn complete_lint(
171 acc: &mut Completions,
172 ctx: &CompletionContext,
173 derive_input: ast::TokenTree,
174 lints_completions: &[LintCompletion],
175) {
173 if let Ok(existing_lints) = parse_comma_sep_input(derive_input) { 176 if let Ok(existing_lints) = parse_comma_sep_input(derive_input) {
174 for lint_completion in lints_completions 177 for lint_completion in lints_completions
175 .into_iter() 178 .into_iter()
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index 209caacc3..c7cac50fe 100644
--- a/xtask/src/codegen.rs
+++ b/xtask/src/codegen.rs
@@ -26,7 +26,7 @@ pub use self::{
26 gen_unstable_future_descriptor::generate_unstable_future_descriptor, 26 gen_unstable_future_descriptor::generate_unstable_future_descriptor,
27}; 27};
28 28
29// Directory used by xtask 29// Directory used by xtask
30const STORAGE: &str = ".xtask"; 30const STORAGE: &str = ".xtask";
31 31
32const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; 32const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar";
diff --git a/xtask/src/codegen/gen_unstable_future_descriptor.rs b/xtask/src/codegen/gen_unstable_future_descriptor.rs
index 6dce8ba0a..75b603d7d 100644
--- a/xtask/src/codegen/gen_unstable_future_descriptor.rs
+++ b/xtask/src/codegen/gen_unstable_future_descriptor.rs
@@ -1,23 +1,27 @@
1//! Generates descriptors structure for unstable feature from Unstable Book 1//! Generates descriptors structure for unstable feature from Unstable Book
2 2
3use crate::{ 3use crate::codegen::update;
4 codegen::{self, project_root, Mode, Result}, 4use crate::codegen::{self, project_root, Mode, Result};
5}; 5use quote::quote;
6use std::process::Command;
7use std::fs; 6use std::fs;
7use std::process::Command;
8use walkdir::WalkDir; 8use walkdir::WalkDir;
9use quote::quote;
10use crate::codegen::update;
11 9
12pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> { 10pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> {
13 let path = project_root().join(codegen::STORAGE); 11 let path = project_root().join(codegen::STORAGE);
14 fs::create_dir_all(path.clone())?; 12 fs::create_dir_all(path.clone())?;
15 13
16 Command::new("git").current_dir(path.clone()).arg("init").output()?; 14 Command::new("git").current_dir(path.clone()).arg("init").output()?;
17 Command::new("git").current_dir(path.clone()).args(&["remote", "add", "-f", "origin", codegen::REPOSITORY_URL]).output()?; 15 Command::new("git")
18 Command::new("git").current_dir(path.clone()).args(&["sparse-checkout", "set", "/src/doc/unstable-book/src/"]).output()?; 16 .current_dir(path.clone())
17 .args(&["remote", "add", "-f", "origin", codegen::REPOSITORY_URL])
18 .output()?;
19 Command::new("git")
20 .current_dir(path.clone())
21 .args(&["sparse-checkout", "set", "/src/doc/unstable-book/src/"])
22 .output()?;
19 Command::new("git").current_dir(path.clone()).args(&["pull", "origin", "master"]).output()?; 23 Command::new("git").current_dir(path.clone()).args(&["pull", "origin", "master"]).output()?;
20 //TODO: check git, and do pull 24 //TODO: check git, and do pull
21 25
22 let src_dir = path.join("src/doc/unstable-book/src"); 26 let src_dir = path.join("src/doc/unstable-book/src");
23 let files = WalkDir::new(src_dir.join("language-features")) 27 let files = WalkDir::new(src_dir.join("language-features"))
@@ -26,18 +30,23 @@ pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> {
26 .filter_map(|e| e.ok()) 30 .filter_map(|e| e.ok())
27 .filter(|entry| { 31 .filter(|entry| {
28 // Get all `.md ` files 32 // Get all `.md ` files
29 entry.file_type().is_file() && entry.path().extension().map(|ext| ext == "md").unwrap_or(false) 33 entry.file_type().is_file()
34 && entry.path().extension().map(|ext| ext == "md").unwrap_or(false)
35 })
36 .collect::<Vec<_>>();
37
38 let definitions = files
39 .iter()
40 .map(|entry| {
41 let path = entry.path();
42 let feature_ident =
43 format!("{}", path.file_stem().unwrap().to_str().unwrap().replace("-", "_"));
44 let doc = format!("{}", std::fs::read_to_string(path).unwrap());
45
46 quote! { LintCompletion { label: #feature_ident, description: #doc } }
30 }) 47 })
31 .collect::<Vec<_>>(); 48 .collect::<Vec<_>>();
32 49
33 let definitions = files.iter().map(|entry| {
34 let path = entry.path();
35 let feature_ident = format!("{}", path.file_stem().unwrap().to_str().unwrap().replace("-", "_"));
36 let doc = format!("{}", std::fs::read_to_string(path).unwrap() );
37
38 quote!{ LintCompletion { label: #feature_ident, description: #doc } }
39 }).collect::<Vec<_>>();
40
41 let ts = quote! { 50 let ts = quote! {
42 use crate::completion::LintCompletion; 51 use crate::completion::LintCompletion;
43 52
@@ -45,10 +54,10 @@ pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> {
45 #(#definitions),* 54 #(#definitions),*
46 ]; 55 ];
47 }; 56 };
48 57
49 let destination = project_root().join(codegen::UNSTABLE_FEATURE); 58 let destination = project_root().join(codegen::UNSTABLE_FEATURE);
50 let contents = crate::reformat(ts.to_string())?; 59 let contents = crate::reformat(ts.to_string())?;
51 update(destination.as_path(), &contents, mode)?; 60 update(destination.as_path(), &contents, mode)?;
52 61
53 Ok(()) 62 Ok(())
54} \ No newline at end of file 63}