diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2025-01-15 13:58:07 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-15 13:58:07 +0000 |
| commit | 805598dac3f55703af4af6376ea9570bc1ee6d40 (patch) | |
| tree | db9bb27bab27d6282cf450776c79f074974b4bdb | |
| parent | 6bf145932a5391d37fe92d5eb00750c6de859e1b (diff) | |
| parent | 79f1471cd0ceae668cb756fabea89a5403f6fb88 (diff) | |
| download | rust-805598dac3f55703af4af6376ea9570bc1ee6d40.tar.gz rust-805598dac3f55703af4af6376ea9570bc1ee6d40.zip | |
Merge pull request #18922 from Veykril/push-tmtzukrsnott
fix: Don't return inlay hints outside requested range
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs | 3 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs | 49 |
2 files changed, 28 insertions, 24 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs index 505217cdc1e..6d83a747d76 100644 --- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs +++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs @@ -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 } diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs index f178b4d4f07..ab5464156f0 100644 --- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs +++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs @@ -392,36 +392,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 = |
