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:
@@ -454,7 +454,7 @@ impl PickerDelegate for BranchListDelegate {
|
||||
_window: &mut Window,
|
||||
cx: &mut Context<Picker<Self>>,
|
||||
) -> Option<Self::ListItem> {
|
||||
let entry = &self.matches[ix];
|
||||
let entry = &self.matches.get(ix)?;
|
||||
|
||||
let (commit_time, author_name, subject) = entry
|
||||
.branch
|
||||
|
||||
@@ -216,7 +216,7 @@ impl PickerDelegate for PickerPromptDelegate {
|
||||
_window: &mut Window,
|
||||
_cx: &mut Context<Picker<Self>>,
|
||||
) -> Option<Self::ListItem> {
|
||||
let hit = &self.matches[ix];
|
||||
let hit = &self.matches.get(ix)?;
|
||||
let shortened_option = util::truncate_and_trailoff(&hit.string, self.max_match_length);
|
||||
|
||||
Some(
|
||||
|
||||
Reference in New Issue
Block a user