mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Formatted changes.
This commit is contained in:
parent
d7e36c3dd2
commit
3aaf46afa1
@ -6,8 +6,8 @@ use ra_syntax::{
|
||||
|
||||
use crate::{
|
||||
ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams},
|
||||
Assist, AssistCtx, AssistId,
|
||||
utils::{get_missing_impl_items, resolve_target_trait},
|
||||
Assist, AssistCtx, AssistId,
|
||||
};
|
||||
|
||||
#[derive(PartialEq)]
|
||||
@ -129,7 +129,7 @@ fn add_missing_impl_members_inner(
|
||||
ast::ImplItem::FnDef(def) => match mode {
|
||||
AddMissingImplMembersMode::DefaultMethodsOnly => def.body().is_some(),
|
||||
AddMissingImplMembersMode::NoDefaultMethods => def.body().is_none(),
|
||||
}
|
||||
},
|
||||
_ => mode == AddMissingImplMembersMode::NoDefaultMethods,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
@ -9,14 +9,13 @@ use hir::db::HirDatabase;
|
||||
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
/// Generate a collection of associated items that are missing from a
|
||||
/// Generate a collection of associated items that are missing from a
|
||||
/// `impl Trait for` block.
|
||||
pub fn get_missing_impl_items(
|
||||
db: &impl HirDatabase,
|
||||
analyzer: &hir::SourceAnalyzer,
|
||||
impl_block: &ast::ImplBlock,
|
||||
) -> Vec<hir::AssocItem> {
|
||||
|
||||
// Names must be unique between constants and functions. However, type aliases
|
||||
// may share the same name as a function or constant.
|
||||
let mut impl_fns_consts = FxHashSet::default();
|
||||
@ -53,9 +52,10 @@ pub fn get_missing_impl_items(
|
||||
.filter(|i| match i {
|
||||
hir::AssocItem::Function(f) => !impl_fns_consts.contains(&f.name(db).to_string()),
|
||||
hir::AssocItem::TypeAlias(t) => !impl_type.contains(&t.name(db).to_string()),
|
||||
hir::AssocItem::Const(c) => {
|
||||
c.name(db).map(|n| !impl_fns_consts.contains(&n.to_string())).unwrap_or_default()
|
||||
}
|
||||
hir::AssocItem::Const(c) => c
|
||||
.name(db)
|
||||
.map(|n| !impl_fns_consts.contains(&n.to_string()))
|
||||
.unwrap_or_default(),
|
||||
})
|
||||
.map(|i| i.clone())
|
||||
.collect()
|
||||
|
@ -2,53 +2,55 @@ use crate::completion::{
|
||||
CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
|
||||
};
|
||||
|
||||
use ra_syntax::{ast::{self, edit}, AstNode, SyntaxKind, TextRange};
|
||||
use hir::{self, Docs, HasSource};
|
||||
use ra_syntax::{
|
||||
ast::{self, edit},
|
||||
AstNode, SyntaxKind, TextRange,
|
||||
};
|
||||
|
||||
use ra_assists::utils::get_missing_impl_items;
|
||||
|
||||
/// Analyzes the specified `CompletionContext` and provides magic completions
|
||||
/// if the context falls within a `impl Trait for` block.
|
||||
///
|
||||
///
|
||||
/// # Completion Activation
|
||||
/// The completion will activate when a user begins to type a function
|
||||
/// The completion will activate when a user begins to type a function
|
||||
/// definition, an associated type, or an associated constant.
|
||||
///
|
||||
///
|
||||
/// ### Functions
|
||||
/// ```ignore
|
||||
/// trait SomeTrait {
|
||||
/// fn foo(&self);
|
||||
/// }
|
||||
///
|
||||
///
|
||||
/// impl SomeTrait for () {
|
||||
/// fn <|>
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// ### Associated Types
|
||||
/// ```ignore
|
||||
/// trait SomeTrait {
|
||||
/// type SomeType;
|
||||
/// }
|
||||
///
|
||||
///
|
||||
/// impl SomeTrait for () {
|
||||
/// type <|>
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// ### Associated Constants
|
||||
/// ```ignore
|
||||
/// trait SomeTrait {
|
||||
/// const SOME_CONST: u16;
|
||||
/// }
|
||||
///
|
||||
///
|
||||
/// impl SomeTrait for () {
|
||||
/// const <|>
|
||||
/// }
|
||||
/// ```
|
||||
pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
|
||||
// it is possible to have a parent `fn` and `impl` block. Ignore completion
|
||||
// it is possible to have a parent `fn` and `impl` block. Ignore completion
|
||||
// attempts from within a `fn` block.
|
||||
if ctx.function_syntax.is_some() {
|
||||
return;
|
||||
@ -111,11 +113,7 @@ fn add_type_alias_impl(
|
||||
.add_to(acc);
|
||||
}
|
||||
|
||||
fn add_const_impl(
|
||||
acc: &mut Completions,
|
||||
ctx: &CompletionContext,
|
||||
const_: &hir::Const,
|
||||
) {
|
||||
fn add_const_impl(acc: &mut Completions, ctx: &CompletionContext, const_: &hir::Const) {
|
||||
let snippet = make_const_compl_syntax(&const_.source(ctx.db).value);
|
||||
|
||||
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
|
||||
@ -131,12 +129,8 @@ fn make_const_compl_syntax(const_: &ast::ConstDef) -> String {
|
||||
let const_start = const_.syntax().text_range().start();
|
||||
let const_end = const_.syntax().text_range().end();
|
||||
|
||||
let start = const_
|
||||
.syntax()
|
||||
.first_child_or_token()
|
||||
.map_or(
|
||||
const_start,
|
||||
|f| f.text_range().start());
|
||||
let start =
|
||||
const_.syntax().first_child_or_token().map_or(const_start, |f| f.text_range().start());
|
||||
|
||||
let end = const_
|
||||
.syntax()
|
||||
|
Loading…
Reference in New Issue
Block a user