Truncate multi-line debug value hints (#34305)
Release Notes: - Multi-line debug inline values are now truncated. Co-authored-by: Anthony Eid <hello@anthonyeid.me>
This commit is contained in:
parent
90bf602ceb
commit
0bd65829f7
3 changed files with 40 additions and 3 deletions
|
@ -2241,3 +2241,34 @@ func main() {
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_trim_multi_line_inline_value(executor: BackgroundExecutor, cx: &mut TestAppContext) {
|
||||||
|
let variables = [("y", "hello\n world")];
|
||||||
|
|
||||||
|
let before = r#"
|
||||||
|
fn main() {
|
||||||
|
let y = "hello\n world";
|
||||||
|
}
|
||||||
|
"#
|
||||||
|
.unindent();
|
||||||
|
|
||||||
|
let after = r#"
|
||||||
|
fn main() {
|
||||||
|
let y: hello… = "hello\n world";
|
||||||
|
}
|
||||||
|
"#
|
||||||
|
.unindent();
|
||||||
|
|
||||||
|
test_inline_values_util(
|
||||||
|
&variables,
|
||||||
|
&[],
|
||||||
|
&before,
|
||||||
|
&after,
|
||||||
|
None,
|
||||||
|
rust_lang(),
|
||||||
|
executor,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
|
@ -19655,8 +19655,9 @@ impl Editor {
|
||||||
Anchor::in_buffer(excerpt_id, buffer_id, hint.position),
|
Anchor::in_buffer(excerpt_id, buffer_id, hint.position),
|
||||||
hint.text(),
|
hint.text(),
|
||||||
);
|
);
|
||||||
|
if !inlay.text.chars().contains(&'\n') {
|
||||||
new_inlays.push(inlay);
|
new_inlays.push(inlay);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -560,6 +560,11 @@ impl DapStore {
|
||||||
fn format_value(mut value: String) -> String {
|
fn format_value(mut value: String) -> String {
|
||||||
const LIMIT: usize = 100;
|
const LIMIT: usize = 100;
|
||||||
|
|
||||||
|
if let Some(index) = value.find("\n") {
|
||||||
|
value.truncate(index);
|
||||||
|
value.push_str("…");
|
||||||
|
}
|
||||||
|
|
||||||
if value.len() > LIMIT {
|
if value.len() > LIMIT {
|
||||||
let mut index = LIMIT;
|
let mut index = LIMIT;
|
||||||
// If index isn't a char boundary truncate will cause a panic
|
// If index isn't a char boundary truncate will cause a panic
|
||||||
|
@ -567,7 +572,7 @@ impl DapStore {
|
||||||
index -= 1;
|
index -= 1;
|
||||||
}
|
}
|
||||||
value.truncate(index);
|
value.truncate(index);
|
||||||
value.push_str("...");
|
value.push_str("…");
|
||||||
}
|
}
|
||||||
|
|
||||||
format!(": {}", value)
|
format!(": {}", value)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue