use rustc_hash::{FxHashMap, FxHashSet};
-use hir::{HasSource, HirDisplay, Module, ModuleDef, Semantics, TypeInfo};
+use hir::{HasSource, HirDisplay, Module, Semantics, TypeInfo};
use ide_db::helpers::FamousDefs;
use ide_db::{
base_db::FileId,
fn gen_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let call: ast::MethodCallExpr = ctx.find_node_at_offset()?;
+ if ctx.sema.resolve_method_call(&call).is_some() {
+ return None;
+ }
+
let fn_name = call.name_ref()?;
let adt = ctx.sema.type_of_expr(&call.receiver()?)?.original().strip_references().as_adt()?;
/// assert_eq!(names, expected);
/// ```
fn deduplicate_arg_names(arg_names: &mut Vec<String>) {
- let arg_name_counts = arg_names.iter().fold(FxHashMap::default(), |mut m, name| {
- *m.entry(name).or_insert(0) += 1;
- m
- });
+ let mut arg_name_counts = FxHashMap::default();
+ for name in arg_names.iter() {
+ *arg_name_counts.entry(name).or_insert(0) += 1;
+ }
let duplicate_arg_names: FxHashSet<String> = arg_name_counts
.into_iter()
.filter(|(_, count)| *count >= 2)
let name = (|| match arg_expr {
ast::Expr::CastExpr(cast_expr) => Some(fn_arg_name(sema, &cast_expr.expr()?)),
expr => {
- let name_ref = expr.syntax().descendants().filter_map(ast::NameRef::cast).last()?;
- if let Some(NameRefClass::Definition(Definition::ModuleDef(
- ModuleDef::Const(_) | ModuleDef::Static(_),
- ))) = NameRefClass::classify(sema, &name_ref)
+ let name_ref = expr
+ .syntax()
+ .descendants()
+ .filter_map(ast::NameRef::cast)
+ .filter(|name| name.ident_token().is_some())
+ .last()?;
+ if let Some(NameRefClass::Definition(Definition::Const(_) | Definition::Static(_))) =
+ NameRefClass::classify(sema, &name_ref)
{
return Some(name_ref.to_string().to_lowercase());
};
foo(a.0);
}
-fn foo(arg0: ()) ${0:-> _} {
+fn foo(a: ()) ${0:-> _} {
todo!()
}
",