Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve context expansion #10957

Merged
merged 19 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/icons/arrow_down_from_line.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/arrow_up_from_line.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
"wrap_guides": [],
// Hide the values of in variables from visual display in private files
"redact_private_values": false,
// The default number of lines to expand excerpts in the multibuffer by.
"expand_excerpt_lines": 3,
// Globs to match against file paths to determine if a file is private.
"private_files": [
"**/.env*",
Expand Down
2 changes: 1 addition & 1 deletion crates/assistant2/src/tools/annotate_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl ToolView for AnnotationResultView {
MultiBuffer::new(0, language::Capability::ReadWrite).with_title(String::new())
});
let editor = cx.new_view(|cx| {
Editor::for_multibuffer(multibuffer.clone(), Some(self.project.clone()), cx)
Editor::for_multibuffer(multibuffer.clone(), Some(self.project.clone()), true, cx)
});

self.editor = Some(editor.clone());
Expand Down
5 changes: 3 additions & 2 deletions crates/auto_update/src/auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@ fn view_release_notes_locally(workspace: &mut Workspace, cx: &mut ViewContext<Wo
let buffer = cx.new_model(|cx| MultiBuffer::singleton(buffer, cx));

let tab_description = SharedString::from(body.title.to_string());
let editor = cx
.new_view(|cx| Editor::for_multibuffer(buffer, Some(project), cx));
let editor = cx.new_view(|cx| {
Editor::for_multibuffer(buffer, Some(project), true, cx)
});
let workspace_handle = workspace.weak_handle();
let view: View<MarkdownPreviewView> = MarkdownPreviewView::new(
MarkdownPreviewMode::Default,
Expand Down
5 changes: 3 additions & 2 deletions crates/collab/src/tests/following_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,9 @@ async fn test_basic_following(
result
});
let multibuffer_editor_a = workspace_a.update(cx_a, |workspace, cx| {
let editor =
cx.new_view(|cx| Editor::for_multibuffer(multibuffer_a, Some(project_a.clone()), cx));
let editor = cx.new_view(|cx| {
Editor::for_multibuffer(multibuffer_a, Some(project_a.clone()), true, cx)
});
workspace.add_item_to_active_pane(Box::new(editor.clone()), None, cx);
editor
});
Expand Down
12 changes: 6 additions & 6 deletions crates/copilot/src/copilot_completion_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ mod tests {
);
multibuffer
});
let editor = cx.add_window(|cx| Editor::for_multibuffer(multibuffer, None, cx));
let editor = cx.add_window(|cx| Editor::for_multibuffer(multibuffer, None, true, cx));
editor.update(cx, |editor, cx| editor.focus(cx)).unwrap();
let copilot_provider = cx.new_model(|_| CopilotCompletionProvider::new(copilot));
editor
Expand Down Expand Up @@ -811,7 +811,7 @@ mod tests {
assert!(editor.has_active_inline_completion(cx));
assert_eq!(
editor.display_text(cx),
"\n\na = 1\nb = 2 + a\n\n\n\nc = 3\nd = 4\n"
"\n\n\na = 1\nb = 2 + a\n\n\n\n\n\nc = 3\nd = 4\n\n"
);
assert_eq!(editor.text(cx), "a = 1\nb = 2\n\nc = 3\nd = 4\n");
});
Expand All @@ -833,7 +833,7 @@ mod tests {
assert!(!editor.has_active_inline_completion(cx));
assert_eq!(
editor.display_text(cx),
"\n\na = 1\nb = 2\n\n\n\nc = 3\nd = 4\n"
"\n\n\na = 1\nb = 2\n\n\n\n\n\nc = 3\nd = 4\n\n"
);
assert_eq!(editor.text(cx), "a = 1\nb = 2\n\nc = 3\nd = 4\n");

Expand All @@ -842,7 +842,7 @@ mod tests {
assert!(!editor.has_active_inline_completion(cx));
assert_eq!(
editor.display_text(cx),
"\n\na = 1\nb = 2\n\n\n\nc = 3\nd = 4 \n"
"\n\n\na = 1\nb = 2\n\n\n\n\n\nc = 3\nd = 4 \n\n"
);
assert_eq!(editor.text(cx), "a = 1\nb = 2\n\nc = 3\nd = 4 \n");
});
Expand All @@ -853,7 +853,7 @@ mod tests {
assert!(editor.has_active_inline_completion(cx));
assert_eq!(
editor.display_text(cx),
"\n\na = 1\nb = 2\n\n\n\nc = 3\nd = 4 + c\n"
"\n\n\na = 1\nb = 2\n\n\n\n\n\nc = 3\nd = 4 + c\n\n"
);
assert_eq!(editor.text(cx), "a = 1\nb = 2\n\nc = 3\nd = 4 \n");
});
Expand Down Expand Up @@ -1032,7 +1032,7 @@ mod tests {
);
multibuffer
});
let editor = cx.add_window(|cx| Editor::for_multibuffer(multibuffer, None, cx));
let editor = cx.add_window(|cx| Editor::for_multibuffer(multibuffer, None, true, cx));
let copilot_provider = cx.new_model(|_| CopilotCompletionProvider::new(copilot));
editor
.update(cx, |editor, cx| {
Expand Down
6 changes: 4 additions & 2 deletions crates/diagnostics/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl ProjectDiagnosticsEditor {
});
let editor = cx.new_view(|cx| {
let mut editor =
Editor::for_multibuffer(excerpts.clone(), Some(project_handle.clone()), cx);
Editor::for_multibuffer(excerpts.clone(), Some(project_handle.clone()), false, cx);
editor.set_vertical_scroll_margin(5, cx);
editor
});
Expand Down Expand Up @@ -792,13 +792,15 @@ impl Item for ProjectDiagnosticsEditor {
}
}

