Merge branch 'main' into fix-worktree-drag-reorder

This commit is contained in:
Elliot Thomas 2026-05-05 17:09:25 +01:00 committed by GitHub
commit 15117d76dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 621 additions and 610 deletions

View file

@ -1037,9 +1037,7 @@ async fn active_diagnostics_dismiss_after_invalidation(cx: &mut TestAppContext)
cx.update_editor(|editor, window, cx| {
editor.go_to_diagnostic(&GoToDiagnostic::default(), window, cx);
assert_eq!(
editor
.active_diagnostic_group()
.map(|diagnostics_group| diagnostics_group.active_message.as_str()),
editor.active_diagnostic_message(),
Some(message),
"Should have a diagnostics group activated"
);
@ -1069,7 +1067,7 @@ async fn active_diagnostics_dismiss_after_invalidation(cx: &mut TestAppContext)
});
cx.run_until_parked();
cx.update_editor(|editor, _, _| {
assert_eq!(editor.active_diagnostic_group(), None);
assert_eq!(editor.active_diagnostic_message(), None);
});
cx.assert_editor_state(indoc! {"
fn func(abcˇ def: i32) -> u32 {
@ -1078,7 +1076,7 @@ async fn active_diagnostics_dismiss_after_invalidation(cx: &mut TestAppContext)
cx.update_editor(|editor, window, cx| {
editor.go_to_diagnostic(&GoToDiagnostic::default(), window, cx);
assert_eq!(editor.active_diagnostic_group(), None);
assert_eq!(editor.active_diagnostic_message(), None);
});
cx.assert_editor_state(indoc! {"
fn func(abcˇ def: i32) -> u32 {

View file

@ -94,7 +94,7 @@ pub use wrap_map::{WrapPoint, WrapRow, WrapSnapshot};
use collections::{HashMap, HashSet, IndexSet};
use gpui::{
App, Context, Entity, EntityId, Font, HighlightStyle, LineLayout, Pixels, UnderlineStyle,
App, Context, Entity, EntityId, Font, HighlightStyle, Hsla, LineLayout, Pixels, UnderlineStyle,
WeakEntity,
};
use language::{
@ -113,6 +113,7 @@ use settings::Settings;
use smallvec::SmallVec;
use sum_tree::{Bias, TreeMap};
use text::{BufferId, LineIndent, Patch};
use theme::StatusColors;
use ui::{SharedString, px};
use unicode_segmentation::UnicodeSegmentation;
use ztracing::instrument;
@ -1848,8 +1849,7 @@ impl DisplaySnapshot {
&& editor_style.show_underlines
&& !(chunk.is_unnecessary && severity > lsp::DiagnosticSeverity::WARNING))
.then(|| {
let diagnostic_color =
super::diagnostic_style(severity, &editor_style.status);
let diagnostic_color = diagnostic_style(severity, &editor_style.status);
UnderlineStyle {
color: Some(diagnostic_color),
thickness: 1.0.into(),
@ -2414,6 +2414,16 @@ impl DisplaySnapshot {
}
}
fn diagnostic_style(severity: lsp::DiagnosticSeverity, colors: &StatusColors) -> Hsla {
match severity {
lsp::DiagnosticSeverity::ERROR => colors.error,
lsp::DiagnosticSeverity::WARNING => colors.warning,
lsp::DiagnosticSeverity::INFORMATION => colors.info,
lsp::DiagnosticSeverity::HINT => colors.hint,
_ => colors.ignored,
}
}
impl std::ops::Deref for DisplaySnapshot {
type Target = BlockSnapshot;

View file

@ -57,7 +57,12 @@ mod signature_help;
#[cfg(any(test, feature = "test-support"))]
pub mod test;
#[path = "editor/diagnostics.rs"]
mod diagnostics;
pub(crate) use actions::*;
use diagnostics::{ActiveDiagnostic, GlobalDiagnosticRenderer, InlineDiagnostic};
pub use diagnostics::{DiagnosticRenderer, set_diagnostic_renderer};
pub use display_map::{
ChunkRenderer, ChunkRendererContext, DisplayPoint, FoldPlaceholder, HighlightKey,
NavigationOverlayKey, SemanticTokenHighlight,
@ -390,48 +395,6 @@ pub fn set_blame_renderer(renderer: impl BlameRenderer + 'static, cx: &mut App)
cx.set_global(GlobalBlameRenderer(Arc::new(renderer)));
}
pub trait DiagnosticRenderer {
fn render_group(
&self,
diagnostic_group: Vec<DiagnosticEntryRef<'_, Point>>,
buffer_id: BufferId,
snapshot: EditorSnapshot,
editor: WeakEntity<Editor>,
language_registry: Option<Arc<LanguageRegistry>>,
cx: &mut App,
) -> Vec<BlockProperties<Anchor>>;
fn render_hover(
&self,
diagnostic_group: Vec<DiagnosticEntryRef<'_, Point>>,
range: Range<Point>,
buffer_id: BufferId,
language_registry: Option<Arc<LanguageRegistry>>,
cx: &mut App,
) -> Option<Entity<markdown::Markdown>>;
fn open_link(
&self,
editor: &mut Editor,
link: SharedString,
window: &mut Window,
cx: &mut Context<Editor>,
);
}
pub(crate) struct GlobalDiagnosticRenderer(pub Arc<dyn DiagnosticRenderer>);
impl GlobalDiagnosticRenderer {
fn global(cx: &App) -> Option<Arc<dyn DiagnosticRenderer>> {
cx.try_global::<Self>().map(|g| g.0.clone())
}
}
impl gpui::Global for GlobalDiagnosticRenderer {}
pub fn set_diagnostic_renderer(renderer: impl DiagnosticRenderer + 'static, cx: &mut App) {
cx.set_global(GlobalDiagnosticRenderer(Arc::new(renderer)));
}
pub struct SearchWithinRange;
trait InvalidationRegion {
@ -678,15 +641,6 @@ enum EditPredictionSettings {
},
}
#[derive(Debug, Clone)]
struct InlineDiagnostic {
message: SharedString,
group_id: usize,
is_primary: bool,
start: Point,
severity: lsp::DiagnosticSeverity,
}
pub enum MenuEditPredictionsPolicy {
Never,
ByProvider,
@ -1771,22 +1725,6 @@ struct RegisteredEditPredictionDelegate {
_subscription: Subscription,
}
#[derive(Debug, PartialEq, Eq)]
pub struct ActiveDiagnosticGroup {
pub active_range: Range<Anchor>,
pub active_message: String,
pub group_id: usize,
pub blocks: HashSet<CustomBlockId>,
}
#[derive(Debug, PartialEq, Eq)]
pub(crate) enum ActiveDiagnostic {
None,
All,
Group(ActiveDiagnosticGroup),
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ClipboardSelection {
/// The number of bytes in this selection.
@ -4713,7 +4651,7 @@ impl Editor {
dismissed = true;
}
if self.mode.is_full() && matches!(self.active_diagnostics, ActiveDiagnostic::Group(_)) {
if self.mode.is_full() && self.has_active_diagnostic_group() {
self.dismiss_diagnostics(cx);
dismissed = true;
}
@ -18249,123 +18187,6 @@ impl Editor {
);
}
pub fn go_to_diagnostic(
&mut self,
action: &GoToDiagnostic,
window: &mut Window,
cx: &mut Context<Self>,
) {
if !self.diagnostics_enabled() {
return;
}
self.go_to_diagnostic_impl(Direction::Next, action.severity, window, cx)
}
pub fn go_to_prev_diagnostic(
&mut self,
action: &GoToPreviousDiagnostic,
window: &mut Window,
cx: &mut Context<Self>,
) {
if !self.diagnostics_enabled() {
return;
}
self.go_to_diagnostic_impl(Direction::Prev, action.severity, window, cx)
}
pub fn go_to_diagnostic_impl(
&mut self,
direction: Direction,
severity: GoToDiagnosticSeverityFilter,
window: &mut Window,
cx: &mut Context<Self>,
) {
let buffer = self.buffer.read(cx).snapshot(cx);
let selection = self
.selections
.newest::<MultiBufferOffset>(&self.display_snapshot(cx));
let mut active_group_id = None;
if let ActiveDiagnostic::Group(active_group) = &self.active_diagnostics
&& active_group.active_range.start.to_offset(&buffer) == selection.start
{
active_group_id = Some(active_group.group_id);
}
fn filtered<'a>(
severity: GoToDiagnosticSeverityFilter,
diagnostics: impl Iterator<Item = DiagnosticEntryRef<'a, MultiBufferOffset>>,
) -> impl Iterator<Item = DiagnosticEntryRef<'a, MultiBufferOffset>> {
diagnostics
.filter(move |entry| severity.matches(entry.diagnostic.severity))
.filter(|entry| entry.range.start != entry.range.end)
.filter(|entry| !entry.diagnostic.is_unnecessary)
}
let before = filtered(
severity,
buffer
.diagnostics_in_range(MultiBufferOffset(0)..selection.start)
.filter(|entry| entry.range.start <= selection.start),
);
let after = filtered(
severity,
buffer
.diagnostics_in_range(selection.start..buffer.len())
.filter(|entry| entry.range.start >= selection.start),
);
let mut found: Option<DiagnosticEntryRef<MultiBufferOffset>> = None;
if direction == Direction::Prev {
'outer: for prev_diagnostics in [before.collect::<Vec<_>>(), after.collect::<Vec<_>>()]
{
for diagnostic in prev_diagnostics.into_iter().rev() {
if diagnostic.range.start != selection.start
|| active_group_id
.is_some_and(|active| diagnostic.diagnostic.group_id < active)
{
found = Some(diagnostic);
break 'outer;
}
}
}
} else {
for diagnostic in after.chain(before) {
if diagnostic.range.start != selection.start
|| active_group_id.is_some_and(|active| diagnostic.diagnostic.group_id > active)
{
found = Some(diagnostic);
break;
}
}
}
let Some(next_diagnostic) = found else {
return;
};
let next_diagnostic_start = buffer.anchor_after(next_diagnostic.range.start);
let Some((buffer_anchor, _)) = buffer.anchor_to_buffer_anchor(next_diagnostic_start) else {
return;
};
let buffer_id = buffer_anchor.buffer_id;
let snapshot = self.snapshot(window, cx);
if snapshot.intersects_fold(next_diagnostic.range.start) {
self.unfold_ranges(
std::slice::from_ref(&next_diagnostic.range),
true,
false,
cx,
);
}
self.change_selections(Default::default(), window, cx, |s| {
s.select_ranges(vec![
next_diagnostic.range.start..next_diagnostic.range.start,
])
});
self.activate_diagnostics(buffer_id, next_diagnostic, window, cx);
self.refresh_edit_prediction(false, true, window, cx);
}
pub fn go_to_next_hunk(&mut self, _: &GoToHunk, window: &mut Window, cx: &mut Context<Self>) {
let snapshot = self.snapshot(window, cx);
let selection = self.selections.newest::<Point>(&self.display_snapshot(cx));
@ -20303,183 +20124,10 @@ impl Editor {
window.show_character_palette();
}
fn refresh_active_diagnostics(&mut self, cx: &mut Context<Editor>) {
if !self.diagnostics_enabled() {
return;
}
if let ActiveDiagnostic::Group(active_diagnostics) = &mut self.active_diagnostics {
let buffer = self.buffer.read(cx).snapshot(cx);
let primary_range_start = active_diagnostics.active_range.start.to_offset(&buffer);
let primary_range_end = active_diagnostics.active_range.end.to_offset(&buffer);
let is_valid = buffer
.diagnostics_in_range::<MultiBufferOffset>(primary_range_start..primary_range_end)
.any(|entry| {
entry.diagnostic.is_primary
&& !entry.range.is_empty()
&& entry.range.start == primary_range_start
&& entry.diagnostic.message == active_diagnostics.active_message
});
if !is_valid {
self.dismiss_diagnostics(cx);
}
}
}
pub fn active_diagnostic_group(&self) -> Option<&ActiveDiagnosticGroup> {
match &self.active_diagnostics {
ActiveDiagnostic::Group(group) => Some(group),
_ => None,
}
}
pub fn set_all_diagnostics_active(&mut self, cx: &mut Context<Self>) {
if !self.diagnostics_enabled() {
return;
}
self.dismiss_diagnostics(cx);
self.active_diagnostics = ActiveDiagnostic::All;
}
fn activate_diagnostics(
&mut self,
buffer_id: BufferId,
diagnostic: DiagnosticEntryRef<'_, MultiBufferOffset>,
window: &mut Window,
cx: &mut Context<Self>,
) {
if !self.diagnostics_enabled() || matches!(self.active_diagnostics, ActiveDiagnostic::All) {
return;
}
self.dismiss_diagnostics(cx);
let snapshot = self.snapshot(window, cx);
let buffer = self.buffer.read(cx).snapshot(cx);
let Some(renderer) = GlobalDiagnosticRenderer::global(cx) else {
return;
};
let diagnostic_group = buffer
.diagnostic_group(buffer_id, diagnostic.diagnostic.group_id)
.collect::<Vec<_>>();
let language_registry = self
.project()
.map(|project| project.read(cx).languages().clone());
let blocks = renderer.render_group(
diagnostic_group,
buffer_id,
snapshot,
cx.weak_entity(),
language_registry,
cx,
);
let blocks = self.display_map.update(cx, |display_map, cx| {
display_map.insert_blocks(blocks, cx).into_iter().collect()
});
self.active_diagnostics = ActiveDiagnostic::Group(ActiveDiagnosticGroup {
active_range: buffer.anchor_before(diagnostic.range.start)
..buffer.anchor_after(diagnostic.range.end),
active_message: diagnostic.diagnostic.message.clone(),
group_id: diagnostic.diagnostic.group_id,
blocks,
});
cx.notify();
}
fn dismiss_diagnostics(&mut self, cx: &mut Context<Self>) {
if matches!(self.active_diagnostics, ActiveDiagnostic::All) {
return;
};
let prev = mem::replace(&mut self.active_diagnostics, ActiveDiagnostic::None);
if let ActiveDiagnostic::Group(group) = prev {
self.display_map.update(cx, |display_map, cx| {
display_map.remove_blocks(group.blocks, cx);
});
cx.notify();
}
}
/// Disable inline diagnostics rendering for this editor.
pub fn disable_inline_diagnostics(&mut self) {
self.inline_diagnostics_enabled = false;
self.inline_diagnostics_update = Task::ready(());
self.inline_diagnostics.clear();
}
pub fn disable_diagnostics(&mut self, cx: &mut Context<Self>) {
self.diagnostics_enabled = false;
self.dismiss_diagnostics(cx);
self.inline_diagnostics_update = Task::ready(());
self.inline_diagnostics.clear();
}
pub fn disable_word_completions(&mut self) {
self.word_completions_enabled = false;
}
pub fn diagnostics_enabled(&self) -> bool {
self.diagnostics_enabled && self.lsp_data_enabled()
}
pub fn inline_diagnostics_enabled(&self) -> bool {
self.inline_diagnostics_enabled && self.diagnostics_enabled()
}
pub fn show_inline_diagnostics(&self) -> bool {
self.show_inline_diagnostics
}
pub fn toggle_inline_diagnostics(
&mut self,
_: &ToggleInlineDiagnostics,
window: &mut Window,
cx: &mut Context<Editor>,
) {
self.show_inline_diagnostics = !self.show_inline_diagnostics;
self.refresh_inline_diagnostics(false, window, cx);
}
pub fn set_max_diagnostics_severity(&mut self, severity: DiagnosticSeverity, cx: &mut App) {
self.diagnostics_max_severity = severity;
self.display_map.update(cx, |display_map, _| {
display_map.diagnostics_max_severity = self.diagnostics_max_severity;
});
}
pub fn toggle_diagnostics(
&mut self,
_: &ToggleDiagnostics,
window: &mut Window,
cx: &mut Context<Editor>,
) {
let diagnostics_enabled =
self.diagnostics_enabled() && self.diagnostics_max_severity != DiagnosticSeverity::Off;
self.diagnostics_enabled = !diagnostics_enabled;
let new_severity = if self.diagnostics_enabled {
EditorSettings::get_global(cx)
.diagnostics_max_severity
.filter(|severity| severity != &DiagnosticSeverity::Off)
.unwrap_or(DiagnosticSeverity::Hint)
} else {
DiagnosticSeverity::Off
};
self.set_max_diagnostics_severity(new_severity, cx);
if self.diagnostics_enabled {
self.active_diagnostics = ActiveDiagnostic::None;
self.inline_diagnostics_update = Task::ready(());
self.inline_diagnostics.clear();
} else {
self.refresh_inline_diagnostics(false, window, cx);
}
cx.notify();
}
pub fn toggle_minimap(
&mut self,
_: &ToggleMinimap,
@ -20491,135 +20139,6 @@ impl Editor {
}
}
fn refresh_inline_diagnostics(
&mut self,
debounce: bool,
window: &mut Window,
cx: &mut Context<Self>,
) {
let max_severity = ProjectSettings::get_global(cx)
.diagnostics
.inline
.max_severity
.unwrap_or(self.diagnostics_max_severity);
if !self.inline_diagnostics_enabled()
|| !self.diagnostics_enabled()
|| !self.show_inline_diagnostics
|| max_severity == DiagnosticSeverity::Off
{
self.inline_diagnostics_update = Task::ready(());
self.inline_diagnostics.clear();
return;
}
let debounce_ms = ProjectSettings::get_global(cx)
.diagnostics
.inline
.update_debounce_ms;
let debounce = if debounce && debounce_ms > 0 {
Some(Duration::from_millis(debounce_ms))
} else {
None
};
self.inline_diagnostics_update = cx.spawn_in(window, async move |editor, cx| {
if let Some(debounce) = debounce {
cx.background_executor().timer(debounce).await;
}
let Some(snapshot) = editor.upgrade().map(|editor| {
editor.update(cx, |editor, cx| editor.buffer().read(cx).snapshot(cx))
}) else {
return;
};
let new_inline_diagnostics = cx
.background_spawn(async move {
let mut inline_diagnostics = Vec::<(Anchor, InlineDiagnostic)>::new();
for diagnostic_entry in
snapshot.diagnostics_in_range(MultiBufferOffset(0)..snapshot.len())
{
let message = diagnostic_entry
.diagnostic
.message
.split_once('\n')
.map(|(line, _)| line)
.map(SharedString::new)
.unwrap_or_else(|| {
SharedString::new(&*diagnostic_entry.diagnostic.message)
});
let start_anchor = snapshot.anchor_before(diagnostic_entry.range.start);
let (Ok(i) | Err(i)) = inline_diagnostics
.binary_search_by(|(probe, _)| probe.cmp(&start_anchor, &snapshot));
inline_diagnostics.insert(
i,
(
start_anchor,
InlineDiagnostic {
message,
group_id: diagnostic_entry.diagnostic.group_id,
start: diagnostic_entry.range.start.to_point(&snapshot),
is_primary: diagnostic_entry.diagnostic.is_primary,
severity: diagnostic_entry.diagnostic.severity,
},
),
);
}
inline_diagnostics
})
.await;
editor
.update(cx, |editor, cx| {
editor.inline_diagnostics = new_inline_diagnostics;
cx.notify();
})
.ok();
});
}
fn pull_diagnostics(
&mut self,
buffer_id: BufferId,
_window: &Window,
cx: &mut Context<Self>,
) -> Option<()> {
// `ActiveDiagnostic::All` is a special mode where editor's diagnostics are managed by the external view,
// skip any LSP updates for it.
if self.active_diagnostics == ActiveDiagnostic::All || !self.diagnostics_enabled() {
return None;
}
let pull_diagnostics_settings = ProjectSettings::get_global(cx)
.diagnostics
.lsp_pull_diagnostics;
if !pull_diagnostics_settings.enabled {
return None;
}
let debounce = Duration::from_millis(pull_diagnostics_settings.debounce_ms);
let project = self.project()?.downgrade();
let buffer = self.buffer().read(cx).buffer(buffer_id)?;
self.pull_diagnostics_task = cx.spawn(async move |_, cx| {
cx.background_executor().timer(debounce).await;
if let Ok(task) = project.update(cx, |project, cx| {
project.lsp_store().update(cx, |lsp_store, cx| {
lsp_store.pull_diagnostics_for_buffer(buffer, cx)
})
}) {
task.await.log_err();
}
project
.update(cx, |project, cx| {
project.lsp_store().update(cx, |lsp_store, cx| {
lsp_store.pull_document_diagnostics_for_buffer_edit(buffer_id, cx);
})
})
.log_err();
});
Some(())
}
pub fn set_selections_from_remote(
&mut self,
selections: Vec<Selection<Anchor>>,
@ -25098,16 +24617,6 @@ impl Editor {
};
}
fn update_diagnostics_state(&mut self, window: &mut Window, cx: &mut Context<'_, Editor>) {
if !self.diagnostics_enabled() {
return;
}
self.refresh_active_diagnostics(cx);
self.refresh_inline_diagnostics(true, window, cx);
self.scrollbar_marker_state.dirty = true;
cx.notify();
}
pub fn start_temporary_diff_override(&mut self) {
self.load_diff_task.take();
self.temporary_diff_override = true;
@ -29637,16 +29146,6 @@ fn edit_prediction_fallback_text(edits: &[(Range<Anchor>, Arc<str>)], cx: &App)
}
}
pub fn diagnostic_style(severity: lsp::DiagnosticSeverity, colors: &StatusColors) -> Hsla {
match severity {
lsp::DiagnosticSeverity::ERROR => colors.error,
lsp::DiagnosticSeverity::WARNING => colors.warning,
lsp::DiagnosticSeverity::INFORMATION => colors.info,
lsp::DiagnosticSeverity::HINT => colors.hint,
_ => colors.ignored,
}
}
pub fn styled_runs_for_code_label<'a>(
label: &'a CodeLabel,
syntax_theme: &'a theme::SyntaxTheme,

View file

@ -0,0 +1,519 @@
use super::*;
pub trait DiagnosticRenderer {
fn render_group(
&self,
diagnostic_group: Vec<DiagnosticEntryRef<'_, Point>>,
buffer_id: BufferId,
snapshot: EditorSnapshot,
editor: WeakEntity<Editor>,
language_registry: Option<Arc<LanguageRegistry>>,
cx: &mut App,
) -> Vec<BlockProperties<Anchor>>;
fn render_hover(
&self,
diagnostic_group: Vec<DiagnosticEntryRef<'_, Point>>,
range: Range<Point>,
buffer_id: BufferId,
language_registry: Option<Arc<LanguageRegistry>>,
cx: &mut App,
) -> Option<Entity<markdown::Markdown>>;
fn open_link(
&self,
editor: &mut Editor,
link: SharedString,
window: &mut Window,
cx: &mut Context<Editor>,
);
}
pub fn set_diagnostic_renderer(renderer: impl DiagnosticRenderer + 'static, cx: &mut App) {
cx.set_global(GlobalDiagnosticRenderer(Arc::new(renderer)));
}
pub(super) struct GlobalDiagnosticRenderer(Arc<dyn DiagnosticRenderer>);
impl GlobalDiagnosticRenderer {
pub(super) fn global(cx: &App) -> Option<Arc<dyn DiagnosticRenderer>> {
cx.try_global::<Self>().map(|g| g.0.clone())
}
}
impl gpui::Global for GlobalDiagnosticRenderer {}
#[derive(Debug, Clone)]
pub(super) struct InlineDiagnostic {
pub(super) message: SharedString,
pub(super) group_id: usize,
pub(super) is_primary: bool,
pub(super) start: Point,
pub(super) severity: lsp::DiagnosticSeverity,
}
#[derive(Debug, PartialEq, Eq)]
pub(super) struct ActiveDiagnosticGroup {
active_range: Range<Anchor>,
active_message: String,
group_id: usize,
blocks: HashSet<CustomBlockId>,
}
#[derive(Debug, PartialEq, Eq)]
pub(super) enum ActiveDiagnostic {
None,
All,
Group(ActiveDiagnosticGroup),
}
impl Editor {
pub fn go_to_diagnostic(
&mut self,
action: &GoToDiagnostic,
window: &mut Window,
cx: &mut Context<Self>,
) {
if !self.diagnostics_enabled() {
return;
}
self.go_to_diagnostic_impl(Direction::Next, action.severity, window, cx)
}
pub fn go_to_prev_diagnostic(
&mut self,
action: &GoToPreviousDiagnostic,
window: &mut Window,
cx: &mut Context<Self>,
) {
if !self.diagnostics_enabled() {
return;
}
self.go_to_diagnostic_impl(Direction::Prev, action.severity, window, cx)
}
pub fn go_to_diagnostic_impl(
&mut self,
direction: Direction,
severity: GoToDiagnosticSeverityFilter,
window: &mut Window,
cx: &mut Context<Self>,
) {
let buffer = self.buffer.read(cx).snapshot(cx);
let selection = self
.selections
.newest::<MultiBufferOffset>(&self.display_snapshot(cx));
let mut active_group_id = None;
if let ActiveDiagnostic::Group(active_group) = &self.active_diagnostics
&& active_group.active_range.start.to_offset(&buffer) == selection.start
{
active_group_id = Some(active_group.group_id);
}
fn filtered<'a>(
severity: GoToDiagnosticSeverityFilter,
diagnostics: impl Iterator<Item = DiagnosticEntryRef<'a, MultiBufferOffset>>,
) -> impl Iterator<Item = DiagnosticEntryRef<'a, MultiBufferOffset>> {
diagnostics
.filter(move |entry| severity.matches(entry.diagnostic.severity))
.filter(|entry| entry.range.start != entry.range.end)
.filter(|entry| !entry.diagnostic.is_unnecessary)
}
let before = filtered(
severity,
buffer
.diagnostics_in_range(MultiBufferOffset(0)..selection.start)
.filter(|entry| entry.range.start <= selection.start),
);
let after = filtered(
severity,
buffer
.diagnostics_in_range(selection.start..buffer.len())
.filter(|entry| entry.range.start >= selection.start),
);
let mut found: Option<DiagnosticEntryRef<MultiBufferOffset>> = None;
if direction == Direction::Prev {
'outer: for prev_diagnostics in [before.collect::<Vec<_>>(), after.collect::<Vec<_>>()]
{
for diagnostic in prev_diagnostics.into_iter().rev() {
if diagnostic.range.start != selection.start
|| active_group_id
.is_some_and(|active| diagnostic.diagnostic.group_id < active)
{
found = Some(diagnostic);
break 'outer;
}
}
}
} else {
for diagnostic in after.chain(before) {
if diagnostic.range.start != selection.start
|| active_group_id.is_some_and(|active| diagnostic.diagnostic.group_id > active)
{
found = Some(diagnostic);
break;
}
}
}
let Some(next_diagnostic) = found else {
return;
};
let next_diagnostic_start = buffer.anchor_after(next_diagnostic.range.start);
let Some((buffer_anchor, _)) = buffer.anchor_to_buffer_anchor(next_diagnostic_start) else {
return;
};
let buffer_id = buffer_anchor.buffer_id;
let snapshot = self.snapshot(window, cx);
if snapshot.intersects_fold(next_diagnostic.range.start) {
self.unfold_ranges(
std::slice::from_ref(&next_diagnostic.range),
true,
false,
cx,
);
}
self.change_selections(Default::default(), window, cx, |s| {
s.select_ranges(vec![
next_diagnostic.range.start..next_diagnostic.range.start,
])
});
self.activate_diagnostics(buffer_id, next_diagnostic, window, cx);
self.refresh_edit_prediction(false, true, window, cx);
}
#[cfg(any(test, feature = "test-support"))]
pub fn active_diagnostic_message(&self) -> Option<&str> {
match &self.active_diagnostics {
ActiveDiagnostic::Group(group) => Some(group.active_message.as_str()),
_ => None,
}
}
pub fn set_all_diagnostics_active(&mut self, cx: &mut Context<Self>) {
if !self.diagnostics_enabled() {
return;
}
self.dismiss_diagnostics(cx);
self.active_diagnostics = ActiveDiagnostic::All;
}
/// Disable inline diagnostics rendering for this editor.
pub fn disable_inline_diagnostics(&mut self) {
self.inline_diagnostics_enabled = false;
self.inline_diagnostics_update = Task::ready(());
self.inline_diagnostics.clear();
}
pub fn disable_diagnostics(&mut self, cx: &mut Context<Self>) {
self.diagnostics_enabled = false;
self.dismiss_diagnostics(cx);
self.inline_diagnostics_update = Task::ready(());
self.inline_diagnostics.clear();
}
pub fn diagnostics_enabled(&self) -> bool {
self.diagnostics_enabled && self.lsp_data_enabled()
}
pub fn inline_diagnostics_enabled(&self) -> bool {
self.inline_diagnostics_enabled && self.diagnostics_enabled()
}
pub fn show_inline_diagnostics(&self) -> bool {
self.show_inline_diagnostics
}
pub fn toggle_inline_diagnostics(
&mut self,
_: &ToggleInlineDiagnostics,
window: &mut Window,
cx: &mut Context<Editor>,
) {
self.show_inline_diagnostics = !self.show_inline_diagnostics;
self.refresh_inline_diagnostics(false, window, cx);
}
pub fn set_max_diagnostics_severity(&mut self, severity: DiagnosticSeverity, cx: &mut App) {
self.diagnostics_max_severity = severity;
self.display_map.update(cx, |display_map, _| {
display_map.diagnostics_max_severity = self.diagnostics_max_severity;
});
}
pub fn toggle_diagnostics(
&mut self,
_: &ToggleDiagnostics,
window: &mut Window,
cx: &mut Context<Editor>,
) {
let diagnostics_enabled =
self.diagnostics_enabled() && self.diagnostics_max_severity != DiagnosticSeverity::Off;
self.diagnostics_enabled = !diagnostics_enabled;
let new_severity = if self.diagnostics_enabled {
EditorSettings::get_global(cx)
.diagnostics_max_severity
.filter(|severity| severity != &DiagnosticSeverity::Off)
.unwrap_or(DiagnosticSeverity::Hint)
} else {
DiagnosticSeverity::Off
};
self.set_max_diagnostics_severity(new_severity, cx);
if self.diagnostics_enabled {
self.active_diagnostics = ActiveDiagnostic::None;
self.inline_diagnostics_update = Task::ready(());
self.inline_diagnostics.clear();
} else {
self.refresh_inline_diagnostics(false, window, cx);
}
cx.notify();
}
pub(super) fn all_diagnostics_active(&self) -> bool {
self.active_diagnostics == ActiveDiagnostic::All
}
pub(super) fn active_diagnostic_group_id(&self) -> Option<usize> {
match &self.active_diagnostics {
ActiveDiagnostic::Group(group) => Some(group.group_id),
_ => None,
}
}
pub(super) fn has_active_diagnostic_group(&self) -> bool {
matches!(self.active_diagnostics, ActiveDiagnostic::Group(_))
}
pub(super) fn refresh_active_diagnostics(&mut self, cx: &mut Context<Editor>) {
if !self.diagnostics_enabled() {
return;
}
if let ActiveDiagnostic::Group(active_diagnostics) = &mut self.active_diagnostics {
let buffer = self.buffer.read(cx).snapshot(cx);
let primary_range_start = active_diagnostics.active_range.start.to_offset(&buffer);
let primary_range_end = active_diagnostics.active_range.end.to_offset(&buffer);
let is_valid = buffer
.diagnostics_in_range::<MultiBufferOffset>(primary_range_start..primary_range_end)
.any(|entry| {
entry.diagnostic.is_primary
&& !entry.range.is_empty()
&& entry.range.start == primary_range_start
&& entry.diagnostic.message == active_diagnostics.active_message
});
if !is_valid {
self.dismiss_diagnostics(cx);
}
}
}
pub(super) fn activate_diagnostics(
&mut self,
buffer_id: BufferId,
diagnostic: DiagnosticEntryRef<'_, MultiBufferOffset>,
window: &mut Window,
cx: &mut Context<Self>,
) {
if !self.diagnostics_enabled() || matches!(self.active_diagnostics, ActiveDiagnostic::All) {
return;
}
self.dismiss_diagnostics(cx);
let snapshot = self.snapshot(window, cx);
let buffer = self.buffer.read(cx).snapshot(cx);
let Some(renderer) = GlobalDiagnosticRenderer::global(cx) else {
return;
};
let diagnostic_group = buffer
.diagnostic_group(buffer_id, diagnostic.diagnostic.group_id)
.collect::<Vec<_>>();
let language_registry = self
.project()
.map(|project| project.read(cx).languages().clone());
let blocks = renderer.render_group(
diagnostic_group,
buffer_id,
snapshot,
cx.weak_entity(),
language_registry,
cx,
);
let blocks = self.display_map.update(cx, |display_map, cx| {
display_map.insert_blocks(blocks, cx).into_iter().collect()
});
self.active_diagnostics = ActiveDiagnostic::Group(ActiveDiagnosticGroup {
active_range: buffer.anchor_before(diagnostic.range.start)
..buffer.anchor_after(diagnostic.range.end),
active_message: diagnostic.diagnostic.message.clone(),
group_id: diagnostic.diagnostic.group_id,
blocks,
});
cx.notify();
}
pub(super) fn dismiss_diagnostics(&mut self, cx: &mut Context<Self>) {
if matches!(self.active_diagnostics, ActiveDiagnostic::All) {
return;
};
let prev = mem::replace(&mut self.active_diagnostics, ActiveDiagnostic::None);
if let ActiveDiagnostic::Group(group) = prev {
self.display_map.update(cx, |display_map, cx| {
display_map.remove_blocks(group.blocks, cx);
});
cx.notify();
}
}
pub(super) fn refresh_inline_diagnostics(
&mut self,
debounce: bool,
window: &mut Window,
cx: &mut Context<Self>,
) {
let max_severity = ProjectSettings::get_global(cx)
.diagnostics
.inline
.max_severity
.unwrap_or(self.diagnostics_max_severity);
if !self.inline_diagnostics_enabled()
|| !self.diagnostics_enabled()
|| !self.show_inline_diagnostics
|| max_severity == DiagnosticSeverity::Off
{
self.inline_diagnostics_update = Task::ready(());
self.inline_diagnostics.clear();
return;
}
let debounce_ms = ProjectSettings::get_global(cx)
.diagnostics
.inline
.update_debounce_ms;
let debounce = if debounce && debounce_ms > 0 {
Some(Duration::from_millis(debounce_ms))
} else {
None
};
self.inline_diagnostics_update = cx.spawn_in(window, async move |editor, cx| {
if let Some(debounce) = debounce {
cx.background_executor().timer(debounce).await;
}
let Some(snapshot) = editor.upgrade().map(|editor| {
editor.update(cx, |editor, cx| editor.buffer().read(cx).snapshot(cx))
}) else {
return;
};
let new_inline_diagnostics = cx
.background_spawn(async move {
let mut inline_diagnostics = Vec::<(Anchor, InlineDiagnostic)>::new();
for diagnostic_entry in
snapshot.diagnostics_in_range(MultiBufferOffset(0)..snapshot.len())
{
let message = diagnostic_entry
.diagnostic
.message
.split_once('\n')
.map(|(line, _)| line)
.map(SharedString::new)
.unwrap_or_else(|| {
SharedString::new(&*diagnostic_entry.diagnostic.message)
});
let start_anchor = snapshot.anchor_before(diagnostic_entry.range.start);
let (Ok(i) | Err(i)) = inline_diagnostics
.binary_search_by(|(probe, _)| probe.cmp(&start_anchor, &snapshot));
inline_diagnostics.insert(
i,
(
start_anchor,
InlineDiagnostic {
message,
group_id: diagnostic_entry.diagnostic.group_id,
start: diagnostic_entry.range.start.to_point(&snapshot),
is_primary: diagnostic_entry.diagnostic.is_primary,
severity: diagnostic_entry.diagnostic.severity,
},
),
);
}
inline_diagnostics
})
.await;
editor
.update(cx, |editor, cx| {
editor.inline_diagnostics = new_inline_diagnostics;
cx.notify();
})
.ok();
});
}
pub(super) fn pull_diagnostics(
&mut self,
buffer_id: BufferId,
_window: &Window,
cx: &mut Context<Self>,
) -> Option<()> {
// `ActiveDiagnostic::All` is a special mode where editor's diagnostics are managed by the external view,
// skip any LSP updates for it.
if self.active_diagnostics == ActiveDiagnostic::All || !self.diagnostics_enabled() {
return None;
}
let pull_diagnostics_settings = ProjectSettings::get_global(cx)
.diagnostics
.lsp_pull_diagnostics;
if !pull_diagnostics_settings.enabled {
return None;
}
let debounce = Duration::from_millis(pull_diagnostics_settings.debounce_ms);
let project = self.project()?.downgrade();
let buffer = self.buffer().read(cx).buffer(buffer_id)?;
self.pull_diagnostics_task = cx.spawn(async move |_, cx| {
cx.background_executor().timer(debounce).await;
if let Ok(task) = project.update(cx, |project, cx| {
project.lsp_store().update(cx, |lsp_store, cx| {
lsp_store.pull_diagnostics_for_buffer(buffer, cx)
})
}) {
task.await.log_err();
}
project
.update(cx, |project, cx| {
project.lsp_store().update(cx, |lsp_store, cx| {
lsp_store.pull_document_diagnostics_for_buffer_edit(buffer_id, cx);
})
})
.log_err();
});
Some(())
}
pub(super) fn update_diagnostics_state(
&mut self,
window: &mut Window,
cx: &mut Context<'_, Editor>,
) {
if !self.diagnostics_enabled() {
return;
}
self.refresh_active_diagnostics(cx);
self.refresh_inline_diagnostics(true, window, cx);
self.scrollbar_marker_state.dirty = true;
cx.notify();
}
}

View file

@ -1,11 +1,11 @@
use crate::{
ActiveDiagnostic, BUFFER_HEADER_PADDING, BlockId, CURSORS_VISIBLE_FOR, ChunkRendererContext,
ChunkReplacement, CodeActionSource, ColumnarMode, ConflictsOurs, ConflictsOursMarker,
ConflictsOuter, ConflictsTheirs, ConflictsTheirsMarker, ContextMenuPlacement, CursorShape,
CustomBlockId, DisplayDiffHunk, DisplayPoint, DisplayRow, EditDisplayMode, EditPrediction,
Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle, FILE_HEADER_HEIGHT,
FocusedBlock, GutterDimensions, GutterHoverButton, HalfPageDown, HalfPageUp, HandleInput,
HoveredCursor, InlayHintRefreshReason, JumpData, LineDown, LineHighlight, LineUp, MAX_LINE_LEN,
BUFFER_HEADER_PADDING, BlockId, CURSORS_VISIBLE_FOR, ChunkRendererContext, ChunkReplacement,
CodeActionSource, ColumnarMode, ConflictsOurs, ConflictsOursMarker, ConflictsOuter,
ConflictsTheirs, ConflictsTheirsMarker, ContextMenuPlacement, CursorShape, CustomBlockId,
DisplayDiffHunk, DisplayPoint, DisplayRow, EditDisplayMode, EditPrediction, Editor, EditorMode,
EditorSettings, EditorSnapshot, EditorStyle, FILE_HEADER_HEIGHT, FocusedBlock,
GutterDimensions, GutterHoverButton, HalfPageDown, HalfPageUp, HandleInput, HoveredCursor,
InlayHintRefreshReason, JumpData, LineDown, LineHighlight, LineUp, MAX_LINE_LEN,
MINIMAP_FONT_SIZE, MULTI_BUFFER_EXCERPT_HEADER_HEIGHT, OpenExcerpts, PageDown, PageUp,
PhantomDiffReviewIndicator, Point, RowExt, RowRangeExt, SelectPhase, Selection,
SelectionDragState, SelectionEffects, SizingBehavior, SoftWrap, StickyHeaderExcerpt, ToPoint,
@ -2498,12 +2498,7 @@ impl EditorElement {
None => return HashMap::default(),
};
let active_diagnostics_group =
if let ActiveDiagnostic::Group(group) = &self.editor.read(cx).active_diagnostics {
Some(group.group_id)
} else {
None
};
let active_diagnostics_group = self.editor.read(cx).active_diagnostic_group_id();
let diagnostics_by_rows = self.editor.update(cx, |editor, cx| {
let snapshot = editor.snapshot(window, cx);

View file

@ -1,6 +1,6 @@
use crate::{
ActiveDiagnostic, Anchor, AnchorRangeExt, DisplayPoint, DisplayRow, Editor, EditorSettings,
EditorSnapshot, GlobalDiagnosticRenderer, HighlightKey, Hover,
Anchor, AnchorRangeExt, DisplayPoint, DisplayRow, Editor, EditorSettings, EditorSnapshot,
GlobalDiagnosticRenderer, HighlightKey, Hover,
display_map::{InlayOffset, ToDisplayPoint, is_invisible},
editor_settings::EditorSettingsScrollbarProxy,
hover_links::{InlayHighlight, RangeInEditor},
@ -319,12 +319,8 @@ fn show_hover(
}
let hover_popover_delay = EditorSettings::get_global(cx).hover_popover_delay.0;
let all_diagnostics_active = editor.active_diagnostics == ActiveDiagnostic::All;
let active_group_id = if let ActiveDiagnostic::Group(group) = &editor.active_diagnostics {
Some(group.group_id)
} else {
None
};
let all_diagnostics_active = editor.all_diagnostics_active();
let active_group_id = editor.active_diagnostic_group_id();
let renderer = GlobalDiagnosticRenderer::global(cx);
let task = cx.spawn_in(window, async move |this, cx| {

View file

@ -27,7 +27,6 @@ use std::process::ExitStatus;
use std::str::FromStr;
use std::{
cmp::Ordering,
future,
path::{Path, PathBuf},
sync::Arc,
};
@ -1089,7 +1088,7 @@ impl RealGitRepository {
.map(Path::to_path_buf)
}
fn git_binary(&self) -> Result<GitBinary> {
fn git_binary_in_worktree(&self) -> Result<GitBinary> {
Ok(GitBinary::new(
self.any_git_binary_path.clone(),
self.working_directory()
@ -1100,12 +1099,27 @@ impl RealGitRepository {
))
}
fn git_binary(&self) -> GitBinary {
let repository = self.repository.lock();
let working_directory = repository
.workdir()
.unwrap_or_else(|| repository.path())
.to_path_buf();
GitBinary::new(
self.any_git_binary_path.clone(),
working_directory,
repository.path().to_path_buf(),
self.executor.clone(),
self.is_trusted(),
)
}
fn edit_ref(&self, edit: RefEdit) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git = self.git_binary();
self.executor
.spawn(async move {
let args = edit.into_args();
git_binary?.run(&args).await?;
git.run(&args).await?;
Ok(())
})
.boxed()
@ -1115,10 +1129,10 @@ impl RealGitRepository {
if let Some(output) = self.any_git_binary_help_output.lock().clone() {
return output;
}
let git_binary = self.git_binary();
let git = self.git_binary();
let output: SharedString = self
.executor
.spawn(async move { git_binary?.run(&["help", "-a"]).await })
.spawn(async move { git.run(&["help", "-a"]).await })
.await
.unwrap_or_default()
.into();
@ -1202,10 +1216,9 @@ impl GitRepository for RealGitRepository {
}
fn show(&self, commit: String) -> BoxFuture<'_, Result<CommitDetails>> {
let git_binary = self.git_binary();
let git = self.git_binary();
self.executor
.spawn(async move {
let git = git_binary?;
let output = git
.build_command(&[
"show",
@ -1237,12 +1250,8 @@ impl GitRepository for RealGitRepository {
}
fn load_commit(&self, commit: String, cx: AsyncApp) -> BoxFuture<'_, Result<CommitDiff>> {
if self.repository.lock().workdir().is_none() {
return future::ready(Err(anyhow!("no working directory"))).boxed();
}
let git_binary = self.git_binary();
let git = self.git_binary();
cx.background_spawn(async move {
let git = git_binary?;
let show_output = git
.build_command(&[
"show",
@ -1372,7 +1381,7 @@ impl GitRepository for RealGitRepository {
mode: ResetMode,
env: Arc<HashMap<String, String>>,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
async move {
let mode_flag = match mode {
ResetMode::Mixed => "--mixed",
@ -1401,7 +1410,7 @@ impl GitRepository for RealGitRepository {
paths: Vec<RepoPath>,
env: Arc<HashMap<String, String>>,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
async move {
if paths.is_empty() {
return Ok(());
@ -1557,10 +1566,9 @@ impl GitRepository for RealGitRepository {
env: Arc<HashMap<String, String>>,
is_executable: bool,
) -> BoxFuture<'_, anyhow::Result<()>> {
let git_binary = self.git_binary();
let git = self.git_binary();
self.executor
.spawn(async move {
let git = git_binary?;
let mode = if is_executable { "100755" } else { "100644" };
if let Some(content) = content {
@ -1624,10 +1632,9 @@ impl GitRepository for RealGitRepository {
}
fn revparse_batch(&self, revs: Vec<String>) -> BoxFuture<'_, Result<Vec<Option<String>>>> {
let git_binary = self.git_binary();
let git = self.git_binary();
self.executor
.spawn(async move {
let git = git_binary?;
let mut process = git
.build_command(&["cat-file", "--batch-check=%(objectname)"])
.stdin(Stdio::piped())
@ -1678,7 +1685,7 @@ impl GitRepository for RealGitRepository {
}
fn status(&self, path_prefixes: &[RepoPath]) -> Task<Result<GitStatus>> {
let git = match self.git_binary() {
let git = match self.git_binary_in_worktree() {
Ok(git) => git,
Err(e) => return Task::ready(Err(e)),
};
@ -1697,7 +1704,7 @@ impl GitRepository for RealGitRepository {
}
fn diff_tree(&self, request: DiffTreeType) -> BoxFuture<'_, Result<TreeDiff>> {
let git = match self.git_binary() {
let git = match self.git_binary_in_worktree() {
Ok(git) => git,
Err(e) => return Task::ready(Err(e)).boxed(),
};
@ -1735,7 +1742,7 @@ impl GitRepository for RealGitRepository {
}
fn stash_entries(&self) -> BoxFuture<'_, Result<GitStash>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
let git = git_binary?;
@ -1755,7 +1762,7 @@ impl GitRepository for RealGitRepository {
}
fn branches(&self) -> BoxFuture<'_, Result<Vec<Branch>>> {
let git_binary = self.git_binary();
let git = self.git_binary();
self.executor
.spawn(async move {
let fields = [
@ -1777,7 +1784,6 @@ impl GitRepository for RealGitRepository {
"--format",
&fields,
];
let git = git_binary?;
let output = git.build_command(&args).output().await?;
anyhow::ensure!(
@ -1814,7 +1820,7 @@ impl GitRepository for RealGitRepository {
}
fn worktrees(&self) -> BoxFuture<'_, Result<Vec<Worktree>>> {
let git_binary = self.git_binary();
let git = self.git_binary();
let main_worktree_path = {
let repo = self.repository.lock();
let common_dir = repo.commondir().to_path_buf();
@ -1822,7 +1828,6 @@ impl GitRepository for RealGitRepository {
};
self.executor
.spawn(async move {
let git = git_binary?;
let output = git
.build_command(&["worktree", "list", "--porcelain"])
.output()
@ -1846,7 +1851,7 @@ impl GitRepository for RealGitRepository {
target: CreateWorktreeTarget,
path: PathBuf,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git = self.git_binary();
let mut args = vec![OsString::from("worktree"), OsString::from("add")];
match &target {
@ -1878,7 +1883,6 @@ impl GitRepository for RealGitRepository {
self.executor
.spawn(async move {
std::fs::create_dir_all(path.parent().unwrap_or(&path))?;
let git = git_binary?;
let output = git.build_command(&args).output().await?;
if output.status.success() {
Ok(())
@ -1891,7 +1895,7 @@ impl GitRepository for RealGitRepository {
}
fn remove_worktree(&self, path: PathBuf, force: bool) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git = self.git_binary();
self.executor
.spawn(async move {
@ -1901,14 +1905,14 @@ impl GitRepository for RealGitRepository {
}
args.push("--".into());
args.push(path.as_os_str().into());
git_binary?.run(&args).await?;
git.run(&args).await?;
anyhow::Ok(())
})
.boxed()
}
fn rename_worktree(&self, old_path: PathBuf, new_path: PathBuf) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git = self.git_binary();
self.executor
.spawn(async move {
@ -1919,7 +1923,7 @@ impl GitRepository for RealGitRepository {
old_path.as_os_str().into(),
new_path.as_os_str().into(),
];
git_binary?.run(&args).await?;
git.run(&args).await?;
anyhow::Ok(())
})
.boxed()
@ -1953,7 +1957,7 @@ impl GitRepository for RealGitRepository {
fn change_branch(&self, name: String) -> BoxFuture<'_, Result<()>> {
let repo = self.repository.clone();
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
let branch = self.executor.spawn(async move {
let repo = repo.lock();
let branch = if let Ok(branch) = repo.find_branch(&name, BranchType::Local) {
@ -1999,7 +2003,7 @@ impl GitRepository for RealGitRepository {
name: String,
base_branch: Option<String>,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
@ -2017,7 +2021,7 @@ impl GitRepository for RealGitRepository {
}
fn rename_branch(&self, branch: String, new_name: String) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
@ -2030,7 +2034,7 @@ impl GitRepository for RealGitRepository {
}
fn delete_branch(&self, is_remote: bool, name: String) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
@ -2048,7 +2052,7 @@ impl GitRepository for RealGitRepository {
content: Rope,
line_ending: LineEnding,
) -> BoxFuture<'_, Result<crate::blame::Blame>> {
let git = self.git_binary();
let git = self.git_binary_in_worktree();
self.executor
.spawn(async move {
@ -2058,7 +2062,7 @@ impl GitRepository for RealGitRepository {
}
fn diff(&self, diff: DiffType) -> BoxFuture<'_, Result<String>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
let git = git_binary?;
@ -2089,7 +2093,7 @@ impl GitRepository for RealGitRepository {
path_prefixes: &[RepoPath],
) -> BoxFuture<'_, Result<crate::status::GitDiffStat>> {
let path_prefixes = path_prefixes.to_vec();
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
@ -2119,7 +2123,7 @@ impl GitRepository for RealGitRepository {
paths: Vec<RepoPath>,
env: Arc<HashMap<String, String>>,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
if !paths.is_empty() {
@ -2146,7 +2150,7 @@ impl GitRepository for RealGitRepository {
paths: Vec<RepoPath>,
env: Arc<HashMap<String, String>>,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
@ -2175,7 +2179,7 @@ impl GitRepository for RealGitRepository {
paths: Vec<RepoPath>,
env: Arc<HashMap<String, String>>,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
let git = git_binary?;
@ -2201,7 +2205,7 @@ impl GitRepository for RealGitRepository {
index: Option<usize>,
env: Arc<HashMap<String, String>>,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
let git = git_binary?;
@ -2226,7 +2230,7 @@ impl GitRepository for RealGitRepository {
index: Option<usize>,
env: Arc<HashMap<String, String>>,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
let git = git_binary?;
@ -2251,7 +2255,7 @@ impl GitRepository for RealGitRepository {
index: Option<usize>,
env: Arc<HashMap<String, String>>,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
let git = git_binary?;
@ -2279,7 +2283,7 @@ impl GitRepository for RealGitRepository {
ask_pass: AskPassDelegate,
env: Arc<HashMap<String, String>>,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
let executor = self.executor.clone();
// Note: Do not spawn this command on the background thread, it might pop open the credential helper
// which we want to block on.
@ -2325,11 +2329,11 @@ impl GitRepository for RealGitRepository {
}
fn repair_worktrees(&self) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git = self.git_binary();
self.executor
.spawn(async move {
let args: Vec<OsString> = vec!["worktree".into(), "repair".into()];
git_binary?.run(&args).await?;
git.run(&args).await?;
Ok(())
})
.boxed()
@ -2431,7 +2435,7 @@ impl GitRepository for RealGitRepository {
env: Arc<HashMap<String, String>>,
cx: AsyncApp,
) -> BoxFuture<'_, Result<RemoteCommandOutput>> {
let working_directory = self.working_directory();
let working_directory = self.working_directory().unwrap_or(self.path());
let git_directory = self.path();
let remote_name = format!("{}", fetch_options);
let git_binary_path = self.system_git_binary_path.clone();
@ -2441,7 +2445,6 @@ impl GitRepository for RealGitRepository {
// which we want to block on.
async move {
let git_binary_path = git_binary_path.context("git not found on $PATH, can't fetch")?;
let working_directory = working_directory?;
let git = GitBinary::new(
git_binary_path,
working_directory,
@ -2461,10 +2464,9 @@ impl GitRepository for RealGitRepository {
}
fn get_push_remote(&self, branch: String) -> BoxFuture<'_, Result<Option<Remote>>> {
let git_binary = self.git_binary();
let git = self.git_binary();
self.executor
.spawn(async move {
let git = git_binary?;
let output = git
.build_command(&["rev-parse", "--abbrev-ref"])
.arg(format!("{branch}@{{push}}"))
@ -2486,10 +2488,9 @@ impl GitRepository for RealGitRepository {
}
fn get_branch_remote(&self, branch: String) -> BoxFuture<'_, Result<Option<Remote>>> {
let git_binary = self.git_binary();
let git = self.git_binary();
self.executor
.spawn(async move {
let git = git_binary?;
let output = git
.build_command(&["config", "--get"])
.arg(format!("branch.{branch}.remote"))
@ -2508,10 +2509,9 @@ impl GitRepository for RealGitRepository {
}
fn get_all_remotes(&self) -> BoxFuture<'_, Result<Vec<Remote>>> {
let git_binary = self.git_binary();
let git = self.git_binary();
self.executor
.spawn(async move {
let git = git_binary?;
let output = git.build_command(&["remote", "-v"]).output().await?;
anyhow::ensure!(
@ -2561,7 +2561,7 @@ impl GitRepository for RealGitRepository {
}
fn check_for_pushed_commit(&self) -> BoxFuture<'_, Result<Vec<SharedString>>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
let git = git_binary?;
@ -2615,7 +2615,7 @@ impl GitRepository for RealGitRepository {
}
fn checkpoint(&self) -> BoxFuture<'static, Result<GitRepositoryCheckpoint>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
let mut git = git_binary?.envs(checkpoint_author_envs());
@ -2644,7 +2644,7 @@ impl GitRepository for RealGitRepository {
}
fn restore_checkpoint(&self, checkpoint: GitRepositoryCheckpoint) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
let git = git_binary?;
@ -2674,7 +2674,7 @@ impl GitRepository for RealGitRepository {
}
fn create_archive_checkpoint(&self) -> BoxFuture<'_, Result<(String, String)>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
let mut git = git_binary?.envs(checkpoint_author_envs());
@ -2732,7 +2732,7 @@ impl GitRepository for RealGitRepository {
staged_sha: String,
unstaged_sha: String,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
let git = git_binary?;
@ -2762,7 +2762,7 @@ impl GitRepository for RealGitRepository {
left: GitRepositoryCheckpoint,
right: GitRepositoryCheckpoint,
) -> BoxFuture<'_, Result<bool>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
let git = git_binary?;
@ -2796,7 +2796,7 @@ impl GitRepository for RealGitRepository {
base_checkpoint: GitRepositoryCheckpoint,
target_checkpoint: GitRepositoryCheckpoint,
) -> BoxFuture<'_, Result<String>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
self.executor
.spawn(async move {
let git = git_binary?;
@ -2816,11 +2816,9 @@ impl GitRepository for RealGitRepository {
&self,
include_remote_name: bool,
) -> BoxFuture<'_, Result<Option<SharedString>>> {
let git_binary = self.git_binary();
let git = self.git_binary();
self.executor
.spawn(async move {
let git = git_binary?;
let strip_prefix = if include_remote_name {
"refs/remotes/"
} else {
@ -2869,7 +2867,7 @@ impl GitRepository for RealGitRepository {
hook: RunHook,
env: Arc<HashMap<String, String>>,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git_binary = self.git_binary_in_worktree();
let repository = self.repository.clone();
let help_output = self.any_git_binary_help_output();
@ -2922,11 +2920,9 @@ impl GitRepository for RealGitRepository {
log_order: LogOrder,
request_tx: Sender<Vec<Arc<InitialGraphCommitData>>>,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git = self.git_binary();
async move {
let git = git_binary?;
let mut git_log_command = vec![
"log",
GRAPH_COMMIT_FORMAT,
@ -3004,11 +3000,9 @@ impl GitRepository for RealGitRepository {
search_args: SearchCommitArgs,
request_tx: Sender<Oid>,
) -> BoxFuture<'_, Result<()>> {
let git_binary = self.git_binary();
let git = self.git_binary();
async move {
let git = git_binary?;
let mut args = vec!["log", SEARCH_COMMIT_FORMAT, log_source.get_arg()?];
args.push("--fixed-strings");
@ -3058,7 +3052,7 @@ impl GitRepository for RealGitRepository {
}
fn commit_data_reader(&self) -> Result<CommitDataReader> {
let git_binary = self.git_binary()?;
let git_binary = self.git_binary();
let (request_tx, request_rx) = async_channel::bounded::<CommitDataRequest>(64);