From fa2eaea05afebe3ede81c6c46865788762d60042 Mon Sep 17 00:00:00 2001 From: La1itchauhan Date: Sun, 18 Oct 2026 19:33:41 +0000 Subject: [PATCH 1/2] Add tests for hiding redundant parameter name inlay hints When an argument is a bare variable named the same as its parameter, the hint repeats what the code already says. These tests cover that case, a different-name argument that still gets a hint, and an attribute access like obj.a, which is not treated as a match. --- pyrefly/lib/test/lsp/inlay_hint.rs | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pyrefly/lib/test/lsp/inlay_hint.rs b/pyrefly/lib/test/lsp/inlay_hint.rs index a9f2133479..21e7644c53 100644 --- a/pyrefly/lib/test/lsp/inlay_hint.rs +++ b/pyrefly/lib/test/lsp/inlay_hint.rs @@ -608,6 +608,45 @@ test("a", "b") assert_eq!(parameter_name_hint_labels(code, true), vec!["a= ", "b= "]); } +#[test] +fn test_issue_5105_hide_hint_when_arg_matches_param_name() { + // A matching name is hidden while a different name still shows. + let code = r#" +def foo(a: int, b: int) -> None: + pass + +a = 1 +c = 2 +foo(a, c) +"#; + assert_eq!(parameter_name_hint_labels(code, true), vec!["b= "]); + + // Every argument matching leaves no hints. + let code = r#" +def foo(a: int, b: int) -> None: + pass + +a = 1 +b = 2 +foo(a, b) +"#; + assert_eq!(parameter_name_hint_labels(code, true), Vec::::new()); + + // obj.a against parameter a still shows a=, so only plain names are suppressed. + let code = r#" +class Box: + a: int = 1 + +def foo(a: int, b: int) -> None: + pass + +obj = Box() +c = 2 +foo(obj.a, c) +"#; + assert_eq!(parameter_name_hint_labels(code, true), vec!["a= ", "b= "]); +} + #[test] fn test_parameter_name_hints_with_varargs() { let code = r#" From e59984d7de46370eccccbf76a3e7b888b53dd0e4 Mon Sep 17 00:00:00 2001 From: La1itchauhan Date: Sun, 18 Oct 2026 19:33:52 +0000 Subject: [PATCH 2/2] Hide parameter name inlay hint when argument has the same name Showing `a=` before an argument that is already named `a` is noise. Skip the hint when a positional argument is a plain name identical to its parameter's name. Other expressions, including attribute accesses, still get hints. Fixes #5105 --- pyrefly/lib/lsp/wasm/inlay_hints.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrefly/lib/lsp/wasm/inlay_hints.rs b/pyrefly/lib/lsp/wasm/inlay_hints.rs index 03aae383c4..a35a9b0437 100644 --- a/pyrefly/lib/lsp/wasm/inlay_hints.rs +++ b/pyrefly/lib/lsp/wasm/inlay_hints.rs @@ -589,6 +589,7 @@ impl<'a> Transaction<'a> { && param_match.name.as_str() != "__self" && param_match.name.as_str() != "cls" && param_match.name.as_str() != "_cls" + && !matches!(arg, Expr::Name(name) if name.id == *param_match.name) { param_hints.push(( arg.range().start(),