Show location of log file when using zed: open log (#13252)

This changes the breadcrumb header from "untitled" to "Last 1000 lines
in <location of log file>".

Reason is that it's been incredibly frustrating not seeing the location
of the log file there and not seeing that it's actually a truncated
version of the logs.

This is one remedy for that.

Other options considered:

1. Opening the actual log file. Turns out that is huge. On Linux right
now it's 5 megabyte after 5 minutes.
2. Opening the file and adding it on the buffer. That is tricky and
weird, because you have to modify the underlying buffer and set the
file, after having to add it to the workspace and getting its entry,
etc.
3. Setting a `display_file_path` on Buffer. That would require also
adding it on `BufferSnapshot` and then threading that through so that it
gets returned by the multi-buffer and then in the editor. And ultimately
this here is a "view concern", so we thought we just add it as such.

So yes, not the best change possible, but it's not that invasive and
makes it clear that it's a view-only concern.

Release Notes:

- N/A

Co-authored-by: Kirill <kirill@zed.dev>
This commit is contained in:
Thorsten Ball 2024-06-19 12:21:28 +02:00 committed by GitHub
parent d4891a62bb
commit 8c4fb34f6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 13 deletions

View File

@ -552,6 +552,7 @@ pub struct Editor {
tasks_update_task: Option<Task<()>>,
previous_search_ranges: Option<Arc<[Range<Anchor>]>>,
file_header_size: u8,
breadcrumb_header: Option<String>,
}
#[derive(Clone)]
@ -1863,6 +1864,7 @@ impl Editor {
tasks_update_task: None,
linked_edit_ranges: Default::default(),
previous_search_ranges: None,
breadcrumb_header: None,
};
this.tasks_update_task = Some(this.refresh_runnables(cx));
this._subscriptions.extend(project_subscriptions);
@ -10505,6 +10507,10 @@ impl Editor {
)
}
pub fn set_breadcrumb_header(&mut self, new_header: String) {
self.breadcrumb_header = Some(new_header);
}
pub fn clear_search_within_ranges(&mut self, cx: &mut ViewContext<Self>) {
self.clear_background_highlights::<SearchWithinRange>(cx);
}

View File

@ -816,22 +816,24 @@ impl Item for Editor {
let buffer = multibuffer.buffer(buffer_id)?;
let buffer = buffer.read(cx);
let filename = buffer
.snapshot()
.resolve_file_path(
cx,
self.project
.as_ref()
.map(|project| project.read(cx).visible_worktrees(cx).count() > 1)
.unwrap_or_default(),
)
.map(|path| path.to_string_lossy().to_string())
.unwrap_or_else(|| "untitled".to_string());
let text = self.breadcrumb_header.clone().unwrap_or_else(|| {
buffer
.snapshot()
.resolve_file_path(
cx,
self.project
.as_ref()
.map(|project| project.read(cx).visible_worktrees(cx).count() > 1)
.unwrap_or_default(),
)
.map(|path| path.to_string_lossy().to_string())
.unwrap_or_else(|| "untitled".to_string())
});
let settings = ThemeSettings::get_global(cx);
let mut breadcrumbs = vec![BreadcrumbText {
text: filename,
text,
highlights: None,
font: Some(settings.buffer_font.clone()),
}];

View File

@ -633,7 +633,14 @@ fn open_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
MultiBuffer::singleton(buffer, cx).with_title("Log".into())
});
let editor = cx.new_view(|cx| {
Editor::for_multibuffer(buffer, Some(project), true, cx)
let mut editor =
Editor::for_multibuffer(buffer, Some(project), true, cx);
editor.set_breadcrumb_header(format!(
"Last {} lines in {}",
MAX_LINES,
paths::log_file().display()
));
editor
});
editor.update(cx, |editor, cx| {