mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Merge #5695
5695: Added completion for unstable features r=matklad a=Fihtangolz Added xtask for downloading list of unstable features from the unstable book and codegen for it. Also included small changes from linter. Co-authored-by: Dmitry <mamhigtt@gmail.com> Co-authored-by: Dmitry Opokin <mamhigtt@gmail.com>
This commit is contained in:
commit
f18f9da7d8
8 changed files with 100 additions and 8 deletions
|
@ -18,6 +18,7 @@ mod complete_unqualified_path;
|
|||
mod complete_postfix;
|
||||
mod complete_macro_in_item_position;
|
||||
mod complete_trait_impl;
|
||||
mod unstable_feature_descriptor;
|
||||
|
||||
use ide_db::RootDatabase;
|
||||
|
||||
|
@ -29,6 +30,11 @@ use crate::{
|
|||
FilePosition,
|
||||
};
|
||||
|
||||
//FIXME: cyclic imports caused by xtask generation, this should be better
|
||||
use crate::completion::{
|
||||
complete_attribute::LintCompletion, unstable_feature_descriptor::UNSTABLE_FEATURE_DESCRIPTOR,
|
||||
};
|
||||
|
||||
pub use crate::completion::{
|
||||
completion_config::CompletionConfig,
|
||||
completion_item::{CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat},
|
||||
|
|
|
@ -9,6 +9,7 @@ use syntax::{ast, AstNode, SyntaxKind};
|
|||
use crate::completion::{
|
||||
completion_context::CompletionContext,
|
||||
completion_item::{CompletionItem, CompletionItemKind, CompletionKind, Completions},
|
||||
UNSTABLE_FEATURE_DESCRIPTOR,
|
||||
};
|
||||
|
||||
pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
|
||||
|
@ -17,12 +18,15 @@ pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
|
|||
(Some(path), Some(token_tree)) if path.to_string() == "derive" => {
|
||||
complete_derive(acc, ctx, token_tree)
|
||||
}
|
||||
(Some(path), Some(token_tree)) if path.to_string() == "feature" => {
|
||||
complete_lint(acc, ctx, token_tree, UNSTABLE_FEATURE_DESCRIPTOR)
|
||||
}
|
||||
(Some(path), Some(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(_token_tree)) => {}
|
||||
_ => complete_attribute_start(acc, ctx, attribute),
|
||||
|
@ -162,9 +166,14 @@ 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))
|
||||
{
|
||||
|
@ -228,7 +237,7 @@ fn get_derive_names_in_scope(ctx: &CompletionContext) -> FxHashSet<String> {
|
|||
result
|
||||
}
|
||||
|
||||
struct DeriveCompletion {
|
||||
pub(crate) struct DeriveCompletion {
|
||||
label: &'static str,
|
||||
dependencies: &'static [&'static str],
|
||||
}
|
||||
|
@ -248,9 +257,9 @@ const DEFAULT_DERIVE_COMPLETIONS: &[DeriveCompletion] = &[
|
|||
DeriveCompletion { label: "Ord", dependencies: &["PartialOrd", "Eq", "PartialEq"] },
|
||||
];
|
||||
|
||||
struct LintCompletion {
|
||||
label: &'static str,
|
||||
description: &'static str,
|
||||
pub(crate) struct LintCompletion {
|
||||
pub(crate) label: &'static str,
|
||||
pub(crate) description: &'static str,
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
|
4
crates/ide/src/completion/unstable_feature_descriptor.rs
Normal file
4
crates/ide/src/completion/unstable_feature_descriptor.rs
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue