mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Formatted changes.
This commit is contained in:
parent
d7e36c3dd2
commit
3aaf46afa1
3 changed files with 23 additions and 29 deletions
|
@ -6,8 +6,8 @@ use ra_syntax::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams},
|
ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams},
|
||||||
Assist, AssistCtx, AssistId,
|
|
||||||
utils::{get_missing_impl_items, resolve_target_trait},
|
utils::{get_missing_impl_items, resolve_target_trait},
|
||||||
|
Assist, AssistCtx, AssistId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
|
@ -129,7 +129,7 @@ fn add_missing_impl_members_inner(
|
||||||
ast::ImplItem::FnDef(def) => match mode {
|
ast::ImplItem::FnDef(def) => match mode {
|
||||||
AddMissingImplMembersMode::DefaultMethodsOnly => def.body().is_some(),
|
AddMissingImplMembersMode::DefaultMethodsOnly => def.body().is_some(),
|
||||||
AddMissingImplMembersMode::NoDefaultMethods => def.body().is_none(),
|
AddMissingImplMembersMode::NoDefaultMethods => def.body().is_none(),
|
||||||
}
|
},
|
||||||
_ => mode == AddMissingImplMembersMode::NoDefaultMethods,
|
_ => mode == AddMissingImplMembersMode::NoDefaultMethods,
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
|
@ -16,7 +16,6 @@ pub fn get_missing_impl_items(
|
||||||
analyzer: &hir::SourceAnalyzer,
|
analyzer: &hir::SourceAnalyzer,
|
||||||
impl_block: &ast::ImplBlock,
|
impl_block: &ast::ImplBlock,
|
||||||
) -> Vec<hir::AssocItem> {
|
) -> Vec<hir::AssocItem> {
|
||||||
|
|
||||||
// Names must be unique between constants and functions. However, type aliases
|
// Names must be unique between constants and functions. However, type aliases
|
||||||
// may share the same name as a function or constant.
|
// may share the same name as a function or constant.
|
||||||
let mut impl_fns_consts = FxHashSet::default();
|
let mut impl_fns_consts = FxHashSet::default();
|
||||||
|
@ -53,9 +52,10 @@ pub fn get_missing_impl_items(
|
||||||
.filter(|i| match i {
|
.filter(|i| match i {
|
||||||
hir::AssocItem::Function(f) => !impl_fns_consts.contains(&f.name(db).to_string()),
|
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::TypeAlias(t) => !impl_type.contains(&t.name(db).to_string()),
|
||||||
hir::AssocItem::Const(c) => {
|
hir::AssocItem::Const(c) => c
|
||||||
c.name(db).map(|n| !impl_fns_consts.contains(&n.to_string())).unwrap_or_default()
|
.name(db)
|
||||||
}
|
.map(|n| !impl_fns_consts.contains(&n.to_string()))
|
||||||
|
.unwrap_or_default(),
|
||||||
})
|
})
|
||||||
.map(|i| i.clone())
|
.map(|i| i.clone())
|
||||||
.collect()
|
.collect()
|
||||||
|
|
|
@ -2,8 +2,11 @@ use crate::completion::{
|
||||||
CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
|
CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
|
||||||
};
|
};
|
||||||
|
|
||||||
use ra_syntax::{ast::{self, edit}, AstNode, SyntaxKind, TextRange};
|
|
||||||
use hir::{self, Docs, HasSource};
|
use hir::{self, Docs, HasSource};
|
||||||
|
use ra_syntax::{
|
||||||
|
ast::{self, edit},
|
||||||
|
AstNode, SyntaxKind, TextRange,
|
||||||
|
};
|
||||||
|
|
||||||
use ra_assists::utils::get_missing_impl_items;
|
use ra_assists::utils::get_missing_impl_items;
|
||||||
|
|
||||||
|
@ -47,7 +50,6 @@ use ra_assists::utils::get_missing_impl_items;
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) {
|
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.
|
// attempts from within a `fn` block.
|
||||||
if ctx.function_syntax.is_some() {
|
if ctx.function_syntax.is_some() {
|
||||||
|
@ -111,11 +113,7 @@ fn add_type_alias_impl(
|
||||||
.add_to(acc);
|
.add_to(acc);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_const_impl(
|
fn add_const_impl(acc: &mut Completions, ctx: &CompletionContext, const_: &hir::Const) {
|
||||||
acc: &mut Completions,
|
|
||||||
ctx: &CompletionContext,
|
|
||||||
const_: &hir::Const,
|
|
||||||
) {
|
|
||||||
let snippet = make_const_compl_syntax(&const_.source(ctx.db).value);
|
let snippet = make_const_compl_syntax(&const_.source(ctx.db).value);
|
||||||
|
|
||||||
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
|
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_start = const_.syntax().text_range().start();
|
||||||
let const_end = const_.syntax().text_range().end();
|
let const_end = const_.syntax().text_range().end();
|
||||||
|
|
||||||
let start = const_
|
let start =
|
||||||
.syntax()
|
const_.syntax().first_child_or_token().map_or(const_start, |f| f.text_range().start());
|
||||||
.first_child_or_token()
|
|
||||||
.map_or(
|
|
||||||
const_start,
|
|
||||||
|f| f.text_range().start());
|
|
||||||
|
|
||||||
let end = const_
|
let end = const_
|
||||||
.syntax()
|
.syntax()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue