mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-26 11:55:04 +00:00
Drop needless trait
This commit is contained in:
parent
e07d3c94de
commit
0ed27c388a
4 changed files with 20 additions and 28 deletions
|
@ -1,6 +1,9 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
use ra_syntax::{ast, match_ast, AstNode};
|
use ra_syntax::{
|
||||||
|
ast::{self, ModuleItemOwner},
|
||||||
|
match_ast, AstNode,
|
||||||
|
};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions};
|
use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions};
|
||||||
|
@ -16,11 +19,19 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
|
|
||||||
let mut params = FxHashMap::default();
|
let mut params = FxHashMap::default();
|
||||||
for node in ctx.token.parent().ancestors() {
|
for node in ctx.token.parent().ancestors() {
|
||||||
match_ast! {
|
let items = match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::SourceFile(it) => process(it, &mut params),
|
ast::SourceFile(it) => it.items(),
|
||||||
ast::ItemList(it) => process(it, &mut params),
|
ast::ItemList(it) => it.items(),
|
||||||
_ => (),
|
_ => continue,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for item in items {
|
||||||
|
if let ast::ModuleItem::FnDef(func) = item {
|
||||||
|
func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| {
|
||||||
|
let text = param.syntax().text().to_string();
|
||||||
|
params.entry(text).or_insert((0, param)).0 += 1;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,15 +50,6 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
.lookup_by(lookup)
|
.lookup_by(lookup)
|
||||||
.add_to(acc)
|
.add_to(acc)
|
||||||
});
|
});
|
||||||
|
|
||||||
fn process<N: ast::FnDefOwner>(node: N, params: &mut FxHashMap<String, (u32, ast::Param)>) {
|
|
||||||
node.functions().filter_map(|it| it.param_list()).flat_map(|it| it.params()).for_each(
|
|
||||||
|param| {
|
|
||||||
let text = param.syntax().text().to_string();
|
|
||||||
params.entry(text).or_insert((0, param)).0 += 1;
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -22,7 +22,6 @@ impl AstNode for SourceFile {
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
}
|
}
|
||||||
impl ast::ModuleItemOwner for SourceFile {}
|
impl ast::ModuleItemOwner for SourceFile {}
|
||||||
impl ast::FnDefOwner for SourceFile {}
|
|
||||||
impl ast::AttrsOwner for SourceFile {}
|
impl ast::AttrsOwner for SourceFile {}
|
||||||
impl SourceFile {
|
impl SourceFile {
|
||||||
pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) }
|
pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) }
|
||||||
|
@ -344,7 +343,6 @@ impl AstNode for ItemList {
|
||||||
}
|
}
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
}
|
}
|
||||||
impl ast::FnDefOwner for ItemList {}
|
|
||||||
impl ast::ModuleItemOwner for ItemList {}
|
impl ast::ModuleItemOwner for ItemList {}
|
||||||
impl ItemList {
|
impl ItemList {
|
||||||
pub fn l_curly_token(&self) -> Option<LCurly> { support::token(&self.syntax) }
|
pub fn l_curly_token(&self) -> Option<LCurly> { support::token(&self.syntax) }
|
||||||
|
@ -2512,7 +2510,6 @@ impl AstNode for MacroItems {
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
}
|
}
|
||||||
impl ast::ModuleItemOwner for MacroItems {}
|
impl ast::ModuleItemOwner for MacroItems {}
|
||||||
impl ast::FnDefOwner for MacroItems {}
|
|
||||||
impl MacroItems {}
|
impl MacroItems {}
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct MacroStmts {
|
pub struct MacroStmts {
|
||||||
|
@ -2548,7 +2545,6 @@ impl AstNode for ExternItemList {
|
||||||
}
|
}
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
}
|
}
|
||||||
impl ast::FnDefOwner for ExternItemList {}
|
|
||||||
impl ast::ModuleItemOwner for ExternItemList {}
|
impl ast::ModuleItemOwner for ExternItemList {}
|
||||||
impl ExternItemList {
|
impl ExternItemList {
|
||||||
pub fn l_curly_token(&self) -> Option<LCurly> { support::token(&self.syntax) }
|
pub fn l_curly_token(&self) -> Option<LCurly> { support::token(&self.syntax) }
|
||||||
|
|
|
@ -43,12 +43,6 @@ pub trait ArgListOwner: AstNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FnDefOwner: AstNode {
|
|
||||||
fn functions(&self) -> AstChildren<ast::FnDef> {
|
|
||||||
support::children(self.syntax())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait ModuleItemOwner: AstNode {
|
pub trait ModuleItemOwner: AstNode {
|
||||||
fn items(&self) -> AstChildren<ast::ModuleItem> {
|
fn items(&self) -> AstChildren<ast::ModuleItem> {
|
||||||
support::children(self.syntax())
|
support::children(self.syntax())
|
||||||
|
|
|
@ -298,7 +298,7 @@ macro_rules! ast_enums {
|
||||||
|
|
||||||
pub(crate) const AST_SRC: AstSrc = AstSrc {
|
pub(crate) const AST_SRC: AstSrc = AstSrc {
|
||||||
nodes: &ast_nodes! {
|
nodes: &ast_nodes! {
|
||||||
struct SourceFile: ModuleItemOwner, FnDefOwner, AttrsOwner {
|
struct SourceFile: ModuleItemOwner, AttrsOwner {
|
||||||
modules: [Module],
|
modules: [Module],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,7 +364,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
|
||||||
Semi
|
Semi
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ItemList: FnDefOwner, ModuleItemOwner {
|
struct ItemList: ModuleItemOwner {
|
||||||
LCurly,
|
LCurly,
|
||||||
impl_items: [ImplItem],
|
impl_items: [ImplItem],
|
||||||
RCurly
|
RCurly
|
||||||
|
@ -604,14 +604,14 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
|
||||||
struct LifetimeArg { Lifetime }
|
struct LifetimeArg { Lifetime }
|
||||||
struct ConstArg { Literal, Eq, BlockExpr }
|
struct ConstArg { Literal, Eq, BlockExpr }
|
||||||
|
|
||||||
struct MacroItems: ModuleItemOwner, FnDefOwner { }
|
struct MacroItems: ModuleItemOwner{ }
|
||||||
|
|
||||||
struct MacroStmts {
|
struct MacroStmts {
|
||||||
statements: [Stmt],
|
statements: [Stmt],
|
||||||
Expr,
|
Expr,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ExternItemList: FnDefOwner, ModuleItemOwner {
|
struct ExternItemList: ModuleItemOwner {
|
||||||
LCurly,
|
LCurly,
|
||||||
extern_items: [ExternItem],
|
extern_items: [ExternItem],
|
||||||
RCurly
|
RCurly
|
||||||
|
|
Loading…
Reference in a new issue