Increase the context in other multibuffers (#10582)

This moves the diagnostics and find all references to be in line with
the search pane. This also centralizes the constant into the editor code
base.

Release Notes:

- Increased diagnostic context to match the project search context.
This commit is contained in:
Mikayla Maki 2024-04-15 14:44:14 -07:00 committed by GitHub
parent 7a112b22ac
commit 4d314b2dd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 15 deletions

View File

@ -44,8 +44,6 @@ use workspace::{
actions!(diagnostics, [Deploy, ToggleWarnings]); actions!(diagnostics, [Deploy, ToggleWarnings]);
const CONTEXT_LINE_COUNT: u32 = 1;
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
ProjectDiagnosticsSettings::register(cx); ProjectDiagnosticsSettings::register(cx);
cx.observe_new_views(ProjectDiagnosticsEditor::register) cx.observe_new_views(ProjectDiagnosticsEditor::register)
@ -63,6 +61,7 @@ struct ProjectDiagnosticsEditor {
paths_to_update: HashMap<LanguageServerId, HashSet<ProjectPath>>, paths_to_update: HashMap<LanguageServerId, HashSet<ProjectPath>>,
current_diagnostics: HashMap<LanguageServerId, HashSet<ProjectPath>>, current_diagnostics: HashMap<LanguageServerId, HashSet<ProjectPath>>,
include_warnings: bool, include_warnings: bool,
context: u32,
_subscriptions: Vec<Subscription>, _subscriptions: Vec<Subscription>,
} }
@ -116,7 +115,8 @@ impl ProjectDiagnosticsEditor {
workspace.register_action(Self::deploy); workspace.register_action(Self::deploy);
} }
fn new( fn new_with_context(
context: u32,
project_handle: Model<Project>, project_handle: Model<Project>,
workspace: WeakView<Workspace>, workspace: WeakView<Workspace>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
@ -181,6 +181,7 @@ impl ProjectDiagnosticsEditor {
let summary = project.diagnostic_summary(false, cx); let summary = project.diagnostic_summary(false, cx);
let mut this = Self { let mut this = Self {
project: project_handle, project: project_handle,
context,
summary, summary,
workspace, workspace,
excerpts, excerpts,
@ -200,6 +201,19 @@ impl ProjectDiagnosticsEditor {
this this
} }
fn new(
project_handle: Model<Project>,
workspace: WeakView<Workspace>,
cx: &mut ViewContext<Self>,
) -> Self {
Self::new_with_context(
editor::DEFAULT_MULTIBUFFER_CONTEXT,
project_handle,
workspace,
cx,
)
}
fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext<Workspace>) { fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext<Workspace>) {
if let Some(existing) = workspace.item_of_type::<ProjectDiagnosticsEditor>(cx) { if let Some(existing) = workspace.item_of_type::<ProjectDiagnosticsEditor>(cx) {
workspace.activate_item(&existing, cx); workspace.activate_item(&existing, cx);
@ -430,18 +444,16 @@ impl ProjectDiagnosticsEditor {
let resolved_entry = entry.map(|e| e.resolve::<Point>(&snapshot)); let resolved_entry = entry.map(|e| e.resolve::<Point>(&snapshot));
if let Some((range, start_ix)) = &mut pending_range { if let Some((range, start_ix)) = &mut pending_range {
if let Some(entry) = resolved_entry.as_ref() { if let Some(entry) = resolved_entry.as_ref() {
if entry.range.start.row if entry.range.start.row <= range.end.row + 1 + self.context * 2 {
<= range.end.row + 1 + CONTEXT_LINE_COUNT * 2
{
range.end = range.end.max(entry.range.end); range.end = range.end.max(entry.range.end);
continue; continue;
} }
} }
let excerpt_start = let excerpt_start =
Point::new(range.start.row.saturating_sub(CONTEXT_LINE_COUNT), 0); Point::new(range.start.row.saturating_sub(self.context), 0);
let excerpt_end = snapshot.clip_point( let excerpt_end = snapshot.clip_point(
Point::new(range.end.row + CONTEXT_LINE_COUNT, u32::MAX), Point::new(range.end.row + self.context, u32::MAX),
Bias::Left, Bias::Left,
); );
let excerpt_id = excerpts let excerpt_id = excerpts
@ -1030,7 +1042,12 @@ mod tests {
// Open the project diagnostics view while there are already diagnostics. // Open the project diagnostics view while there are already diagnostics.
let view = window.build_view(cx, |cx| { let view = window.build_view(cx, |cx| {
ProjectDiagnosticsEditor::new(project.clone(), workspace.downgrade(), cx) ProjectDiagnosticsEditor::new_with_context(
1,
project.clone(),
workspace.downgrade(),
cx,
)
}); });
view.next_notification(cx).await; view.next_notification(cx).await;
@ -1340,7 +1357,12 @@ mod tests {
let workspace = window.root(cx).unwrap(); let workspace = window.root(cx).unwrap();
let view = window.build_view(cx, |cx| { let view = window.build_view(cx, |cx| {
ProjectDiagnosticsEditor::new(project.clone(), workspace.downgrade(), cx) ProjectDiagnosticsEditor::new_with_context(
1,
project.clone(),
workspace.downgrade(),
cx,
)
}); });
// Two language servers start updating diagnostics // Two language servers start updating diagnostics

View File

@ -138,6 +138,7 @@ use workspace::{
use crate::hover_links::find_url; use crate::hover_links::find_url;
pub const DEFAULT_MULTIBUFFER_CONTEXT: u32 = 2;
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500); const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
const MAX_LINE_LEN: usize = 1024; const MAX_LINE_LEN: usize = 1024;
const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10; const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10;
@ -3738,7 +3739,7 @@ impl Editor {
buffer buffer
.edited_ranges_for_transaction::<usize>(transaction) .edited_ranges_for_transaction::<usize>(transaction)
.collect(), .collect(),
1, DEFAULT_MULTIBUFFER_CONTEXT,
cx, cx,
), ),
); );
@ -8007,7 +8008,7 @@ impl Editor {
ranges_to_highlight.extend(multibuffer.push_excerpts_with_context_lines( ranges_to_highlight.extend(multibuffer.push_excerpts_with_context_lines(
location.buffer.clone(), location.buffer.clone(),
ranges_for_buffer, ranges_for_buffer,
1, DEFAULT_MULTIBUFFER_CONTEXT,
cx, cx,
)) ))
} }

View File

@ -54,8 +54,6 @@ struct ActiveSettings(HashMap<WeakModel<Project>, ProjectSearchSettings>);
impl Global for ActiveSettings {} impl Global for ActiveSettings {}
const SEARCH_CONTEXT: u32 = 2;
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.set_global(ActiveSettings::default()); cx.set_global(ActiveSettings::default());
cx.observe_new_views(|workspace: &mut Workspace, _cx| { cx.observe_new_views(|workspace: &mut Workspace, _cx| {
@ -234,7 +232,7 @@ impl ProjectSearch {
excerpts.stream_excerpts_with_context_lines( excerpts.stream_excerpts_with_context_lines(
buffer, buffer,
ranges, ranges,
SEARCH_CONTEXT, editor::DEFAULT_MULTIBUFFER_CONTEXT,
cx, cx,
) )
}) })