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:
Dmitry 2020-08-09 20:33:47 +07:00
parent 020a40335b
commit 1a43a0f63e
8 changed files with 90 additions and 10 deletions

View File

@ -4,7 +4,7 @@ members = [ "crates/*", "xtask/" ]
[profile.dev]
# disabling debug info speeds up builds a bunch,
# and we don't rely on it for debugging that much.
debug = 0
debug = 2
[profile.release]
incremental = true

View File

@ -1,4 +1,4 @@
//! FIXME: write short doc here
//! Provides set of implementation for hir's objects that allows get back location in file.
use either::Either;
use hir_def::{

View File

@ -18,13 +18,17 @@
mod complete_postfix;
mod complete_macro_in_item_position;
mod complete_trait_impl;
mod unstable_feature_descriptor;
use ra_ide_db::RootDatabase;
use crate::{
completion::{
completion_context::CompletionContext,
completion_item::{CompletionKind, Completions},
//TODO: rework
unstable_feature_descriptor::UNSTABLE_FEATURE_DESCRIPTOR,
complete_attribute::LintCompletion,
},
FilePosition,
};

View File

@ -9,8 +9,11 @@
use crate::completion::{
completion_context::CompletionContext,
completion_item::{CompletionItem, CompletionItemKind, CompletionKind, Completions},
unstable_feature_descriptor
};
use crate::completion::UNSTABLE_FEATURE_DESCRIPTOR;
pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
let attribute = ctx.attribute_under_caret.as_ref()?;
match (attribute.path(), attribute.input()) {
@ -19,12 +22,17 @@ pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
{
complete_derive(acc, ctx, token_tree)
}
(Some(path), Some(ast::AttrInput::TokenTree(token_tree)))
if path.to_string() == "feature" =>
{
complete_lint(acc, ctx, token_tree, UNSTABLE_FEATURE_DESCRIPTOR);
}
(Some(path), Some(ast::AttrInput::TokenTree(token_tree)))
if ["allow", "warn", "deny", "forbid"]
.iter()
.any(|lint_level| lint_level == &path.to_string()) =>
{
complete_lint(acc, ctx, token_tree)
complete_lint(acc, ctx, token_tree, DEFAULT_LINT_COMPLETIONS)
}
(_, Some(ast::AttrInput::TokenTree(_token_tree))) => {}
_ => complete_attribute_start(acc, ctx, attribute),
@ -87,7 +95,7 @@ const fn attr(
attr(r#"deprecated = "…""#, Some("deprecated"), Some(r#"deprecated = "${0:reason}""#)),
attr("derive(…)", Some("derive"), Some(r#"derive(${0:Debug})"#)),
attr(r#"doc = "…""#, Some("doc"), Some(r#"doc = "${0:docs}""#)),
attr("feature(…)", Some("feature"), Some("feature(${0:flag})")).prefer_inner(),
attr("feature(…)", Some("feature"), Some("feature(${0:lint})")).prefer_inner(),
attr("forbid(…)", Some("forbid"), Some("forbid(${0:lint})")),
// FIXME: resolve through macro resolution?
attr("global_allocator", None, None).prefer_inner(),
@ -164,9 +172,9 @@ fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input:
}
}
fn complete_lint(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) {
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) {
for lint_completion in DEFAULT_LINT_COMPLETIONS
for lint_completion in lints_completions
.into_iter()
.filter(|completion| !existing_lints.contains(completion.label))
{
@ -250,9 +258,9 @@ struct DeriveCompletion {
DeriveCompletion { label: "Ord", dependencies: &["PartialOrd", "Eq", "PartialEq"] },
];
struct LintCompletion {
label: &'static str,
description: &'static str,
pub struct LintCompletion {
pub label: &'static str,
pub description: &'static str,
}
#[rustfmt::skip]

File diff suppressed because one or more lines are too long

View File

@ -9,6 +9,7 @@
mod gen_parser_tests;
mod gen_assists_docs;
mod gen_feature_docs;
mod gen_unstable_future_descriptor;
use std::{
fmt, mem,
@ -22,8 +23,12 @@
gen_feature_docs::generate_feature_docs,
gen_parser_tests::generate_parser_tests,
gen_syntax::generate_syntax,
gen_unstable_future_descriptor::generate_unstable_future_descriptor,
};
// Directory used by xtask
const STORAGE: &str = ".xtask";
const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar";
const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/ok";
const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err";
@ -35,6 +40,9 @@
const ASSISTS_DIR: &str = "crates/ra_assists/src/handlers";
const ASSISTS_TESTS: &str = "crates/ra_assists/src/tests/generated.rs";
const REPOSITORY_URL: &str = "https://github.com/rust-lang/rust";
const UNSTABLE_FEATURE: &str = "crates/ra_ide/src/completion/unstable_feature_descriptor.rs";
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Mode {
Overwrite,

View 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(())
}

View File

@ -76,6 +76,7 @@ fn main() -> Result<()> {
"codegen" => {
args.finish()?;
codegen::generate_syntax(Mode::Overwrite)?;
codegen::generate_unstable_future_descriptor(Mode::Overwrite)?;
codegen::generate_parser_tests(Mode::Overwrite)?;
codegen::generate_assists_tests(Mode::Overwrite)?;
codegen::generate_assists_docs(Mode::Overwrite)?;