From a30887f03b89dac712827f9982c399c3f0b8019d Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 21 Nov 2025 11:08:21 +0100 Subject: [PATCH] Fix some panics (#43233) Fixes ZED-2NP Fixes ZED-3DP Fixes ZED-3EV Release Notes: - N/A *or* Added/Fixed/Improved ... --- crates/editor/src/editor.rs | 4 +--- crates/language_tools/src/lsp_log_view.rs | 15 ++++++++------- crates/util/src/paths.rs | 15 +++++++++++---- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index c3da066cfd73cab5b2de610bbf1bc653f7e6d874..30c03c1a8481003aad991c3acf4c6be38bf4b8d5 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -17112,9 +17112,6 @@ impl Editor { let multi_buffer = editor.read_with(cx, |editor, _| editor.buffer().clone())?; - let multi_buffer_snapshot = - multi_buffer.read_with(cx, |multi_buffer, cx| multi_buffer.snapshot(cx))?; - let (locations, current_location_index) = multi_buffer.update(cx, |multi_buffer, cx| { let mut locations = locations @@ -17134,6 +17131,7 @@ impl Editor { }) .collect::>(); + let multi_buffer_snapshot = multi_buffer.snapshot(cx); // There is an O(n) implementation, but given this list will be // small (usually <100 items), the extra O(log(n)) factor isn't // worth the (surprisingly large amount of) extra complexity. diff --git a/crates/language_tools/src/lsp_log_view.rs b/crates/language_tools/src/lsp_log_view.rs index 5f96f8e03048a14f82626ab774a21aab02dc89bf..3f99a3e83413691c3893b184406f6e2569062623 100644 --- a/crates/language_tools/src/lsp_log_view.rs +++ b/crates/language_tools/src/lsp_log_view.rs @@ -5,7 +5,6 @@ use gpui::{ App, Context, Corner, Entity, EventEmitter, FocusHandle, Focusable, IntoElement, ParentElement, Render, Styled, Subscription, Task, WeakEntity, Window, actions, div, }; -use itertools::Itertools; use language::{LanguageServerId, language_settings::SoftWrap}; use lsp::{ LanguageServer, LanguageServerBinary, LanguageServerName, LanguageServerSelector, MessageType, @@ -241,13 +240,15 @@ impl LspLogView { ], cx, ); - if text.len() > 1024 - && let Some((fold_offset, _)) = - text.char_indices().dropping(1024).next() - && fold_offset < text.len() - { + if text.len() > 1024 { + let b = editor.buffer().read(cx).as_singleton().unwrap().read(cx); + let fold_offset = + b.as_rope().ceil_char_boundary(last_offset.0 + 1024); editor.fold_ranges( - vec![last_offset + fold_offset..last_offset + text.len()], + vec![ + MultiBufferOffset(fold_offset) + ..MultiBufferOffset(b.as_rope().len()), + ], false, window, cx, diff --git a/crates/util/src/paths.rs b/crates/util/src/paths.rs index 5813c444af555dc90c65ce6f1584067b446cc79b..74929c6c831bcdb035756483ddbf9b2bc9ad444c 100644 --- a/crates/util/src/paths.rs +++ b/crates/util/src/paths.rs @@ -625,7 +625,14 @@ impl PathWithPosition { pub fn parse_str(s: &str) -> Self { let trimmed = s.trim(); let path = Path::new(trimmed); - let maybe_file_name_with_row_col = path.file_name().unwrap_or_default().to_string_lossy(); + let Some(maybe_file_name_with_row_col) = path.file_name().unwrap_or_default().to_str() + else { + return Self { + path: Path::new(s).to_path_buf(), + row: None, + column: None, + }; + }; if maybe_file_name_with_row_col.is_empty() { return Self { path: Path::new(s).to_path_buf(), @@ -640,15 +647,15 @@ impl PathWithPosition { static SUFFIX_RE: LazyLock = LazyLock::new(|| Regex::new(ROW_COL_CAPTURE_REGEX).unwrap()); match SUFFIX_RE - .captures(&maybe_file_name_with_row_col) + .captures(maybe_file_name_with_row_col) .map(|caps| caps.extract()) { Some((_, [file_name, maybe_row, maybe_column])) => { let row = maybe_row.parse::().ok(); let column = maybe_column.parse::().ok(); - let suffix_length = maybe_file_name_with_row_col.len() - file_name.len(); - let path_without_suffix = &trimmed[..trimmed.len() - suffix_length]; + let (_, suffix) = trimmed.split_once(file_name).unwrap(); + let path_without_suffix = &trimmed[..trimmed.len() - suffix.len()]; Self { path: Path::new(path_without_suffix).to_path_buf(),