Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ file_retrieval_tools = []
get_started_tab = []
code_mode_chip = []
github_pr_prompt_chip = []
code_review_comments_chip = []
create_project_flow = []
agent_mode_evals = [
"integration_tests",
Expand Down
22 changes: 22 additions & 0 deletions app/src/ai/agent/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ impl ReviewComment {
.unwrap_or_else(|| "Review Comment".to_string()),
}
}

/// A one-line summary of the comment used for compact list rows.
///
/// This shows the actual comment text (rather than its file/line location),
/// collapsing any internal whitespace/newlines into single spaces so it renders
/// on a single line, and hard-truncating to `max_chars` with an ellipsis as a
/// defensive bound. Falls back to [`Self::title`] when the comment has no body.
pub fn summary(&self, max_chars: usize) -> String {
let collapsed = self
.content
.split_whitespace()
.collect::<Vec<_>>()
.join(" ");
if collapsed.is_empty() {
return self.title();
}
crate::util::truncation::truncate_from_end(&collapsed, max_chars)
}
}

impl From<crate::code_review::comments::AttachedReviewComment> for ReviewComment {
Expand Down Expand Up @@ -100,3 +118,7 @@ pub struct ReviewDiff {
pub file_path: Option<LocalOrRemotePath>,
pub line_number: Option<usize>,
}

#[cfg(test)]
#[path = "comment_tests.rs"]
mod tests;
44 changes: 44 additions & 0 deletions app/src/ai/agent/comment_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use crate::ai::agent::comment::{ReviewComment, ReviewDiff};
use crate::code_review::comments::CommentId;

fn comment(content: &str, head_title: Option<&str>) -> ReviewComment {
ReviewComment {
id: CommentId::default(),
content: content.to_string(),
diff: ReviewDiff {
file_path: None,
line_number: None,
},
head_title: head_title.map(str::to_string),
}
}

#[test]
fn summary_shows_comment_text_when_short() {
let c = comment("Please rename this variable", None);
assert_eq!(c.summary(80), "Please rename this variable");
}

#[test]
fn summary_truncates_long_text_with_ellipsis() {
let c = comment("abcdefghij", None);
// truncate_from_end keeps max_chars - 1 chars and appends the ellipsis glyph.
assert_eq!(c.summary(4), "abc…");
}

#[test]
fn summary_collapses_whitespace_into_single_line() {
let c = comment("first line\n\nsecond line\tthird", None);
assert_eq!(c.summary(80), "first line second line third");
}

#[test]
fn summary_falls_back_to_title_when_content_is_empty() {
// Empty (whitespace-only) content and no file/line -> falls back to head_title.
let c = comment(" \n ", Some("PR summary"));
assert_eq!(c.summary(80), "PR summary");

// No head title either -> generic title.
let c = comment("", None);
assert_eq!(c.summary(80), "Review Comment");
}
6 changes: 6 additions & 0 deletions app/src/ai/agent/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3175,6 +3175,12 @@ impl AIConversation {
self.todo_lists.last()
}

/// Returns the current code review state for this conversation, if any
/// comments have ever been sent to the agent.
pub fn code_review(&self) -> Option<&CodeReview> {
self.code_review.as_ref()
}

pub fn active_todo(&self) -> Option<&AIAgentTodo> {
self.active_todo_list()
.and_then(|todo_list| todo_list.in_progress_item())
Expand Down
1 change: 1 addition & 0 deletions app/src/ai/blocklist/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::util::color::coloru_with_opacity;
use crate::view_components::action_button::{ActionButtonTheme, NakedTheme};
use crate::Appearance;

pub mod code_review_comments;
pub mod plan_and_todo_list;
pub mod prompt_alert;

Expand Down
Loading
Loading