Skip to content

Commit

Permalink
fix: Don't return inlay hints outside requested range
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Jan 15, 2025
1 parent 9923b00 commit 5ff89d8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
3 changes: 3 additions & 0 deletions crates/ide/src/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ pub(crate) fn inlay_hints(
}
hints(event);
}
if let Some(range_limit) = range_limit {
acc.retain(|hint| range_limit.contains_range(hint.range));
}
acc
}

Expand Down
49 changes: 25 additions & 24 deletions crates/ide/src/inlay_hints/bind_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,36 +391,37 @@ fn main() {
#[test]
fn check_hint_range_limit() {
let fixture = r#"
//- minicore: fn, sized
fn foo() -> impl Fn() { loop {} }
fn foo1() -> impl Fn(f64) { loop {} }
fn foo2() -> impl Fn(f64, f64) { loop {} }
fn foo3() -> impl Fn(f64, f64) -> u32 { loop {} }
fn foo4() -> &'static dyn Fn(f64, f64) -> u32 { loop {} }
fn foo5() -> &'static dyn Fn(&'static dyn Fn(f64, f64) -> u32, f64) -> u32 { loop {} }
fn foo6() -> impl Fn(f64, f64) -> u32 + Sized { loop {} }
fn foo7() -> *const (impl Fn(f64, f64) -> u32 + Sized) { loop {} }
fn main() {
let foo = foo();
let foo = foo1();
let foo = foo2();
// ^^^ impl Fn(f64, f64)
let foo = foo3();
// ^^^ impl Fn(f64, f64) -> u32
let foo = foo4();
let foo = foo5();
let foo = foo6();
let foo = foo7();
}
"#;
//- minicore: fn, sized
fn foo() -> impl Fn() { loop {} }
fn foo1() -> impl Fn(f64) { loop {} }
fn foo2() -> impl Fn(f64, f64) { loop {} }
fn foo3() -> impl Fn(f64, f64) -> u32 { loop {} }
fn foo4() -> &'static dyn Fn(f64, f64) -> u32 { loop {} }
fn foo5() -> &'static dyn Fn(&'static dyn Fn(f64, f64) -> u32, f64) -> u32 { loop {} }
fn foo6() -> impl Fn(f64, f64) -> u32 + Sized { loop {} }
fn foo7() -> *const (impl Fn(f64, f64) -> u32 + Sized) { loop {} }
fn main() {
let foo = foo();
let foo = foo1();
let foo = foo2();
// ^^^ impl Fn(f64, f64)
let foo = foo3();
// ^^^ impl Fn(f64, f64) -> u32
let foo = foo4();
// ^^^ &dyn Fn(f64, f64) -> u32
let foo = foo5();
let foo = foo6();
let foo = foo7();
}
"#;
let (analysis, file_id) = fixture::file(fixture);
let expected = extract_annotations(&analysis.file_text(file_id).unwrap());
let inlay_hints = analysis
.inlay_hints(
&InlayHintsConfig { type_hints: true, ..DISABLED_CONFIG },
file_id,
Some(TextRange::new(TextSize::from(500), TextSize::from(600))),
Some(TextRange::new(TextSize::from(491), TextSize::from(640))),
)
.unwrap();
let actual =
Expand Down

0 comments on commit 5ff89d8

Please sign in to comment.