const DIAGNOSTIC_HEADER: &'static str = "diagnostic header";

fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
let (message, code_ranges) = highlight_diagnostic_message(&diagnostic);
let message: SharedString = message;
Box::new(move |cx| {
let highlight_style: HighlightStyle = cx.theme().colors().text_accent.into();
h_flex()
.id("diagnostic header")
.id(DIAGNOSTIC_HEADER)
.py_2()
.pl_10()
.pr_5()
Expand Down
79 changes: 42 additions & 37 deletions crates/diagnostics/src/diagnostics_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ async fn test_diagnostics(cx: &mut TestAppContext) {
assert_eq!(
editor_blocks(&editor, cx),
[
(DisplayRow(0), "path header block".into()),
(DisplayRow(2), "diagnostic header".into()),
(DisplayRow(15), "collapsed context".into()),
(DisplayRow(16), "diagnostic header".into()),
(DisplayRow(25), "collapsed context".into()),
(DisplayRow(0), FILE_HEADER.into()),
(DisplayRow(2), DIAGNOSTIC_HEADER.into()),
(DisplayRow(15), EXCERPT_HEADER.into()),
(DisplayRow(16), DIAGNOSTIC_HEADER.into()),
(DisplayRow(25), EXCERPT_HEADER.into()),
]
);
assert_eq!(
Expand Down Expand Up @@ -243,13 +243,13 @@ async fn test_diagnostics(cx: &mut TestAppContext) {
assert_eq!(
editor_blocks(&editor, cx),
[
(DisplayRow(0), "path header block".into()),
(DisplayRow(2), "diagnostic header".into()),
(DisplayRow(7), "path header block".into()),
(DisplayRow(9), "diagnostic header".into()),
(DisplayRow(22), "collapsed context".into()),
(DisplayRow(23), "diagnostic header".into()),
(DisplayRow(32), "collapsed context".into()),
(DisplayRow(0), FILE_HEADER.into()),
(DisplayRow(2), DIAGNOSTIC_HEADER.into()),
(DisplayRow(7), FILE_HEADER.into()),
(DisplayRow(9), DIAGNOSTIC_HEADER.into()),
(DisplayRow(22), EXCERPT_HEADER.into()),
(DisplayRow(23), DIAGNOSTIC_HEADER.into()),
(DisplayRow(32), EXCERPT_HEADER.into()),
]
);

Expand Down Expand Up @@ -355,15 +355,15 @@ async fn test_diagnostics(cx: &mut TestAppContext) {
assert_eq!(
editor_blocks(&editor, cx),
[
(DisplayRow(0), "path header block".into()),
(DisplayRow(2), "diagnostic header".into()),
(DisplayRow(7), "collapsed context".into()),
(DisplayRow(8), "diagnostic header".into()),
(DisplayRow(13), "path header block".into()),
(DisplayRow(15), "diagnostic header".into()),
(DisplayRow(28), "collapsed context".into()),
(DisplayRow(29), "diagnostic header".into()),
(DisplayRow(38), "collapsed context".into()),
(DisplayRow(0), FILE_HEADER.into()),
(DisplayRow(2), DIAGNOSTIC_HEADER.into()),
(DisplayRow(7), EXCERPT_HEADER.into()),
(DisplayRow(8), DIAGNOSTIC_HEADER.into()),
(DisplayRow(13), FILE_HEADER.into()),
(DisplayRow(15), DIAGNOSTIC_HEADER.into()),
(DisplayRow(28), EXCERPT_HEADER.into()),
(DisplayRow(29), DIAGNOSTIC_HEADER.into()),
(DisplayRow(38), EXCERPT_HEADER.into()),
]
);

Expand Down Expand Up @@ -493,8 +493,8 @@ async fn test_diagnostics_multiple_servers(cx: &mut TestAppContext) {
assert_eq!(
editor_blocks(&editor, cx),
[
(DisplayRow(0), "path header block".into()),
(DisplayRow(2), "diagnostic header".into()),
(DisplayRow(0), FILE_HEADER.into()),
(DisplayRow(2), DIAGNOSTIC_HEADER.into()),
]
);
assert_eq!(
Expand Down Expand Up @@ -539,10 +539,10 @@ async fn test_diagnostics_multiple_servers(cx: &mut TestAppContext) {
assert_eq!(
editor_blocks(&editor, cx),
[
(DisplayRow(0), "path header block".into()),
(DisplayRow(2), "diagnostic header".into()),
(DisplayRow(6), "collapsed context".into()),
(DisplayRow(7), "diagnostic header".into()),
(DisplayRow(0), FILE_HEADER.into()),
(DisplayRow(2), DIAGNOSTIC_HEADER.into()),
(DisplayRow(6), EXCERPT_HEADER.into()),
(DisplayRow(7), DIAGNOSTIC_HEADER.into()),
]
);
assert_eq!(
Expand Down Expand Up @@ -605,10 +605,10 @@ async fn test_diagnostics_multiple_servers(cx: &mut TestAppContext) {
assert_eq!(
editor_blocks(&editor, cx),
[
(DisplayRow(0), "path header block".into()),
(DisplayRow(2), "diagnostic header".into()),
(DisplayRow(7), "collapsed context".into()),
(DisplayRow(8), "diagnostic header".into()),
(DisplayRow(0), FILE_HEADER.into()),
(DisplayRow(2), DIAGNOSTIC_HEADER.into()),
(DisplayRow(7), EXCERPT_HEADER.into()),
(DisplayRow(8), DIAGNOSTIC_HEADER.into()),
]
);
assert_eq!(
Expand Down Expand Up @@ -661,10 +661,10 @@ async fn test_diagnostics_multiple_servers(cx: &mut TestAppContext) {
assert_eq!(
editor_blocks(&editor, cx),
[
(DisplayRow(0), "path header block".into()),
(DisplayRow(2), "diagnostic header".into()),
(DisplayRow(7), "collapsed context".into()),
(DisplayRow(8), "diagnostic header".into()),
(DisplayRow(0), FILE_HEADER.into()),
(DisplayRow(2), DIAGNOSTIC_HEADER.into()),
(DisplayRow(7), EXCERPT_HEADER.into()),
(DisplayRow(8), DIAGNOSTIC_HEADER.into()),
]
);
assert_eq!(
Expand Down Expand Up @@ -958,6 +958,10 @@ fn random_diagnostic(
}
}

const FILE_HEADER: &'static str = "file header";
const EXCERPT_HEADER: &'static str = "excerpt header";
const EXCERPT_FOOTER: &'static str = "excerpt footer";

fn editor_blocks(
editor: &View<Editor>,
cx: &mut VisualTestContext,
Expand Down Expand Up @@ -996,11 +1000,12 @@ fn editor_blocks(
starts_new_buffer, ..
} => {
if *starts_new_buffer {
"path header block".into()
FILE_HEADER.into()
} else {
"collapsed context".into()
EXCERPT_HEADER.into()
}
}
TransformBlock::ExcerptFooter { .. } => EXCERPT_FOOTER.into(),
};

Some((row, name))
Expand Down
14 changes: 14 additions & 0 deletions crates/editor/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,26 @@ pub struct ExpandExcerpts {
pub(super) lines: u32,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
pub struct ExpandExcerptsUp {
#[serde(default)]
pub(super) lines: u32,
}

#[derive(PartialEq, Clone, Deserialize, Default)]
pub struct ExpandExcerptsDown {
#[serde(default)]
pub(super) lines: u32,
}

impl_actions!(
editor,
[
ConfirmCodeAction,
ConfirmCompletion,
ExpandExcerpts,
ExpandExcerptsUp,
ExpandExcerptsDown,
FoldAt,
MoveDownByLines,
MovePageDown,
Expand Down