Fix panic when deleting just-generated text (cherry-pick #10282) (#10287)

gcp-cherry-pick-bot[bot] , Thorsten Ball , and Conrad created

Cherry-picked Fix panic when deleting just-generated text (#10282)

We ran into a panic when deleting text that was just generated by a code
action.

This fixes it by ensuring we don't run into a 0-minus-1 panic when a
buffer_range is empty.

Release Notes:

- Fixed panic that could occur when deleting generated-by-unsaved text.

Co-authored-by: Conrad <conrad@zed.dev>

Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
Co-authored-by: Conrad <conrad@zed.dev>

Change summary

crates/language/src/buffer.rs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

Detailed changes

crates/language/src/buffer.rs 🔗

@@ -2777,10 +2777,13 @@ impl BufferSnapshot {
                         range.start + self.line_len(start.row as u32) as usize - start.column;
                 }
 
-                buffer_ranges.push((range, node_is_name));
+                if !range.is_empty() {
+                    buffer_ranges.push((range, node_is_name));
+                }
             }
 
             if buffer_ranges.is_empty() {
+                matches.advance();
                 continue;
             }