From 48b376fdc9d55309e47bbbe2542afd8e69fa21fd Mon Sep 17 00:00:00 2001 From: Remco Smits Date: Tue, 13 May 2025 23:13:02 +0200 Subject: [PATCH] debugger: Fix nits (#30632) Release Notes: - N/A --------- Co-authored-by: Anthony Eid --- crates/debugger_ui/src/tests/inline_values.rs | 14 +++----------- crates/language/src/language_settings.rs | 4 ++-- crates/project/src/debugger/dap_store.rs | 15 +++++++++++++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/crates/debugger_ui/src/tests/inline_values.rs b/crates/debugger_ui/src/tests/inline_values.rs index 76b94360807e4c20fdc44074646a9e9ae1a59883..6fed57ecacc9ad6062a27f3fa33a95bd52cc1a10 100644 --- a/crates/debugger_ui/src/tests/inline_values.rs +++ b/crates/debugger_ui/src/tests/inline_values.rs @@ -1,7 +1,7 @@ use std::{path::Path, sync::Arc}; use dap::{Scope, StackFrame, Variable, requests::Variables}; -use editor::{Editor, EditorMode, MultiBuffer, actions::ToggleInlineValues}; +use editor::{Editor, EditorMode, MultiBuffer}; use gpui::{BackgroundExecutor, TestAppContext, VisualTestContext}; use language::{Language, LanguageConfig, LanguageMatcher, tree_sitter_python, tree_sitter_rust}; use project::{FakeFs, Project}; @@ -239,11 +239,7 @@ fn main() { }); cx.run_until_parked(); - editor.update_in(cx, |editor, window, cx| { - if !editor.inline_values_enabled() { - editor.toggle_inline_values(&ToggleInlineValues, window, cx); - } - }); + editor.update(cx, |editor, cx| editor.refresh_inline_values(cx)); cx.run_until_parked(); @@ -1604,11 +1600,7 @@ def process_data(untyped_param, typed_param: int, another_typed: str): ) }); - editor.update_in(cx, |editor, window, cx| { - if !editor.inline_values_enabled() { - editor.toggle_inline_values(&ToggleInlineValues, window, cx); - } - }); + editor.update(cx, |editor, cx| editor.refresh_inline_values(cx)); client.on_request::(move |_, _| { Ok(dap::ThreadsResponse { diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs index 3bcff8913aeaff54fc02b06ebc53d08f6c25e1b8..d7a237cf4904165affba92571e603a8f6d3403b7 100644 --- a/crates/language/src/language_settings.rs +++ b/crates/language/src/language_settings.rs @@ -980,8 +980,8 @@ pub struct InlayHintSettings { pub enabled: bool, /// Global switch to toggle inline values on and off. /// - /// Default: false - #[serde(default)] + /// Default: true + #[serde(default = "default_true")] pub show_value_hints: bool, /// Whether type hints should be shown. /// diff --git a/crates/project/src/debugger/dap_store.rs b/crates/project/src/debugger/dap_store.rs index 90ca66a2d402fb47afae666188529a37b7c09c65..ff20de4d3c2ec353f71b874bd3b05d38b04efcc0 100644 --- a/crates/project/src/debugger/dap_store.rs +++ b/crates/project/src/debugger/dap_store.rs @@ -577,6 +577,17 @@ impl DapStore { let snapshot = buffer_handle.read(cx).snapshot(); let all_variables = session.read(cx).variables_by_stack_frame_id(stack_frame_id); + fn format_value(mut value: String) -> String { + const LIMIT: usize = 100; + + if value.len() > LIMIT { + value.truncate(LIMIT); + value.push_str("..."); + } + + format!(": {}", value) + } + cx.spawn(async move |_, cx| { let mut inlay_hints = Vec::with_capacity(inline_value_locations.len()); for inline_value_location in inline_value_locations.iter() { @@ -597,7 +608,7 @@ impl DapStore { inlay_hints.push(InlayHint { position, - label: InlayHintLabel::String(format!(": {}", variable.value)), + label: InlayHintLabel::String(format_value(variable.value.clone())), kind: Some(InlayHintKind::Type), padding_left: false, padding_right: false, @@ -620,7 +631,7 @@ impl DapStore { if let Some(response) = eval_task.await.log_err() { inlay_hints.push(InlayHint { position, - label: InlayHintLabel::String(format!(": {}", response.result)), + label: InlayHintLabel::String(format_value(response.result)), kind: Some(InlayHintKind::Type), padding_left: false, padding_right: false,