Do not show directories in the InvalidBufferView (#36906)

Follow-up of https://github.com/zed-industries/zed/pull/36764

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2025-08-26 00:16:37 +03:00 committed by GitHub
parent 628a9cd8ea
commit 65de969cc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 50 additions and 86 deletions

View file

@ -1404,7 +1404,7 @@ impl ProjectItem for Editor {
} }
fn for_broken_project_item( fn for_broken_project_item(
abs_path: PathBuf, abs_path: &Path,
is_local: bool, is_local: bool,
e: &anyhow::Error, e: &anyhow::Error,
window: &mut Window, window: &mut Window,

View file

@ -1743,6 +1743,5 @@ pub enum Event {
} }
impl EventEmitter<Event> for LogStore {} impl EventEmitter<Event> for LogStore {}
impl EventEmitter<Event> for LspLogView {}
impl EventEmitter<EditorEvent> for LspLogView {} impl EventEmitter<EditorEvent> for LspLogView {}
impl EventEmitter<SearchEvent> for LspLogView {} impl EventEmitter<SearchEvent> for LspLogView {}

View file

@ -1,4 +1,4 @@
use std::{path::PathBuf, sync::Arc}; use std::{path::Path, sync::Arc};
use gpui::{EventEmitter, FocusHandle, Focusable}; use gpui::{EventEmitter, FocusHandle, Focusable};
use ui::{ use ui::{
@ -12,7 +12,7 @@ use crate::Item;
/// A view to display when a certain buffer fails to open. /// A view to display when a certain buffer fails to open.
pub struct InvalidBufferView { pub struct InvalidBufferView {
/// Which path was attempted to open. /// Which path was attempted to open.
pub abs_path: Arc<PathBuf>, pub abs_path: Arc<Path>,
/// An error message, happened when opening the buffer. /// An error message, happened when opening the buffer.
pub error: SharedString, pub error: SharedString,
is_local: bool, is_local: bool,
@ -21,7 +21,7 @@ pub struct InvalidBufferView {
impl InvalidBufferView { impl InvalidBufferView {
pub fn new( pub fn new(
abs_path: PathBuf, abs_path: &Path,
is_local: bool, is_local: bool,
e: &anyhow::Error, e: &anyhow::Error,
_: &mut Window, _: &mut Window,
@ -29,7 +29,7 @@ impl InvalidBufferView {
) -> Self { ) -> Self {
Self { Self {
is_local, is_local,
abs_path: Arc::new(abs_path), abs_path: Arc::from(abs_path),
error: format!("{e}").into(), error: format!("{e}").into(),
focus_handle: cx.focus_handle(), focus_handle: cx.focus_handle(),
} }
@ -43,7 +43,7 @@ impl Item for InvalidBufferView {
// Ensure we always render at least the filename. // Ensure we always render at least the filename.
detail += 1; detail += 1;
let path = self.abs_path.as_path(); let path = self.abs_path.as_ref();
let mut prefix = path; let mut prefix = path;
while detail > 0 { while detail > 0 {

View file

@ -23,7 +23,7 @@ use std::{
any::{Any, TypeId}, any::{Any, TypeId},
cell::RefCell, cell::RefCell,
ops::Range, ops::Range,
path::PathBuf, path::Path,
rc::Rc, rc::Rc,
sync::Arc, sync::Arc,
time::Duration, time::Duration,
@ -1168,7 +1168,7 @@ pub trait ProjectItem: Item {
/// with the error from that failure as an argument. /// with the error from that failure as an argument.
/// Allows to open an item that can gracefully display and handle errors. /// Allows to open an item that can gracefully display and handle errors.
fn for_broken_project_item( fn for_broken_project_item(
_abs_path: PathBuf, _abs_path: &Path,
_is_local: bool, _is_local: bool,
_e: &anyhow::Error, _e: &anyhow::Error,
_window: &mut Window, _window: &mut Window,

View file

@ -613,48 +613,59 @@ impl ProjectItemRegistry {
self.build_project_item_for_path_fns self.build_project_item_for_path_fns
.push(|project, project_path, window, cx| { .push(|project, project_path, window, cx| {
let project_path = project_path.clone(); let project_path = project_path.clone();
let abs_path = project.read(cx).absolute_path(&project_path, cx); let is_file = project
.read(cx)
.entry_for_path(&project_path, cx)
.is_some_and(|entry| entry.is_file());
let entry_abs_path = project.read(cx).absolute_path(&project_path, cx);
let is_local = project.read(cx).is_local(); let is_local = project.read(cx).is_local();
let project_item = let project_item =
<T::Item as project::ProjectItem>::try_open(project, &project_path, cx)?; <T::Item as project::ProjectItem>::try_open(project, &project_path, cx)?;
let project = project.clone(); let project = project.clone();
Some(window.spawn(cx, async move |cx| match project_item.await { Some(window.spawn(cx, async move |cx| {
Ok(project_item) => { match project_item.await.with_context(|| {
let project_item = project_item; format!(
let project_entry_id: Option<ProjectEntryId> = "opening project path {:?}",
project_item.read_with(cx, project::ProjectItem::entry_id)?; entry_abs_path.as_deref().unwrap_or(&project_path.path)
let build_workspace_item = Box::new( )
|pane: &mut Pane, window: &mut Window, cx: &mut Context<Pane>| { }) {
Box::new(cx.new(|cx| { Ok(project_item) => {
T::for_project_item( let project_item = project_item;
project, let project_entry_id: Option<ProjectEntryId> =
Some(pane), project_item.read_with(cx, project::ProjectItem::entry_id)?;
project_item, let build_workspace_item = Box::new(
window, |pane: &mut Pane, window: &mut Window, cx: &mut Context<Pane>| {
cx, Box::new(cx.new(|cx| {
) T::for_project_item(
})) as Box<dyn ItemHandle> project,
}, Some(pane),
) as Box<_>; project_item,
Ok((project_entry_id, build_workspace_item)) window,
} cx,
Err(e) => match abs_path { )
Some(abs_path) => match cx.update(|window, cx| { })) as Box<dyn ItemHandle>
T::for_broken_project_item(abs_path, is_local, &e, window, cx) },
})? { ) as Box<_>;
Some(broken_project_item_view) => { Ok((project_entry_id, build_workspace_item))
let build_workspace_item = Box::new( }
Err(e) => match entry_abs_path.as_deref().filter(|_| is_file) {
Some(abs_path) => match cx.update(|window, cx| {
T::for_broken_project_item(abs_path, is_local, &e, window, cx)
})? {
Some(broken_project_item_view) => {
let build_workspace_item = Box::new(
move |_: &mut Pane, _: &mut Window, cx: &mut Context<Pane>| { move |_: &mut Pane, _: &mut Window, cx: &mut Context<Pane>| {
cx.new(|_| broken_project_item_view).boxed_clone() cx.new(|_| broken_project_item_view).boxed_clone()
}, },
) )
as Box<_>; as Box<_>;
Ok((None, build_workspace_item)) Ok((None, build_workspace_item))
} }
None => Err(e)?,
},
None => Err(e)?, None => Err(e)?,
}, },
None => Err(e)?, }
},
})) }))
}); });
} }
@ -4011,52 +4022,6 @@ impl Workspace {
maybe_pane_handle maybe_pane_handle
} }
pub fn split_pane_with_item(
&mut self,
pane_to_split: WeakEntity<Pane>,
split_direction: SplitDirection,
from: WeakEntity<Pane>,
item_id_to_move: EntityId,
window: &mut Window,
cx: &mut Context<Self>,
) {
let Some(pane_to_split) = pane_to_split.upgrade() else {
return;
};
let Some(from) = from.upgrade() else {
return;
};
let new_pane = self.add_pane(window, cx);
move_item(&from, &new_pane, item_id_to_move, 0, true, window, cx);
self.center
.split(&pane_to_split, &new_pane, split_direction)
.unwrap();
cx.notify();
}
pub fn split_pane_with_project_entry(
&mut self,
pane_to_split: WeakEntity<Pane>,
split_direction: SplitDirection,
project_entry: ProjectEntryId,
window: &mut Window,
cx: &mut Context<Self>,
) -> Option<Task<Result<()>>> {
let pane_to_split = pane_to_split.upgrade()?;
let new_pane = self.add_pane(window, cx);
self.center
.split(&pane_to_split, &new_pane, split_direction)
.unwrap();
let path = self.project.read(cx).path_for_entry(project_entry, cx)?;
let task = self.open_path(path, Some(new_pane.downgrade()), true, window, cx);
Some(cx.foreground_executor().spawn(async move {
task.await?;
Ok(())
}))
}
pub fn join_all_panes(&mut self, window: &mut Window, cx: &mut Context<Self>) { pub fn join_all_panes(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let active_item = self.active_pane.read(cx).active_item(); let active_item = self.active_pane.read(cx).active_item();
for pane in &self.panes { for pane in &self.panes {