mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 05:15:00 +00:00
Show worktree root name for symbol when there are multiple worktrees
Co-Authored-By: Nathan Sobo <nathan@zed.dev> Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
0e4bd4b418
commit
d7db3791d5
2 changed files with 43 additions and 14 deletions
|
@ -453,6 +453,21 @@ impl Project {
|
||||||
.filter_map(move |worktree| worktree.upgrade(cx))
|
.filter_map(move |worktree| worktree.upgrade(cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn strong_worktrees<'a>(
|
||||||
|
&'a self,
|
||||||
|
cx: &'a AppContext,
|
||||||
|
) -> impl 'a + Iterator<Item = ModelHandle<Worktree>> {
|
||||||
|
self.worktrees.iter().filter_map(|worktree| {
|
||||||
|
worktree.upgrade(cx).and_then(|worktree| {
|
||||||
|
if worktree.read(cx).is_weak() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(worktree)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn worktree_for_id(
|
pub fn worktree_for_id(
|
||||||
&self,
|
&self,
|
||||||
id: WorktreeId,
|
id: WorktreeId,
|
||||||
|
|
|
@ -14,6 +14,7 @@ use ordered_float::OrderedFloat;
|
||||||
use postage::watch;
|
use postage::watch;
|
||||||
use project::{Project, Symbol};
|
use project::{Project, Symbol};
|
||||||
use std::{
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
cmp::{self, Reverse},
|
cmp::{self, Reverse},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
@ -277,12 +278,12 @@ impl ProjectSymbolsView {
|
||||||
let view = view.read(cx);
|
let view = view.read(cx);
|
||||||
let start = range.start;
|
let start = range.start;
|
||||||
range.end = cmp::min(range.end, view.matches.len());
|
range.end = cmp::min(range.end, view.matches.len());
|
||||||
items.extend(
|
|
||||||
view.matches[range]
|
let show_worktree_root_name =
|
||||||
.iter()
|
view.project.read(cx).strong_worktrees(cx).count() > 1;
|
||||||
.enumerate()
|
items.extend(view.matches[range].iter().enumerate().map(move |(ix, m)| {
|
||||||
.map(move |(ix, m)| view.render_match(m, start + ix)),
|
view.render_match(m, start + ix, show_worktree_root_name, cx)
|
||||||
);
|
}));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -291,7 +292,13 @@ impl ProjectSymbolsView {
|
||||||
.named("matches")
|
.named("matches")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_match(&self, string_match: &StringMatch, index: usize) -> ElementBox {
|
fn render_match(
|
||||||
|
&self,
|
||||||
|
string_match: &StringMatch,
|
||||||
|
index: usize,
|
||||||
|
show_worktree_root_name: bool,
|
||||||
|
cx: &AppContext,
|
||||||
|
) -> ElementBox {
|
||||||
let settings = self.settings.borrow();
|
let settings = self.settings.borrow();
|
||||||
let style = if index == self.selected_match_index {
|
let style = if index == self.selected_match_index {
|
||||||
&settings.theme.selector.active_item
|
&settings.theme.selector.active_item
|
||||||
|
@ -305,6 +312,19 @@ impl ProjectSymbolsView {
|
||||||
&settings.theme.editor.syntax,
|
&settings.theme.editor.syntax,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut path = symbol.path.to_string_lossy();
|
||||||
|
if show_worktree_root_name {
|
||||||
|
let project = self.project.read(cx);
|
||||||
|
if let Some(worktree) = project.worktree_for_id(symbol.worktree_id, cx) {
|
||||||
|
path = Cow::Owned(format!(
|
||||||
|
"{}{}{}",
|
||||||
|
worktree.read(cx).root_name(),
|
||||||
|
std::path::MAIN_SEPARATOR,
|
||||||
|
path.as_ref()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Flex::column()
|
Flex::column()
|
||||||
.with_child(
|
.with_child(
|
||||||
Text::new(symbol.label.text.clone(), style.label.text.clone())
|
Text::new(symbol.label.text.clone(), style.label.text.clone())
|
||||||
|
@ -317,13 +337,7 @@ impl ProjectSymbolsView {
|
||||||
))
|
))
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
.with_child(
|
.with_child(Label::new(path.to_string(), style.label.clone()).boxed())
|
||||||
Label::new(
|
|
||||||
symbol.path.to_string_lossy().to_string(),
|
|
||||||
style.label.clone(),
|
|
||||||
)
|
|
||||||
.boxed(),
|
|
||||||
)
|
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
.boxed()
|
.boxed()
|
||||||
|
|
Loading…
Reference in a new issue