Merge remote-tracking branch 'origin/main' into ai-refactoring
This commit is contained in:
commit
44f554f489
96 changed files with 4850 additions and 1757 deletions
|
@ -23,7 +23,7 @@ pub mod test;
|
|||
|
||||
use ::git::diff::DiffHunk;
|
||||
use aho_corasick::AhoCorasick;
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use blink_manager::BlinkManager;
|
||||
use client::{ClickhouseEvent, TelemetrySettings};
|
||||
use clock::{Global, ReplicaId};
|
||||
|
@ -60,21 +60,24 @@ use itertools::Itertools;
|
|||
pub use language::{char_kind, CharKind};
|
||||
use language::{
|
||||
language_settings::{self, all_language_settings, InlayHintSettings},
|
||||
AutoindentMode, BracketPair, Buffer, CodeAction, CodeLabel, Completion, CursorShape,
|
||||
Diagnostic, DiagnosticSeverity, File, IndentKind, IndentSize, Language, OffsetRangeExt,
|
||||
OffsetUtf16, Point, Selection, SelectionGoal, TransactionId,
|
||||
point_from_lsp, AutoindentMode, BracketPair, Buffer, CodeAction, CodeLabel, Completion,
|
||||
CursorShape, Diagnostic, DiagnosticSeverity, File, IndentKind, IndentSize, Language,
|
||||
LanguageServerName, OffsetRangeExt, OffsetUtf16, Point, Selection, SelectionGoal,
|
||||
TransactionId,
|
||||
};
|
||||
use link_go_to_definition::{
|
||||
hide_link_definition, show_link_definition, LinkDefinitionKind, LinkGoToDefinitionState,
|
||||
hide_link_definition, show_link_definition, DocumentRange, GoToDefinitionLink, InlayRange,
|
||||
LinkGoToDefinitionState,
|
||||
};
|
||||
use log::error;
|
||||
use lsp::LanguageServerId;
|
||||
use multi_buffer::ToOffsetUtf16;
|
||||
pub use multi_buffer::{
|
||||
Anchor, AnchorRangeExt, ExcerptId, ExcerptRange, MultiBuffer, MultiBufferSnapshot, ToOffset,
|
||||
ToPoint,
|
||||
};
|
||||
use ordered_float::OrderedFloat;
|
||||
use project::{FormatTrigger, Location, LocationLink, Project, ProjectPath, ProjectTransaction};
|
||||
use project::{FormatTrigger, Location, Project, ProjectPath, ProjectTransaction};
|
||||
use rand::{seq::SliceRandom, thread_rng};
|
||||
use scroll::{
|
||||
autoscroll::Autoscroll, OngoingScroll, ScrollAnchor, ScrollManager, ScrollbarAutoHide,
|
||||
|
@ -535,6 +538,8 @@ type CompletionId = usize;
|
|||
type GetFieldEditorTheme = dyn Fn(&theme::Theme) -> theme::FieldEditor;
|
||||
type OverrideTextStyle = dyn Fn(&EditorStyle) -> Option<HighlightStyle>;
|
||||
|
||||
type BackgroundHighlight = (fn(&Theme) -> Color, Vec<DocumentRange>);
|
||||
|
||||
pub struct Editor {
|
||||
handle: WeakViewHandle<Self>,
|
||||
buffer: ModelHandle<MultiBuffer>,
|
||||
|
@ -564,8 +569,7 @@ pub struct Editor {
|
|||
show_wrap_guides: Option<bool>,
|
||||
placeholder_text: Option<Arc<str>>,
|
||||
highlighted_rows: Option<Range<u32>>,
|
||||
#[allow(clippy::type_complexity)]
|
||||
background_highlights: BTreeMap<TypeId, (fn(&Theme) -> Color, Vec<Range<Anchor>>)>,
|
||||
background_highlights: BTreeMap<TypeId, BackgroundHighlight>,
|
||||
nav_history: Option<ItemNavHistory>,
|
||||
context_menu: Option<ContextMenu>,
|
||||
mouse_context_menu: ViewHandle<context_menu::ContextMenu>,
|
||||
|
@ -1247,6 +1251,19 @@ enum InlayHintRefreshReason {
|
|||
NewLinesShown,
|
||||
BufferEdited(HashSet<Arc<Language>>),
|
||||
RefreshRequested,
|
||||
ExcerptsRemoved(Vec<ExcerptId>),
|
||||
}
|
||||
impl InlayHintRefreshReason {
|
||||
fn description(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Toggle(_) => "toggle",
|
||||
Self::SettingsChange(_) => "settings change",
|
||||
Self::NewLinesShown => "new lines shown",
|
||||
Self::BufferEdited(_) => "buffer edited",
|
||||
Self::RefreshRequested => "refresh requested",
|
||||
Self::ExcerptsRemoved(_) => "excerpts removed",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Editor {
|
||||
|
@ -1254,7 +1271,7 @@ impl Editor {
|
|||
field_editor_style: Option<Arc<GetFieldEditorTheme>>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
let buffer = cx.add_model(|cx| Buffer::new(0, String::new(), cx));
|
||||
let buffer = cx.add_model(|cx| Buffer::new(0, cx.model_id() as u64, String::new()));
|
||||
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
Self::new(EditorMode::SingleLine, buffer, None, field_editor_style, cx)
|
||||
}
|
||||
|
@ -1263,7 +1280,7 @@ impl Editor {
|
|||
field_editor_style: Option<Arc<GetFieldEditorTheme>>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
let buffer = cx.add_model(|cx| Buffer::new(0, String::new(), cx));
|
||||
let buffer = cx.add_model(|cx| Buffer::new(0, cx.model_id() as u64, String::new()));
|
||||
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
Self::new(EditorMode::Full, buffer, None, field_editor_style, cx)
|
||||
}
|
||||
|
@ -1273,7 +1290,7 @@ impl Editor {
|
|||
field_editor_style: Option<Arc<GetFieldEditorTheme>>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
let buffer = cx.add_model(|cx| Buffer::new(0, String::new(), cx));
|
||||
let buffer = cx.add_model(|cx| Buffer::new(0, cx.model_id() as u64, String::new()));
|
||||
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
Self::new(
|
||||
EditorMode::AutoHeight { max_lines },
|
||||
|
@ -2746,6 +2763,7 @@ impl Editor {
|
|||
return;
|
||||
}
|
||||
|
||||
let reason_description = reason.description();
|
||||
let (invalidate_cache, required_languages) = match reason {
|
||||
InlayHintRefreshReason::Toggle(enabled) => {
|
||||
self.inlay_hint_cache.enabled = enabled;
|
||||
|
@ -2782,6 +2800,16 @@ impl Editor {
|
|||
ControlFlow::Continue(()) => (InvalidationStrategy::RefreshRequested, None),
|
||||
}
|
||||
}
|
||||
InlayHintRefreshReason::ExcerptsRemoved(excerpts_removed) => {
|
||||
if let Some(InlaySplice {
|
||||
to_remove,
|
||||
to_insert,
|
||||
}) = self.inlay_hint_cache.remove_excerpts(excerpts_removed)
|
||||
{
|
||||
self.splice_inlay_hints(to_remove, to_insert, cx);
|
||||
}
|
||||
return;
|
||||
}
|
||||
InlayHintRefreshReason::NewLinesShown => (InvalidationStrategy::None, None),
|
||||
InlayHintRefreshReason::BufferEdited(buffer_languages) => {
|
||||
(InvalidationStrategy::BufferEdited, Some(buffer_languages))
|
||||
|
@ -2795,6 +2823,7 @@ impl Editor {
|
|||
to_remove,
|
||||
to_insert,
|
||||
}) = self.inlay_hint_cache.spawn_hint_refresh(
|
||||
reason_description,
|
||||
self.excerpt_visible_offsets(required_languages.as_ref(), cx),
|
||||
invalidate_cache,
|
||||
cx,
|
||||
|
@ -4890,7 +4919,6 @@ impl Editor {
|
|||
if let Some(clipboard_selection) = clipboard_selections.get(ix) {
|
||||
let end_offset = start_offset + clipboard_selection.len;
|
||||
to_insert = &clipboard_text[start_offset..end_offset];
|
||||
dbg!(start_offset, end_offset, &clipboard_text, &to_insert);
|
||||
entire_line = clipboard_selection.is_entire_line;
|
||||
start_offset = end_offset + 1;
|
||||
original_indent_column =
|
||||
|
@ -6252,7 +6280,9 @@ impl Editor {
|
|||
) {
|
||||
self.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||
s.move_offsets_with(|snapshot, selection| {
|
||||
let Some(enclosing_bracket_ranges) = snapshot.enclosing_bracket_ranges(selection.start..selection.end) else {
|
||||
let Some(enclosing_bracket_ranges) =
|
||||
snapshot.enclosing_bracket_ranges(selection.start..selection.end)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
|
@ -6264,7 +6294,8 @@ impl Editor {
|
|||
let close = close.to_inclusive();
|
||||
let length = close.end() - open.start;
|
||||
let inside = selection.start >= open.end && selection.end <= *close.start();
|
||||
let in_bracket_range = open.to_inclusive().contains(&selection.head()) || close.contains(&selection.head());
|
||||
let in_bracket_range = open.to_inclusive().contains(&selection.head())
|
||||
|| close.contains(&selection.head());
|
||||
|
||||
// If best is next to a bracket and current isn't, skip
|
||||
if !in_bracket_range && best_in_bracket_range {
|
||||
|
@ -6279,19 +6310,21 @@ impl Editor {
|
|||
best_length = length;
|
||||
best_inside = inside;
|
||||
best_in_bracket_range = in_bracket_range;
|
||||
best_destination = Some(if close.contains(&selection.start) && close.contains(&selection.end) {
|
||||
if inside {
|
||||
open.end
|
||||
best_destination = Some(
|
||||
if close.contains(&selection.start) && close.contains(&selection.end) {
|
||||
if inside {
|
||||
open.end
|
||||
} else {
|
||||
open.start
|
||||
}
|
||||
} else {
|
||||
open.start
|
||||
}
|
||||
} else {
|
||||
if inside {
|
||||
*close.start()
|
||||
} else {
|
||||
*close.end()
|
||||
}
|
||||
});
|
||||
if inside {
|
||||
*close.start()
|
||||
} else {
|
||||
*close.end()
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(destination) = best_destination {
|
||||
|
@ -6535,7 +6568,9 @@ impl Editor {
|
|||
split: bool,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
let Some(workspace) = self.workspace(cx) else { return };
|
||||
let Some(workspace) = self.workspace(cx) else {
|
||||
return;
|
||||
};
|
||||
let buffer = self.buffer.read(cx);
|
||||
let head = self.selections.newest::<usize>(cx).head();
|
||||
let (buffer, head) = if let Some(text_anchor) = buffer.text_anchor_for_position(head, cx) {
|
||||
|
@ -6553,7 +6588,14 @@ impl Editor {
|
|||
cx.spawn_labeled("Fetching Definition...", |editor, mut cx| async move {
|
||||
let definitions = definitions.await?;
|
||||
editor.update(&mut cx, |editor, cx| {
|
||||
editor.navigate_to_definitions(definitions, split, cx);
|
||||
editor.navigate_to_definitions(
|
||||
definitions
|
||||
.into_iter()
|
||||
.map(GoToDefinitionLink::Text)
|
||||
.collect(),
|
||||
split,
|
||||
cx,
|
||||
);
|
||||
})?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
})
|
||||
|
@ -6562,76 +6604,178 @@ impl Editor {
|
|||
|
||||
pub fn navigate_to_definitions(
|
||||
&mut self,
|
||||
mut definitions: Vec<LocationLink>,
|
||||
mut definitions: Vec<GoToDefinitionLink>,
|
||||
split: bool,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) {
|
||||
let Some(workspace) = self.workspace(cx) else { return };
|
||||
let Some(workspace) = self.workspace(cx) else {
|
||||
return;
|
||||
};
|
||||
let pane = workspace.read(cx).active_pane().clone();
|
||||
// If there is one definition, just open it directly
|
||||
if definitions.len() == 1 {
|
||||
let definition = definitions.pop().unwrap();
|
||||
let range = definition
|
||||
.target
|
||||
.range
|
||||
.to_offset(definition.target.buffer.read(cx));
|
||||
|
||||
let range = self.range_for_match(&range);
|
||||
if Some(&definition.target.buffer) == self.buffer.read(cx).as_singleton().as_ref() {
|
||||
self.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||
s.select_ranges([range]);
|
||||
});
|
||||
} else {
|
||||
cx.window_context().defer(move |cx| {
|
||||
let target_editor: ViewHandle<Self> = workspace.update(cx, |workspace, cx| {
|
||||
if split {
|
||||
workspace.split_project_item(definition.target.buffer.clone(), cx)
|
||||
let target_task = match definition {
|
||||
GoToDefinitionLink::Text(link) => Task::Ready(Some(Ok(Some(link.target)))),
|
||||
GoToDefinitionLink::InlayHint(lsp_location, server_id) => {
|
||||
self.compute_target_location(lsp_location, server_id, cx)
|
||||
}
|
||||
};
|
||||
cx.spawn(|editor, mut cx| async move {
|
||||
let target = target_task.await.context("target resolution task")?;
|
||||
if let Some(target) = target {
|
||||
editor.update(&mut cx, |editor, cx| {
|
||||
let range = target.range.to_offset(target.buffer.read(cx));
|
||||
let range = editor.range_for_match(&range);
|
||||
if Some(&target.buffer) == editor.buffer.read(cx).as_singleton().as_ref() {
|
||||
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||
s.select_ranges([range]);
|
||||
});
|
||||
} else {
|
||||
workspace.open_project_item(definition.target.buffer.clone(), cx)
|
||||
cx.window_context().defer(move |cx| {
|
||||
let target_editor: ViewHandle<Self> =
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
if split {
|
||||
workspace.split_project_item(target.buffer.clone(), cx)
|
||||
} else {
|
||||
workspace.open_project_item(target.buffer.clone(), cx)
|
||||
}
|
||||
});
|
||||
target_editor.update(cx, |target_editor, cx| {
|
||||
// When selecting a definition in a different buffer, disable the nav history
|
||||
// to avoid creating a history entry at the previous cursor location.
|
||||
pane.update(cx, |pane, _| pane.disable_history());
|
||||
target_editor.change_selections(
|
||||
Some(Autoscroll::fit()),
|
||||
cx,
|
||||
|s| {
|
||||
s.select_ranges([range]);
|
||||
},
|
||||
);
|
||||
pane.update(cx, |pane, _| pane.enable_history());
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
target_editor.update(cx, |target_editor, cx| {
|
||||
// When selecting a definition in a different buffer, disable the nav history
|
||||
// to avoid creating a history entry at the previous cursor location.
|
||||
pane.update(cx, |pane, _| pane.disable_history());
|
||||
target_editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||
s.select_ranges([range]);
|
||||
});
|
||||
pane.update(cx, |pane, _| pane.enable_history());
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
} else if !definitions.is_empty() {
|
||||
let replica_id = self.replica_id(cx);
|
||||
cx.window_context().defer(move |cx| {
|
||||
let title = definitions
|
||||
.iter()
|
||||
.find(|definition| definition.origin.is_some())
|
||||
.and_then(|definition| {
|
||||
definition.origin.as_ref().map(|origin| {
|
||||
let buffer = origin.buffer.read(cx);
|
||||
format!(
|
||||
"Definitions for {}",
|
||||
buffer
|
||||
.text_for_range(origin.range.clone())
|
||||
.collect::<String>()
|
||||
)
|
||||
})
|
||||
cx.spawn(|editor, mut cx| async move {
|
||||
let (title, location_tasks) = editor
|
||||
.update(&mut cx, |editor, cx| {
|
||||
let title = definitions
|
||||
.iter()
|
||||
.find_map(|definition| match definition {
|
||||
GoToDefinitionLink::Text(link) => {
|
||||
link.origin.as_ref().map(|origin| {
|
||||
let buffer = origin.buffer.read(cx);
|
||||
format!(
|
||||
"Definitions for {}",
|
||||
buffer
|
||||
.text_for_range(origin.range.clone())
|
||||
.collect::<String>()
|
||||
)
|
||||
})
|
||||
}
|
||||
GoToDefinitionLink::InlayHint(_, _) => None,
|
||||
})
|
||||
.unwrap_or("Definitions".to_string());
|
||||
let location_tasks = definitions
|
||||
.into_iter()
|
||||
.map(|definition| match definition {
|
||||
GoToDefinitionLink::Text(link) => {
|
||||
Task::Ready(Some(Ok(Some(link.target))))
|
||||
}
|
||||
GoToDefinitionLink::InlayHint(lsp_location, server_id) => {
|
||||
editor.compute_target_location(lsp_location, server_id, cx)
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
(title, location_tasks)
|
||||
})
|
||||
.unwrap_or("Definitions".to_owned());
|
||||
let locations = definitions
|
||||
.context("location tasks preparation")?;
|
||||
|
||||
let locations = futures::future::join_all(location_tasks)
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|definition| definition.target)
|
||||
.collect();
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
.filter_map(|location| location.transpose())
|
||||
.collect::<Result<_>>()
|
||||
.context("location tasks")?;
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
Self::open_locations_in_multibuffer(
|
||||
workspace, locations, replica_id, title, split, cx,
|
||||
)
|
||||
});
|
||||
});
|
||||
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_target_location(
|
||||
&self,
|
||||
lsp_location: lsp::Location,
|
||||
server_id: LanguageServerId,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) -> Task<anyhow::Result<Option<Location>>> {
|
||||
let Some(project) = self.project.clone() else {
|
||||
return Task::Ready(Some(Ok(None)));
|
||||
};
|
||||
|
||||
cx.spawn(move |editor, mut cx| async move {
|
||||
let location_task = editor.update(&mut cx, |editor, cx| {
|
||||
project.update(cx, |project, cx| {
|
||||
let language_server_name =
|
||||
editor.buffer.read(cx).as_singleton().and_then(|buffer| {
|
||||
project
|
||||
.language_server_for_buffer(buffer.read(cx), server_id, cx)
|
||||
.map(|(_, lsp_adapter)| {
|
||||
LanguageServerName(Arc::from(lsp_adapter.name()))
|
||||
})
|
||||
});
|
||||
language_server_name.map(|language_server_name| {
|
||||
project.open_local_buffer_via_lsp(
|
||||
lsp_location.uri.clone(),
|
||||
server_id,
|
||||
language_server_name,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
})
|
||||
})?;
|
||||
let location = match location_task {
|
||||
Some(task) => Some({
|
||||
let target_buffer_handle = task.await.context("open local buffer")?;
|
||||
let range = {
|
||||
target_buffer_handle.update(&mut cx, |target_buffer, _| {
|
||||
let target_start = target_buffer.clip_point_utf16(
|
||||
point_from_lsp(lsp_location.range.start),
|
||||
Bias::Left,
|
||||
);
|
||||
let target_end = target_buffer.clip_point_utf16(
|
||||
point_from_lsp(lsp_location.range.end),
|
||||
Bias::Left,
|
||||
);
|
||||
target_buffer.anchor_after(target_start)
|
||||
..target_buffer.anchor_before(target_end)
|
||||
})
|
||||
};
|
||||
Location {
|
||||
buffer: target_buffer_handle,
|
||||
range,
|
||||
}
|
||||
}),
|
||||
None => None,
|
||||
};
|
||||
Ok(location)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn find_all_references(
|
||||
workspace: &mut Workspace,
|
||||
_: &FindAllReferences,
|
||||
|
@ -6767,10 +6911,18 @@ impl Editor {
|
|||
let rename_range = if let Some(range) = prepare_rename.await? {
|
||||
Some(range)
|
||||
} else {
|
||||
this.read_with(&cx, |this, cx| {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
let buffer = this.buffer.read(cx).snapshot(cx);
|
||||
let display_snapshot = this
|
||||
.display_map
|
||||
.update(cx, |display_map, cx| display_map.snapshot(cx));
|
||||
let mut buffer_highlights = this
|
||||
.document_highlights_for_position(selection.head(), &buffer)
|
||||
.document_highlights_for_position(
|
||||
selection.head(),
|
||||
&buffer,
|
||||
&display_snapshot,
|
||||
)
|
||||
.filter_map(|highlight| highlight.as_text_range())
|
||||
.filter(|highlight| {
|
||||
highlight.start.excerpt_id() == selection.head().excerpt_id()
|
||||
&& highlight.end.excerpt_id() == selection.head().excerpt_id()
|
||||
|
@ -6825,11 +6977,15 @@ impl Editor {
|
|||
let ranges = this
|
||||
.clear_background_highlights::<DocumentHighlightWrite>(cx)
|
||||
.into_iter()
|
||||
.flat_map(|(_, ranges)| ranges)
|
||||
.flat_map(|(_, ranges)| {
|
||||
ranges.into_iter().filter_map(|range| range.as_text_range())
|
||||
})
|
||||
.chain(
|
||||
this.clear_background_highlights::<DocumentHighlightRead>(cx)
|
||||
.into_iter()
|
||||
.flat_map(|(_, ranges)| ranges),
|
||||
.flat_map(|(_, ranges)| {
|
||||
ranges.into_iter().filter_map(|range| range.as_text_range())
|
||||
}),
|
||||
)
|
||||
.collect();
|
||||
|
||||
|
@ -7497,16 +7653,36 @@ impl Editor {
|
|||
color_fetcher: fn(&Theme) -> Color,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.background_highlights
|
||||
.insert(TypeId::of::<T>(), (color_fetcher, ranges));
|
||||
self.background_highlights.insert(
|
||||
TypeId::of::<T>(),
|
||||
(
|
||||
color_fetcher,
|
||||
ranges.into_iter().map(DocumentRange::Text).collect(),
|
||||
),
|
||||
);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn highlight_inlay_background<T: 'static>(
|
||||
&mut self,
|
||||
ranges: Vec<InlayRange>,
|
||||
color_fetcher: fn(&Theme) -> Color,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.background_highlights.insert(
|
||||
TypeId::of::<T>(),
|
||||
(
|
||||
color_fetcher,
|
||||
ranges.into_iter().map(DocumentRange::Inlay).collect(),
|
||||
),
|
||||
);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn clear_background_highlights<T: 'static>(
|
||||
&mut self,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<(fn(&Theme) -> Color, Vec<Range<Anchor>>)> {
|
||||
) -> Option<BackgroundHighlight> {
|
||||
let highlights = self.background_highlights.remove(&TypeId::of::<T>());
|
||||
if highlights.is_some() {
|
||||
cx.notify();
|
||||
|
@ -7531,7 +7707,8 @@ impl Editor {
|
|||
&'a self,
|
||||
position: Anchor,
|
||||
buffer: &'a MultiBufferSnapshot,
|
||||
) -> impl 'a + Iterator<Item = &Range<Anchor>> {
|
||||
display_snapshot: &'a DisplaySnapshot,
|
||||
) -> impl 'a + Iterator<Item = &DocumentRange> {
|
||||
let read_highlights = self
|
||||
.background_highlights
|
||||
.get(&TypeId::of::<DocumentHighlightRead>())
|
||||
|
@ -7540,14 +7717,16 @@ impl Editor {
|
|||
.background_highlights
|
||||
.get(&TypeId::of::<DocumentHighlightWrite>())
|
||||
.map(|h| &h.1);
|
||||
let left_position = position.bias_left(buffer);
|
||||
let right_position = position.bias_right(buffer);
|
||||
let left_position = display_snapshot.anchor_to_inlay_offset(position.bias_left(buffer));
|
||||
let right_position = display_snapshot.anchor_to_inlay_offset(position.bias_right(buffer));
|
||||
read_highlights
|
||||
.into_iter()
|
||||
.chain(write_highlights)
|
||||
.flat_map(move |ranges| {
|
||||
let start_ix = match ranges.binary_search_by(|probe| {
|
||||
let cmp = probe.end.cmp(&left_position, buffer);
|
||||
let cmp = document_to_inlay_range(probe, display_snapshot)
|
||||
.end
|
||||
.cmp(&left_position);
|
||||
if cmp.is_ge() {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
|
@ -7558,9 +7737,12 @@ impl Editor {
|
|||
};
|
||||
|
||||
let right_position = right_position.clone();
|
||||
ranges[start_ix..]
|
||||
.iter()
|
||||
.take_while(move |range| range.start.cmp(&right_position, buffer).is_le())
|
||||
ranges[start_ix..].iter().take_while(move |range| {
|
||||
document_to_inlay_range(range, display_snapshot)
|
||||
.start
|
||||
.cmp(&right_position)
|
||||
.is_le()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -7570,12 +7752,15 @@ impl Editor {
|
|||
display_snapshot: &DisplaySnapshot,
|
||||
theme: &Theme,
|
||||
) -> Vec<(Range<DisplayPoint>, Color)> {
|
||||
let search_range = display_snapshot.anchor_to_inlay_offset(search_range.start)
|
||||
..display_snapshot.anchor_to_inlay_offset(search_range.end);
|
||||
let mut results = Vec::new();
|
||||
let buffer = &display_snapshot.buffer_snapshot;
|
||||
for (color_fetcher, ranges) in self.background_highlights.values() {
|
||||
let color = color_fetcher(theme);
|
||||
let start_ix = match ranges.binary_search_by(|probe| {
|
||||
let cmp = probe.end.cmp(&search_range.start, buffer);
|
||||
let cmp = document_to_inlay_range(probe, display_snapshot)
|
||||
.end
|
||||
.cmp(&search_range.start);
|
||||
if cmp.is_gt() {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
|
@ -7585,80 +7770,36 @@ impl Editor {
|
|||
Ok(i) | Err(i) => i,
|
||||
};
|
||||
for range in &ranges[start_ix..] {
|
||||
if range.start.cmp(&search_range.end, buffer).is_ge() {
|
||||
let range = document_to_inlay_range(range, display_snapshot);
|
||||
if range.start.cmp(&search_range.end).is_ge() {
|
||||
break;
|
||||
}
|
||||
let start = range
|
||||
.start
|
||||
.to_point(buffer)
|
||||
.to_display_point(display_snapshot);
|
||||
let end = range
|
||||
.end
|
||||
.to_point(buffer)
|
||||
.to_display_point(display_snapshot);
|
||||
|
||||
let start = display_snapshot.inlay_offset_to_display_point(range.start, Bias::Left);
|
||||
let end = display_snapshot.inlay_offset_to_display_point(range.end, Bias::Right);
|
||||
results.push((start..end, color))
|
||||
}
|
||||
}
|
||||
results
|
||||
}
|
||||
|
||||
pub fn background_highlights_in_range_for<T: 'static>(
|
||||
&self,
|
||||
search_range: Range<Anchor>,
|
||||
display_snapshot: &DisplaySnapshot,
|
||||
theme: &Theme,
|
||||
) -> Vec<(Range<DisplayPoint>, Color)> {
|
||||
let mut results = Vec::new();
|
||||
let buffer = &display_snapshot.buffer_snapshot;
|
||||
let Some((color_fetcher, ranges)) = self.background_highlights
|
||||
.get(&TypeId::of::<T>()) else {
|
||||
return vec![];
|
||||
};
|
||||
|
||||
let color = color_fetcher(theme);
|
||||
let start_ix = match ranges.binary_search_by(|probe| {
|
||||
let cmp = probe.end.cmp(&search_range.start, buffer);
|
||||
if cmp.is_gt() {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
Ordering::Less
|
||||
}
|
||||
}) {
|
||||
Ok(i) | Err(i) => i,
|
||||
};
|
||||
for range in &ranges[start_ix..] {
|
||||
if range.start.cmp(&search_range.end, buffer).is_ge() {
|
||||
break;
|
||||
}
|
||||
let start = range
|
||||
.start
|
||||
.to_point(buffer)
|
||||
.to_display_point(display_snapshot);
|
||||
let end = range
|
||||
.end
|
||||
.to_point(buffer)
|
||||
.to_display_point(display_snapshot);
|
||||
results.push((start..end, color))
|
||||
}
|
||||
|
||||
results
|
||||
}
|
||||
|
||||
pub fn background_highlight_row_ranges<T: 'static>(
|
||||
&self,
|
||||
search_range: Range<Anchor>,
|
||||
display_snapshot: &DisplaySnapshot,
|
||||
count: usize,
|
||||
) -> Vec<RangeInclusive<DisplayPoint>> {
|
||||
let search_range = display_snapshot.anchor_to_inlay_offset(search_range.start)
|
||||
..display_snapshot.anchor_to_inlay_offset(search_range.end);
|
||||
let mut results = Vec::new();
|
||||
let buffer = &display_snapshot.buffer_snapshot;
|
||||
let Some((_, ranges)) = self.background_highlights
|
||||
.get(&TypeId::of::<T>()) else {
|
||||
return vec![];
|
||||
};
|
||||
let Some((_, ranges)) = self.background_highlights.get(&TypeId::of::<T>()) else {
|
||||
return vec![];
|
||||
};
|
||||
|
||||
let start_ix = match ranges.binary_search_by(|probe| {
|
||||
let cmp = probe.end.cmp(&search_range.start, buffer);
|
||||
let cmp = document_to_inlay_range(probe, display_snapshot)
|
||||
.end
|
||||
.cmp(&search_range.start);
|
||||
if cmp.is_gt() {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
|
@ -7678,19 +7819,24 @@ impl Editor {
|
|||
let mut start_row: Option<Point> = None;
|
||||
let mut end_row: Option<Point> = None;
|
||||
if ranges.len() > count {
|
||||
return vec![];
|
||||
return Vec::new();
|
||||
}
|
||||
for range in &ranges[start_ix..] {
|
||||
if range.start.cmp(&search_range.end, buffer).is_ge() {
|
||||
let range = document_to_inlay_range(range, display_snapshot);
|
||||
if range.start.cmp(&search_range.end).is_ge() {
|
||||
break;
|
||||
}
|
||||
let end = range.end.to_point(buffer);
|
||||
let end = display_snapshot
|
||||
.inlay_offset_to_display_point(range.end, Bias::Right)
|
||||
.to_point(display_snapshot);
|
||||
if let Some(current_row) = &end_row {
|
||||
if end.row == current_row.row {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let start = range.start.to_point(buffer);
|
||||
let start = display_snapshot
|
||||
.inlay_offset_to_display_point(range.start, Bias::Left)
|
||||
.to_point(display_snapshot);
|
||||
|
||||
if start_row.is_none() {
|
||||
assert_eq!(end_row, None);
|
||||
|
@ -7728,24 +7874,32 @@ impl Editor {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn highlight_inlays<T: 'static>(
|
||||
&mut self,
|
||||
ranges: Vec<InlayRange>,
|
||||
style: HighlightStyle,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.display_map.update(cx, |map, _| {
|
||||
map.highlight_inlays(TypeId::of::<T>(), ranges, style)
|
||||
});
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn text_highlights<'a, T: 'static>(
|
||||
&'a self,
|
||||
cx: &'a AppContext,
|
||||
) -> Option<(HighlightStyle, &'a [Range<Anchor>])> {
|
||||
) -> Option<(HighlightStyle, &'a [DocumentRange])> {
|
||||
self.display_map.read(cx).text_highlights(TypeId::of::<T>())
|
||||
}
|
||||
|
||||
pub fn clear_text_highlights<T: 'static>(
|
||||
&mut self,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<Arc<(HighlightStyle, Vec<Range<Anchor>>)>> {
|
||||
let highlights = self
|
||||
pub fn clear_text_highlights<T: 'static>(&mut self, cx: &mut ViewContext<Self>) {
|
||||
let text_highlights = self
|
||||
.display_map
|
||||
.update(cx, |map, _| map.clear_text_highlights(TypeId::of::<T>()));
|
||||
if highlights.is_some() {
|
||||
if text_highlights.is_some() {
|
||||
cx.notify();
|
||||
}
|
||||
highlights
|
||||
}
|
||||
|
||||
pub fn show_local_cursors(&self, cx: &AppContext) -> bool {
|
||||
|
@ -7763,7 +7917,9 @@ impl Editor {
|
|||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
match event {
|
||||
multi_buffer::Event::Edited => {
|
||||
multi_buffer::Event::Edited {
|
||||
sigleton_buffer_edited,
|
||||
} => {
|
||||
self.refresh_active_diagnostics(cx);
|
||||
self.refresh_code_actions(cx);
|
||||
if self.has_active_copilot_suggestion(cx) {
|
||||
|
@ -7771,30 +7927,32 @@ impl Editor {
|
|||
}
|
||||
cx.emit(Event::BufferEdited);
|
||||
|
||||
if let Some(project) = &self.project {
|
||||
let project = project.read(cx);
|
||||
let languages_affected = multibuffer
|
||||
.read(cx)
|
||||
.all_buffers()
|
||||
.into_iter()
|
||||
.filter_map(|buffer| {
|
||||
let buffer = buffer.read(cx);
|
||||
let language = buffer.language()?;
|
||||
if project.is_local()
|
||||
&& project.language_servers_for_buffer(buffer, cx).count() == 0
|
||||
{
|
||||
None
|
||||
} else {
|
||||
Some(language)
|
||||
}
|
||||
})
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>();
|
||||
if !languages_affected.is_empty() {
|
||||
self.refresh_inlay_hints(
|
||||
InlayHintRefreshReason::BufferEdited(languages_affected),
|
||||
cx,
|
||||
);
|
||||
if *sigleton_buffer_edited {
|
||||
if let Some(project) = &self.project {
|
||||
let project = project.read(cx);
|
||||
let languages_affected = multibuffer
|
||||
.read(cx)
|
||||
.all_buffers()
|
||||
.into_iter()
|
||||
.filter_map(|buffer| {
|
||||
let buffer = buffer.read(cx);
|
||||
let language = buffer.language()?;
|
||||
if project.is_local()
|
||||
&& project.language_servers_for_buffer(buffer, cx).count() == 0
|
||||
{
|
||||
None
|
||||
} else {
|
||||
Some(language)
|
||||
}
|
||||
})
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>();
|
||||
if !languages_affected.is_empty() {
|
||||
self.refresh_inlay_hints(
|
||||
InlayHintRefreshReason::BufferEdited(languages_affected),
|
||||
cx,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7802,12 +7960,16 @@ impl Editor {
|
|||
buffer,
|
||||
predecessor,
|
||||
excerpts,
|
||||
} => cx.emit(Event::ExcerptsAdded {
|
||||
buffer: buffer.clone(),
|
||||
predecessor: *predecessor,
|
||||
excerpts: excerpts.clone(),
|
||||
}),
|
||||
} => {
|
||||
cx.emit(Event::ExcerptsAdded {
|
||||
buffer: buffer.clone(),
|
||||
predecessor: *predecessor,
|
||||
excerpts: excerpts.clone(),
|
||||
});
|
||||
self.refresh_inlay_hints(InlayHintRefreshReason::NewLinesShown, cx);
|
||||
}
|
||||
multi_buffer::Event::ExcerptsRemoved { ids } => {
|
||||
self.refresh_inlay_hints(InlayHintRefreshReason::ExcerptsRemoved(ids.clone()), cx);
|
||||
cx.emit(Event::ExcerptsRemoved { ids: ids.clone() })
|
||||
}
|
||||
multi_buffer::Event::Reparsed => cx.emit(Event::Reparsed),
|
||||
|
@ -7952,6 +8114,7 @@ impl Editor {
|
|||
Some(
|
||||
ranges
|
||||
.iter()
|
||||
.filter_map(|range| range.as_text_range())
|
||||
.map(move |range| {
|
||||
range.start.to_offset_utf16(&snapshot)..range.end.to_offset_utf16(&snapshot)
|
||||
})
|
||||
|
@ -7990,9 +8153,7 @@ impl Editor {
|
|||
suggestion_accepted: bool,
|
||||
cx: &AppContext,
|
||||
) {
|
||||
let Some(project) = &self.project else {
|
||||
return
|
||||
};
|
||||
let Some(project) = &self.project else { return };
|
||||
|
||||
// If None, we are either getting suggestions in a new, unsaved file, or in a file without an extension
|
||||
let file_extension = self
|
||||
|
@ -8021,9 +8182,7 @@ impl Editor {
|
|||
file_extension: Option<String>,
|
||||
cx: &AppContext,
|
||||
) {
|
||||
let Some(project) = &self.project else {
|
||||
return
|
||||
};
|
||||
let Some(project) = &self.project else { return };
|
||||
|
||||
// If None, we are in a file without an extension
|
||||
let file = self
|
||||
|
@ -8124,7 +8283,9 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
|
||||
let Some(lines) = serde_json::to_string_pretty(&lines).log_err() else { return; };
|
||||
let Some(lines) = serde_json::to_string_pretty(&lines).log_err() else {
|
||||
return;
|
||||
};
|
||||
cx.write_to_clipboard(ClipboardItem::new(lines));
|
||||
}
|
||||
|
||||
|
@ -8133,6 +8294,19 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
|
||||
fn document_to_inlay_range(
|
||||
range: &DocumentRange,
|
||||
snapshot: &DisplaySnapshot,
|
||||
) -> Range<InlayOffset> {
|
||||
match range {
|
||||
DocumentRange::Text(text_range) => {
|
||||
snapshot.anchor_to_inlay_offset(text_range.start)
|
||||
..snapshot.anchor_to_inlay_offset(text_range.end)
|
||||
}
|
||||
DocumentRange::Inlay(inlay_range) => inlay_range.highlight_start..inlay_range.highlight_end,
|
||||
}
|
||||
}
|
||||
|
||||
fn inlay_hint_settings(
|
||||
location: Anchor,
|
||||
snapshot: &MultiBufferSnapshot,
|
||||
|
@ -8317,14 +8491,11 @@ impl View for Editor {
|
|||
) -> bool {
|
||||
let pending_selection = self.has_pending_selection();
|
||||
|
||||
if let Some(point) = self.link_go_to_definition_state.last_mouse_location.clone() {
|
||||
if let Some(point) = &self.link_go_to_definition_state.last_trigger_point {
|
||||
if event.cmd && !pending_selection {
|
||||
let point = point.clone();
|
||||
let snapshot = self.snapshot(cx);
|
||||
let kind = if event.shift {
|
||||
LinkDefinitionKind::Type
|
||||
} else {
|
||||
LinkDefinitionKind::Symbol
|
||||
};
|
||||
let kind = point.definition_kind(event.shift);
|
||||
|
||||
show_link_definition(kind, self, point, snapshot, cx);
|
||||
return false;
|
||||
|
@ -8408,6 +8579,7 @@ impl View for Editor {
|
|||
fn marked_text_range(&self, cx: &AppContext) -> Option<Range<usize>> {
|
||||
let snapshot = self.buffer.read(cx).read(cx);
|
||||
let range = self.text_highlights::<InputComposition>(cx)?.1.get(0)?;
|
||||
let range = range.as_text_range()?;
|
||||
Some(range.start.to_offset_utf16(&snapshot).0..range.end.to_offset_utf16(&snapshot).0)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue