Skip to content

Commit 00191d8

Browse files
authored
Merge pull request #19482 from Veykril/push-orrorupvlqpt
fix: Cleanup param name inlay hint filtering
2 parents fb133c8 + 2b382eb commit 00191d8

File tree

7 files changed

+187
-118
lines changed

7 files changed

+187
-118
lines changed

crates/hir/src/attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ fn resolve_impl_trait_item(
260260
// attributes here. Use path resolution directly instead.
261261
//
262262
// FIXME: resolve type aliases (which are not yielded by iterate_path_candidates)
263-
method_resolution::iterate_path_candidates(
263+
_ = method_resolution::iterate_path_candidates(
264264
&canonical,
265265
db,
266266
environment,

crates/hir/src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,10 +2922,14 @@ impl Trait {
29222922
db: &dyn HirDatabase,
29232923
) -> Option<Vec<DynCompatibilityViolation>> {
29242924
let mut violations = vec![];
2925-
hir_ty::dyn_compatibility::dyn_compatibility_with_callback(db, self.id, &mut |violation| {
2926-
violations.push(violation);
2927-
ControlFlow::Continue(())
2928-
});
2925+
_ = hir_ty::dyn_compatibility::dyn_compatibility_with_callback(
2926+
db,
2927+
self.id,
2928+
&mut |violation| {
2929+
violations.push(violation);
2930+
ControlFlow::Continue(())
2931+
},
2932+
);
29292933
violations.is_empty().not().then_some(violations)
29302934
}
29312935

@@ -5514,7 +5518,7 @@ impl Type {
55145518
.generic_def()
55155519
.map_or_else(|| TraitEnvironment::empty(krate.id), |d| db.trait_environment(d));
55165520

5517-
method_resolution::iterate_method_candidates_dyn(
5521+
_ = method_resolution::iterate_method_candidates_dyn(
55185522
&canonical,
55195523
db,
55205524
environment,
@@ -5601,7 +5605,7 @@ impl Type {
56015605
.generic_def()
56025606
.map_or_else(|| TraitEnvironment::empty(krate.id), |d| db.trait_environment(d));
56035607

5604-
method_resolution::iterate_path_candidates(
5608+
_ = method_resolution::iterate_path_candidates(
56055609
&canonical,
56065610
db,
56075611
environment,

crates/ide-assists/src/handlers/extract_function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ impl FunctionBody {
751751
ast::Stmt::Item(_) => (),
752752
ast::Stmt::LetStmt(stmt) => {
753753
if let Some(pat) = stmt.pat() {
754-
walk_pat(&pat, &mut |pat| {
754+
_ = walk_pat(&pat, &mut |pat| {
755755
cb(pat);
756756
std::ops::ControlFlow::<(), ()>::Continue(())
757757
});

crates/ide-db/src/syntax_helpers/node_ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub fn walk_patterns_in_expr(start: &ast::Expr, cb: &mut dyn FnMut(ast::Pat)) {
121121
match ast::Stmt::cast(node.clone()) {
122122
Some(ast::Stmt::LetStmt(l)) => {
123123
if let Some(pat) = l.pat() {
124-
walk_pat(&pat, &mut |pat| {
124+
_ = walk_pat(&pat, &mut |pat| {
125125
cb(pat);
126126
ControlFlow::<(), ()>::Continue(())
127127
});
@@ -159,7 +159,7 @@ pub fn walk_patterns_in_expr(start: &ast::Expr, cb: &mut dyn FnMut(ast::Pat)) {
159159
}
160160
} else if let Some(pat) = ast::Pat::cast(node) {
161161
preorder.skip_subtree();
162-
walk_pat(&pat, &mut |pat| {
162+
_ = walk_pat(&pat, &mut |pat| {
163163
cb(pat);
164164
ControlFlow::<(), ()>::Continue(())
165165
});

crates/ide/src/inlay_hints/generic_param.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
//! Implementation of inlay hints for generic parameters.
2+
use either::Either;
23
use ide_db::{active_parameter::generic_def_for_node, famous_defs::FamousDefs};
34
use syntax::{
45
AstNode,
56
ast::{self, AnyHasGenericArgs, HasGenericArgs, HasName},
67
};
78

89
use crate::{
9-
InlayHint, InlayHintLabel, InlayHintsConfig, InlayKind, inlay_hints::GenericParameterHints,
10+
InlayHint, InlayHintLabel, InlayHintsConfig, InlayKind,
11+
inlay_hints::{GenericParameterHints, param_name},
1012
};
1113

1214
use super::param_name::is_argument_similar_to_param_name;
@@ -62,8 +64,17 @@ pub(crate) fn hints(
6264
let param_name = param.name(sema.db);
6365

6466
let should_hide = {
65-
let argument = get_string_representation(&arg)?;
66-
is_argument_similar_to_param_name(&argument, param_name.as_str())
67+
let param_name = param_name.as_str();
68+
get_segment_representation(&arg).map_or(false, |seg| match seg {
69+
Either::Left(Either::Left(argument)) => {
70+
is_argument_similar_to_param_name(&argument, param_name)
71+
}
72+
Either::Left(Either::Right(argument)) => argument
73+
.segment()
74+
.and_then(|it| it.name_ref())
75+
.is_some_and(|it| it.text().eq_ignore_ascii_case(param_name)),
76+
Either::Right(lifetime) => lifetime.text().eq_ignore_ascii_case(param_name),
77+
})
6778
};
6879

6980
if should_hide {
@@ -111,32 +122,34 @@ pub(crate) fn hints(
111122
Some(())
112123
}
113124

114-
fn get_string_representation(arg: &ast::GenericArg) -> Option<String> {
125+
fn get_segment_representation(
126+
arg: &ast::GenericArg,
127+
) -> Option<Either<Either<Vec<ast::NameRef>, ast::Path>, ast::Lifetime>> {
115128
return match arg {
116129
ast::GenericArg::AssocTypeArg(_) => None,
117-
ast::GenericArg::ConstArg(const_arg) => Some(const_arg.to_string()),
130+
ast::GenericArg::ConstArg(const_arg) => {
131+
param_name::get_segment_representation(&const_arg.expr()?).map(Either::Left)
132+
}
118133
ast::GenericArg::LifetimeArg(lifetime_arg) => {
119134
let lifetime = lifetime_arg.lifetime()?;
120-
Some(lifetime.to_string())
135+
Some(Either::Right(lifetime))
121136
}
122137
ast::GenericArg::TypeArg(type_arg) => {
123138
let ty = type_arg.ty()?;
124-
Some(
125-
type_path_segment(&ty)
126-
.map_or_else(|| type_arg.to_string(), |segment| segment.to_string()),
127-
)
139+
type_path(&ty).map(Either::Right).map(Either::Left)
128140
}
129141
};
130142

131-
fn type_path_segment(ty: &ast::Type) -> Option<ast::PathSegment> {
143+
fn type_path(ty: &ast::Type) -> Option<ast::Path> {
132144
match ty {
133-
ast::Type::ArrayType(it) => type_path_segment(&it.ty()?),
134-
ast::Type::ForType(it) => type_path_segment(&it.ty()?),
135-
ast::Type::ParenType(it) => type_path_segment(&it.ty()?),
136-
ast::Type::PathType(path_type) => path_type.path()?.segment(),
137-
ast::Type::PtrType(it) => type_path_segment(&it.ty()?),
138-
ast::Type::RefType(it) => type_path_segment(&it.ty()?),
139-
ast::Type::SliceType(it) => type_path_segment(&it.ty()?),
145+
ast::Type::ArrayType(it) => type_path(&it.ty()?),
146+
ast::Type::ForType(it) => type_path(&it.ty()?),
147+
ast::Type::ParenType(it) => type_path(&it.ty()?),
148+
ast::Type::PathType(path_type) => path_type.path(),
149+
ast::Type::PtrType(it) => type_path(&it.ty()?),
150+
ast::Type::RefType(it) => type_path(&it.ty()?),
151+
ast::Type::SliceType(it) => type_path(&it.ty()?),
152+
ast::Type::MacroType(macro_type) => macro_type.macro_call()?.path(),
140153
_ => None,
141154
}
142155
}

0 commit comments

Comments
 (0)