Fix crash when filtering items in Picker (#37929)

Closes #37617

We're already using `get` in a bunch of places, this PR updates the
remaining spots to follow the same pattern. Note that the `ix` we read
in `render_match` can sometimes be stale.

The likely reason is that we run the match-update logic asynchronously
(see
[here](https://github.com/zed-industries/zed/blob/138117e0b15664079f5526cb56168750382b49b9/crates/picker/src/picker.rs#L643)).
That means it's possible to render items after the list's [data
update](https://github.com/zed-industries/zed/blob/138117e0b15664079f5526cb56168750382b49b9/crates/picker/src/picker.rs#L652)
but before the [list
reset](https://github.com/zed-industries/zed/blob/138117e0b15664079f5526cb56168750382b49b9/crates/picker/src/picker.rs#L662),
in which case the `ix` can be greater than that of our updated data.

Release Notes:

- Fixed crash when filtering MCP tools.
This commit is contained in:
Smit Barmase
2025-09-10 23:06:09 +05:30
committed by GitHub
parent c0b583c9ef
commit 22e31a0d41
25 changed files with 31 additions and 43 deletions
+2 -8
View File
@@ -1192,10 +1192,7 @@ impl PickerDelegate for RegistersViewDelegate {
_: &mut Window,
cx: &mut Context<Picker<Self>>,
) -> Option<Self::ListItem> {
let register_match = self
.matches
.get(ix)
.expect("Invalid matches state: no element for index {ix}");
let register_match = self.matches.get(ix)?;
let mut output = String::new();
let mut runs = Vec::new();
@@ -1584,10 +1581,7 @@ impl PickerDelegate for MarksViewDelegate {
_: &mut Window,
cx: &mut Context<Picker<Self>>,
) -> Option<Self::ListItem> {
let mark_match = self
.matches
.get(ix)
.expect("Invalid matches state: no element for index {ix}");
let mark_match = self.matches.get(ix)?;
let mut left_output = String::new();
let mut left_runs = Vec::new();