Skip to content

fix: make inlay param hint hiding heurstic case unsensitive #10806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions crates/ide/src/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,25 @@ fn is_argument_similar_to_param_name(argument: &ast::Expr, param_name: &str) ->
None => return false,
};

// std is honestly too panic happy...
let str_split_at = |str: &str, at| str.is_char_boundary(at).then(|| argument.split_at(at));

let param_name = param_name.trim_start_matches('_');
let argument = argument.trim_start_matches('_');
if argument.strip_prefix(param_name).map_or(false, |s| s.starts_with('_')) {
return true;

match str_split_at(argument, param_name.len()) {
Some((prefix, rest)) if prefix.eq_ignore_ascii_case(param_name) => {
return rest.is_empty() || rest.starts_with('_');
}
_ => (),
}
if argument.strip_suffix(param_name).map_or(false, |s| s.ends_with('_')) {
return true;
match argument.len().checked_sub(param_name.len()).and_then(|at| str_split_at(argument, at)) {
Some((rest, suffix)) if param_name.eq_ignore_ascii_case(suffix) => {
return rest.is_empty() || rest.ends_with('_');
}
_ => (),
}
argument == param_name
false
}

/// Hide the parameter name of a unary function if it is a `_` - prefixed suffix of the function's name, or equal.
Expand All @@ -464,9 +474,13 @@ fn is_param_name_suffix_of_fn_name(
match (callable.n_params(), fn_name) {
(1, Some(function)) => {
function == param_name
|| (function.len() > param_name.len()
&& function.ends_with(param_name)
&& function[..function.len() - param_name.len()].ends_with('_'))
|| function
.len()
.checked_sub(param_name.len())
.and_then(|at| function.is_char_boundary(at).then(|| function.split_at(at)))
.map_or(false, |(prefix, suffix)| {
suffix.eq_ignore_ascii_case(param_name) && prefix.ends_with('_')
})
}
_ => false,
}
Expand Down Expand Up @@ -852,6 +866,9 @@ enum CompletionKind {
fn non_ident_pat((a, b): (u32, u32)) {}

fn main() {
const PARAM: u32 = 0;
foo(PARAM);

check("");

map(0);
Expand Down