Skip to content

Commit a30887f

Browse files
authored
Fix some panics (zed-industries#43233)
Fixes ZED-2NP Fixes ZED-3DP Fixes ZED-3EV Release Notes: - N/A *or* Added/Fixed/Improved ...
1 parent 92b6e8e commit a30887f

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

crates/editor/src/editor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17112,9 +17112,6 @@ impl Editor {
1711217112

1711317113
let multi_buffer = editor.read_with(cx, |editor, _| editor.buffer().clone())?;
1711417114

17115-
let multi_buffer_snapshot =
17116-
multi_buffer.read_with(cx, |multi_buffer, cx| multi_buffer.snapshot(cx))?;
17117-
1711817115
let (locations, current_location_index) =
1711917116
multi_buffer.update(cx, |multi_buffer, cx| {
1712017117
let mut locations = locations
@@ -17134,6 +17131,7 @@ impl Editor {
1713417131
})
1713517132
.collect::<Vec<_>>();
1713617133

17134+
let multi_buffer_snapshot = multi_buffer.snapshot(cx);
1713717135
// There is an O(n) implementation, but given this list will be
1713817136
// small (usually <100 items), the extra O(log(n)) factor isn't
1713917137
// worth the (surprisingly large amount of) extra complexity.

crates/language_tools/src/lsp_log_view.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use gpui::{
55
App, Context, Corner, Entity, EventEmitter, FocusHandle, Focusable, IntoElement, ParentElement,
66
Render, Styled, Subscription, Task, WeakEntity, Window, actions, div,
77
};
8-
use itertools::Itertools;
98
use language::{LanguageServerId, language_settings::SoftWrap};
109
use lsp::{
1110
LanguageServer, LanguageServerBinary, LanguageServerName, LanguageServerSelector, MessageType,
@@ -241,13 +240,15 @@ impl LspLogView {
241240
],
242241
cx,
243242
);
244-
if text.len() > 1024
245-
&& let Some((fold_offset, _)) =
246-
text.char_indices().dropping(1024).next()
247-
&& fold_offset < text.len()
248-
{
243+
if text.len() > 1024 {
244+
let b = editor.buffer().read(cx).as_singleton().unwrap().read(cx);
245+
let fold_offset =
246+
b.as_rope().ceil_char_boundary(last_offset.0 + 1024);
249247
editor.fold_ranges(
250-
vec![last_offset + fold_offset..last_offset + text.len()],
248+
vec![
249+
MultiBufferOffset(fold_offset)
250+
..MultiBufferOffset(b.as_rope().len()),
251+
],
251252
false,
252253
window,
253254
cx,

crates/util/src/paths.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,14 @@ impl PathWithPosition {
625625
pub fn parse_str(s: &str) -> Self {
626626
let trimmed = s.trim();
627627
let path = Path::new(trimmed);
628-
let maybe_file_name_with_row_col = path.file_name().unwrap_or_default().to_string_lossy();
628+
let Some(maybe_file_name_with_row_col) = path.file_name().unwrap_or_default().to_str()
629+
else {
630+
return Self {
631+
path: Path::new(s).to_path_buf(),
632+
row: None,
633+
column: None,
634+
};
635+
};
629636
if maybe_file_name_with_row_col.is_empty() {
630637
return Self {
631638
path: Path::new(s).to_path_buf(),
@@ -640,15 +647,15 @@ impl PathWithPosition {
640647
static SUFFIX_RE: LazyLock<Regex> =
641648
LazyLock::new(|| Regex::new(ROW_COL_CAPTURE_REGEX).unwrap());
642649
match SUFFIX_RE
643-
.captures(&maybe_file_name_with_row_col)
650+
.captures(maybe_file_name_with_row_col)
644651
.map(|caps| caps.extract())
645652
{
646653
Some((_, [file_name, maybe_row, maybe_column])) => {
647654
let row = maybe_row.parse::<u32>().ok();
648655
let column = maybe_column.parse::<u32>().ok();
649656

650-
let suffix_length = maybe_file_name_with_row_col.len() - file_name.len();
651-
let path_without_suffix = &trimmed[..trimmed.len() - suffix_length];
657+
let (_, suffix) = trimmed.split_once(file_name).unwrap();
658+
let path_without_suffix = &trimmed[..trimmed.len() - suffix.len()];
652659

653660
Self {
654661
path: Path::new(path_without_suffix).to_path_buf(),

0 commit comments

Comments
 (0)