mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
apply format
This commit is contained in:
parent
7f71ae8d73
commit
cff0fba5e5
4 changed files with 40 additions and 27 deletions
|
@ -21,12 +21,13 @@ mod complete_trait_impl;
|
||||||
mod unstable_feature_descriptor;
|
mod unstable_feature_descriptor;
|
||||||
use ra_ide_db::RootDatabase;
|
use ra_ide_db::RootDatabase;
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
use crate::{
|
use crate::{
|
||||||
completion::{
|
completion::{
|
||||||
completion_context::CompletionContext,
|
completion_context::CompletionContext,
|
||||||
completion_item::{CompletionKind, Completions},
|
completion_item::{CompletionKind, Completions},
|
||||||
|
|
||||||
//TODO: rework
|
//TODO: cyclic imports caused by xtask generation, this should be better
|
||||||
unstable_feature_descriptor::UNSTABLE_FEATURE_DESCRIPTOR,
|
unstable_feature_descriptor::UNSTABLE_FEATURE_DESCRIPTOR,
|
||||||
complete_attribute::LintCompletion,
|
complete_attribute::LintCompletion,
|
||||||
},
|
},
|
||||||
|
|
|
@ -19,9 +19,7 @@ pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
(Some(path), Some(token_tree)) if path.to_string() == "derive" => {
|
(Some(path), Some(token_tree)) if path.to_string() == "derive" => {
|
||||||
complete_derive(acc, ctx, token_tree)
|
complete_derive(acc, ctx, token_tree)
|
||||||
}
|
}
|
||||||
(Some(path), Some(token_tree))
|
(Some(path), Some(token_tree)) if path.to_string() == "feature" => {
|
||||||
if path.to_string() == "feature" =>
|
|
||||||
{
|
|
||||||
complete_lint(acc, ctx, token_tree, UNSTABLE_FEATURE_DESCRIPTOR);
|
complete_lint(acc, ctx, token_tree, UNSTABLE_FEATURE_DESCRIPTOR);
|
||||||
}
|
}
|
||||||
(Some(path), Some(token_tree))
|
(Some(path), Some(token_tree))
|
||||||
|
@ -169,7 +167,12 @@ fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete_lint(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree, lints_completions: &[LintCompletion]) {
|
fn complete_lint(
|
||||||
|
acc: &mut Completions,
|
||||||
|
ctx: &CompletionContext,
|
||||||
|
derive_input: ast::TokenTree,
|
||||||
|
lints_completions: &[LintCompletion],
|
||||||
|
) {
|
||||||
if let Ok(existing_lints) = parse_comma_sep_input(derive_input) {
|
if let Ok(existing_lints) = parse_comma_sep_input(derive_input) {
|
||||||
for lint_completion in lints_completions
|
for lint_completion in lints_completions
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
@ -26,7 +26,7 @@ pub use self::{
|
||||||
gen_unstable_future_descriptor::generate_unstable_future_descriptor,
|
gen_unstable_future_descriptor::generate_unstable_future_descriptor,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Directory used by xtask
|
// Directory used by xtask
|
||||||
const STORAGE: &str = ".xtask";
|
const STORAGE: &str = ".xtask";
|
||||||
|
|
||||||
const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar";
|
const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar";
|
||||||
|
|
|
@ -1,23 +1,27 @@
|
||||||
//! Generates descriptors structure for unstable feature from Unstable Book
|
//! 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 walkdir::WalkDir;
|
|
||||||
use quote::quote;
|
|
||||||
use crate::codegen::update;
|
use crate::codegen::update;
|
||||||
|
use crate::codegen::{self, project_root, Mode, Result};
|
||||||
|
use quote::quote;
|
||||||
|
use std::fs;
|
||||||
|
use std::process::Command;
|
||||||
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> {
|
pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> {
|
||||||
let path = project_root().join(codegen::STORAGE);
|
let path = project_root().join(codegen::STORAGE);
|
||||||
fs::create_dir_all(path.clone())?;
|
fs::create_dir_all(path.clone())?;
|
||||||
|
|
||||||
Command::new("git").current_dir(path.clone()).arg("init").output()?;
|
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")
|
||||||
Command::new("git").current_dir(path.clone()).args(&["sparse-checkout", "set", "/src/doc/unstable-book/src/"]).output()?;
|
.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()?;
|
Command::new("git").current_dir(path.clone()).args(&["pull", "origin", "master"]).output()?;
|
||||||
//TODO: check git, and do pull
|
//TODO: check git, and do pull
|
||||||
|
|
||||||
let src_dir = path.join("src/doc/unstable-book/src");
|
let src_dir = path.join("src/doc/unstable-book/src");
|
||||||
let files = WalkDir::new(src_dir.join("language-features"))
|
let files = WalkDir::new(src_dir.join("language-features"))
|
||||||
|
@ -26,18 +30,23 @@ pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> {
|
||||||
.filter_map(|e| e.ok())
|
.filter_map(|e| e.ok())
|
||||||
.filter(|entry| {
|
.filter(|entry| {
|
||||||
// Get all `.md ` files
|
// Get all `.md ` files
|
||||||
entry.file_type().is_file() && entry.path().extension().map(|ext| ext == "md").unwrap_or(false)
|
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<_>>();
|
.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! {
|
let ts = quote! {
|
||||||
use crate::completion::LintCompletion;
|
use crate::completion::LintCompletion;
|
||||||
|
|
||||||
|
@ -45,10 +54,10 @@ pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> {
|
||||||
#(#definitions),*
|
#(#definitions),*
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
let destination = project_root().join(codegen::UNSTABLE_FEATURE);
|
let destination = project_root().join(codegen::UNSTABLE_FEATURE);
|
||||||
let contents = crate::reformat(ts.to_string())?;
|
let contents = crate::reformat(ts.to_string())?;
|
||||||
update(destination.as_path(), &contents, mode)?;
|
update(destination.as_path(), &contents, mode)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue