From 448af397e695d0d056a054b28b644cf6192abb81 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 17 Sep 2025 14:58:12 -0600 Subject: [PATCH] Fix inlay settings --- assets/settings/default.json | 1 + crates/collab/src/tests/editor_tests.rs | 94 +++--- crates/editor/src/editor.rs | 9 +- crates/editor/src/hover_links.rs | 20 +- crates/editor/src/hover_popover.rs | 20 +- crates/editor/src/inlay_hint_cache.rs | 315 +++++++++--------- crates/language/src/language_settings.rs | 123 ++++++- crates/onboarding/src/basics_page.rs | 4 - crates/onboarding/src/editing_page.rs | 11 +- .../settings/src/settings_content/language.rs | 64 +--- crates/settings/src/settings_store.rs | 3 - 11 files changed, 375 insertions(+), 289 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 8dd3e46eec3f466a2647cf55c57dd4ef32c01776..78fdc3d38d2e33febcb186e1edf68c3a40b01d66 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -603,6 +603,7 @@ // Toggle certain types of hints on and off, all switched on by default. "show_type_hints": true, "show_parameter_hints": true, + "show_value_hints": true, // Corresponds to null/None LSP hint type value. "show_other_hints": true, // Whether to show a background for inlay hints. diff --git a/crates/collab/src/tests/editor_tests.rs b/crates/collab/src/tests/editor_tests.rs index 3fe2e797bf95b6ebf449f388ad48e53f215ca37b..c7c358a44b88d5e5d26115984aa6a731ed6502d4 100644 --- a/crates/collab/src/tests/editor_tests.rs +++ b/crates/collab/src/tests/editor_tests.rs @@ -27,7 +27,7 @@ use project::{ use recent_projects::disconnected_overlay::DisconnectedOverlay; use rpc::RECEIVE_TIMEOUT; use serde_json::json; -use settings::{InlayHintSettings, InlineBlameSettings, SettingsStore}; +use settings::{InlayHintSettingsContent, InlineBlameSettings, SettingsStore}; use std::{ collections::BTreeSet, ops::{Deref as _, Range}, @@ -1786,34 +1786,36 @@ async fn test_mutual_editor_inlay_hint_cache_update( cx_a.update(|cx| { SettingsStore::update_global(cx, |store, cx| { store.update_user_settings(cx, |settings| { - settings.project.all_languages.defaults.inlay_hints = Some(InlayHintSettings { - enabled: true, - show_value_hints: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: false, - show_other_hints: true, - show_background: false, - toggle_on_modifiers_press: None, - }) + settings.project.all_languages.defaults.inlay_hints = + Some(InlayHintSettingsContent { + enabled: true, + show_value_hints: true, + edit_debounce_ms: 0, + scroll_debounce_ms: 0, + show_type_hints: true, + show_parameter_hints: false, + show_other_hints: true, + show_background: false, + toggle_on_modifiers_press: None, + }) }); }); }); cx_b.update(|cx| { SettingsStore::update_global(cx, |store, cx| { store.update_user_settings(cx, |settings| { - settings.project.all_languages.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: false, - show_other_hints: true, - show_background: false, - toggle_on_modifiers_press: None, - }) + settings.project.all_languages.defaults.inlay_hints = + Some(InlayHintSettingsContent { + show_value_hints: true, + enabled: true, + edit_debounce_ms: 0, + scroll_debounce_ms: 0, + show_type_hints: true, + show_parameter_hints: false, + show_other_hints: true, + show_background: false, + toggle_on_modifiers_press: None, + }) }); }); }); @@ -2036,34 +2038,36 @@ async fn test_inlay_hint_refresh_is_forwarded( cx_a.update(|cx| { SettingsStore::update_global(cx, |store, cx| { store.update_user_settings(cx, |settings| { - settings.project.all_languages.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: false, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: false, - show_parameter_hints: false, - show_other_hints: false, - show_background: false, - toggle_on_modifiers_press: None, - }) + settings.project.all_languages.defaults.inlay_hints = + Some(InlayHintSettingsContent { + show_value_hints: true, + enabled: false, + edit_debounce_ms: 0, + scroll_debounce_ms: 0, + show_type_hints: false, + show_parameter_hints: false, + show_other_hints: false, + show_background: false, + toggle_on_modifiers_press: None, + }) }); }); }); cx_b.update(|cx| { SettingsStore::update_global(cx, |store, cx| { store.update_user_settings(cx, |settings| { - settings.project.all_languages.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: true, - show_other_hints: true, - show_background: false, - toggle_on_modifiers_press: None, - }) + settings.project.all_languages.defaults.inlay_hints = + Some(InlayHintSettingsContent { + show_value_hints: true, + enabled: true, + edit_debounce_ms: 0, + scroll_debounce_ms: 0, + show_type_hints: true, + show_parameter_hints: true, + show_other_hints: true, + show_background: false, + toggle_on_modifiers_press: None, + }) }); }); }); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 28dd71c94b341e42fe6a68de6efcf097c7536e6c..2bea1fc72b5586554219bb4967f44edc18424adf 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -126,8 +126,8 @@ use language::{ Language, OffsetRangeExt, Point, Runnable, RunnableRange, Selection, SelectionGoal, TextObject, TransactionId, TreeSitterOptions, WordsQuery, language_settings::{ - self, LspInsertMode, RewrapBehavior, WordsCompletionMode, all_language_settings, - language_settings, + self, InlayHintSettings, LspInsertMode, RewrapBehavior, WordsCompletionMode, + all_language_settings, language_settings, }, point_from_lsp, point_to_lsp, text_diff_with_options, }; @@ -169,10 +169,7 @@ use selections_collection::{ MutableSelectionsCollection, SelectionsCollection, resolve_selections, }; use serde::{Deserialize, Serialize}; -use settings::{ - GitGutterSetting, InlayHintSettings, Settings, SettingsLocation, SettingsStore, - update_settings_file, -}; +use settings::{GitGutterSetting, Settings, SettingsLocation, SettingsStore, update_settings_file}; use smallvec::{SmallVec, smallvec}; use snippet::Snippet; use std::{ diff --git a/crates/editor/src/hover_links.rs b/crates/editor/src/hover_links.rs index bf0367c159f5e576f9f2cf2a5c32f790f9c85ea5..d5a3f17822ff7f0f2324414aeaa9819b8605f53b 100644 --- a/crates/editor/src/hover_links.rs +++ b/crates/editor/src/hover_links.rs @@ -932,7 +932,7 @@ mod tests { use gpui::Modifiers; use indoc::indoc; use lsp::request::{GotoDefinition, GotoTypeDefinition}; - use settings::InlayHintSettings; + use settings::InlayHintSettingsContent; use util::{assert_set_eq, path}; use workspace::item::Item; @@ -1280,15 +1280,15 @@ mod tests { #[gpui::test] async fn test_inlay_hover_links(cx: &mut gpui::TestAppContext) { init_test(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - enabled: true, - show_value_hints: false, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: true, - show_other_hints: true, - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + enabled: Some(true), + show_value_hints: Some(false), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(true), + show_parameter_hints: Some(true), + show_other_hints: Some(true), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rs index 21b9c777e409ef2b2d8a3ecb990b5bd77d408ea5..1815029207cf485292277861cd8d18ed482d6077 100644 --- a/crates/editor/src/hover_popover.rs +++ b/crates/editor/src/hover_popover.rs @@ -1005,7 +1005,7 @@ mod tests { use gpui::App; use indoc::indoc; use markdown::parser::MarkdownEvent; - use settings::InlayHintSettings; + use settings::InlayHintSettingsContent; use smol::stream::StreamExt; use std::sync::atomic; use std::sync::atomic::AtomicUsize; @@ -1551,15 +1551,15 @@ mod tests { #[gpui::test] async fn test_hover_inlay_label_parts(cx: &mut gpui::TestAppContext) { init_test(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: true, - show_other_hints: true, - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(true), + show_parameter_hints: Some(true), + show_other_hints: Some(true), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); diff --git a/crates/editor/src/inlay_hint_cache.rs b/crates/editor/src/inlay_hint_cache.rs index 970c533710a09c84875ce0047060ede5e3a6aa56..59c52e4341a74e85236d99da4bf6ff1195266f68 100644 --- a/crates/editor/src/inlay_hint_cache.rs +++ b/crates/editor/src/inlay_hint_cache.rs @@ -20,12 +20,14 @@ use anyhow::Context as _; use clock::Global; use futures::future; use gpui::{AppContext as _, AsyncApp, Context, Entity, Task, Window}; -use language::{Buffer, BufferSnapshot, language_settings::InlayHintKind}; +use language::{ + Buffer, BufferSnapshot, + language_settings::{InlayHintKind, InlayHintSettings}, +}; use parking_lot::RwLock; use project::{InlayHint, ResolveState}; use collections::{HashMap, HashSet, hash_map}; -use settings::InlayHintSettings; use smol::lock::Semaphore; use sum_tree::Bias; use text::{BufferId, ToOffset, ToPoint}; @@ -1307,7 +1309,7 @@ pub mod tests { use parking_lot::Mutex; use project::{FakeFs, Project}; use serde_json::json; - use settings::{AllLanguageSettingsContent, InlayHintSettings, SettingsStore}; + use settings::{AllLanguageSettingsContent, InlayHintSettingsContent, SettingsStore}; use std::sync::atomic::{AtomicBool, AtomicU32, AtomicUsize, Ordering}; use text::Point; use util::path; @@ -1318,15 +1320,17 @@ pub mod tests { async fn test_basic_cache_update_with_duplicate_hints(cx: &mut gpui::TestAppContext) { let allowed_hint_kinds = HashSet::from_iter([None, Some(InlayHintKind::Type)]); init_test(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Type)), - show_parameter_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)), - show_other_hints: allowed_hint_kinds.contains(&None), - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(allowed_hint_kinds.contains(&Some(InlayHintKind::Type))), + show_parameter_hints: Some( + allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)), + ), + show_other_hints: Some(allowed_hint_kinds.contains(&None)), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -1428,15 +1432,15 @@ pub mod tests { #[gpui::test] async fn test_cache_update_on_lsp_completion_tasks(cx: &mut gpui::TestAppContext) { init_test(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: true, - show_other_hints: true, - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(true), + show_parameter_hints: Some(true), + show_other_hints: Some(true), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -1535,15 +1539,15 @@ pub mod tests { #[gpui::test] async fn test_no_hint_updates_for_unrelated_language_files(cx: &mut gpui::TestAppContext) { init_test(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: true, - show_other_hints: true, - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(true), + show_parameter_hints: Some(true), + show_other_hints: Some(true), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -1765,15 +1769,17 @@ pub mod tests { async fn test_hint_setting_changes(cx: &mut gpui::TestAppContext) { let allowed_hint_kinds = HashSet::from_iter([None, Some(InlayHintKind::Type)]); init_test(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Type)), - show_parameter_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)), - show_other_hints: allowed_hint_kinds.contains(&None), - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(allowed_hint_kinds.contains(&Some(InlayHintKind::Type))), + show_parameter_hints: Some( + allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)), + ), + show_other_hints: Some(allowed_hint_kinds.contains(&None)), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -1926,16 +1932,19 @@ pub mod tests { ), ] { update_test_language_settings(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: new_allowed_hint_kinds.contains(&Some(InlayHintKind::Type)), - show_parameter_hints: new_allowed_hint_kinds - .contains(&Some(InlayHintKind::Parameter)), - show_other_hints: new_allowed_hint_kinds.contains(&None), - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some( + new_allowed_hint_kinds.contains(&Some(InlayHintKind::Type)), + ), + show_parameter_hints: Some( + new_allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)), + ), + show_other_hints: Some(new_allowed_hint_kinds.contains(&None)), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -1970,16 +1979,19 @@ pub mod tests { let another_allowed_hint_kinds = HashSet::from_iter([Some(InlayHintKind::Type)]); update_test_language_settings(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: false, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: another_allowed_hint_kinds.contains(&Some(InlayHintKind::Type)), - show_parameter_hints: another_allowed_hint_kinds - .contains(&Some(InlayHintKind::Parameter)), - show_other_hints: another_allowed_hint_kinds.contains(&None), - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(false), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some( + another_allowed_hint_kinds.contains(&Some(InlayHintKind::Type)), + ), + show_parameter_hints: Some( + another_allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)), + ), + show_other_hints: Some(another_allowed_hint_kinds.contains(&None)), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -2027,16 +2039,19 @@ pub mod tests { let final_allowed_hint_kinds = HashSet::from_iter([Some(InlayHintKind::Parameter)]); update_test_language_settings(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: final_allowed_hint_kinds.contains(&Some(InlayHintKind::Type)), - show_parameter_hints: final_allowed_hint_kinds - .contains(&Some(InlayHintKind::Parameter)), - show_other_hints: final_allowed_hint_kinds.contains(&None), - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some( + final_allowed_hint_kinds.contains(&Some(InlayHintKind::Type)), + ), + show_parameter_hints: Some( + final_allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)), + ), + show_other_hints: Some(final_allowed_hint_kinds.contains(&None)), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -2102,15 +2117,15 @@ pub mod tests { #[gpui::test] async fn test_hint_request_cancellation(cx: &mut gpui::TestAppContext) { init_test(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: true, - show_other_hints: true, - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(true), + show_parameter_hints: Some(true), + show_other_hints: Some(true), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -2239,15 +2254,15 @@ pub mod tests { #[gpui::test(iterations = 10)] async fn test_large_buffer_inlay_requests_split(cx: &mut gpui::TestAppContext) { init_test(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: true, - show_other_hints: true, - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(true), + show_parameter_hints: Some(true), + show_other_hints: Some(true), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -2540,15 +2555,15 @@ pub mod tests { #[gpui::test] async fn test_multiple_excerpts_large_multibuffer(cx: &mut gpui::TestAppContext) { init_test(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: true, - show_other_hints: true, - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(true), + show_parameter_hints: Some(true), + show_other_hints: Some(true), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -2864,15 +2879,15 @@ pub mod tests { #[gpui::test] async fn test_excerpts_removed(cx: &mut gpui::TestAppContext) { init_test(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: false, - show_parameter_hints: false, - show_other_hints: false, - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(false), + show_parameter_hints: Some(false), + show_other_hints: Some(false), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -3041,15 +3056,15 @@ pub mod tests { .unwrap(); update_test_language_settings(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: true, - show_other_hints: true, - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(true), + show_parameter_hints: Some(true), + show_other_hints: Some(true), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -3074,15 +3089,15 @@ pub mod tests { #[gpui::test] async fn test_inside_char_boundary_range_hints(cx: &mut gpui::TestAppContext) { init_test(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: true, - show_other_hints: true, - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(true), + show_parameter_hints: Some(true), + show_other_hints: Some(true), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -3167,15 +3182,15 @@ pub mod tests { #[gpui::test] async fn test_toggle_inlay_hints(cx: &mut gpui::TestAppContext) { init_test(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: false, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: true, - show_other_hints: true, - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(false), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(true), + show_parameter_hints: Some(true), + show_other_hints: Some(true), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -3244,15 +3259,15 @@ pub mod tests { .unwrap(); update_test_language_settings(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: true, - show_other_hints: true, - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(true), + show_parameter_hints: Some(true), + show_other_hints: Some(true), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); @@ -3305,15 +3320,15 @@ pub mod tests { #[gpui::test] async fn test_inlays_at_the_same_place(cx: &mut gpui::TestAppContext) { init_test(cx, |settings| { - settings.defaults.inlay_hints = Some(InlayHintSettings { - show_value_hints: true, - enabled: true, - edit_debounce_ms: 0, - scroll_debounce_ms: 0, - show_type_hints: true, - show_parameter_hints: true, - show_other_hints: true, - show_background: false, + settings.defaults.inlay_hints = Some(InlayHintSettingsContent { + show_value_hints: Some(true), + enabled: Some(true), + edit_debounce_ms: Some(0), + scroll_debounce_ms: Some(0), + show_type_hints: Some(true), + show_parameter_hints: Some(true), + show_other_hints: Some(true), + show_background: Some(false), toggle_on_modifiers_press: None, }) }); diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs index 22f1d5df982a1796c236f5813b273e5e6e78ae7b..f1daa0d3f8198fb36ef37bfe79a6ed01f7ea2add 100644 --- a/crates/language/src/language_settings.rs +++ b/crates/language/src/language_settings.rs @@ -7,7 +7,7 @@ use ec4rs::{ property::{FinalNewline, IndentSize, IndentStyle, MaxLineLen, TabWidth, TrimTrailingWs}, }; use globset::{Glob, GlobMatcher, GlobSet, GlobSetBuilder}; -use gpui::App; +use gpui::{App, Modifiers}; use itertools::{Either, Itertools}; use schemars::{JsonSchema, json_schema}; use serde::{Deserialize, Serialize}; @@ -130,7 +130,7 @@ pub struct LanguageSettings { /// Whether to start a new line with a comment when a previous line is a comment as well. pub extend_comment_on_newline: bool, /// Inlay hint related settings. - pub inlay_hints: settings::InlayHintSettings, + pub inlay_hints: InlayHintSettings, /// Whether to automatically close brackets. pub use_autoclose: bool, /// Whether to automatically surround text with brackets. @@ -211,6 +211,73 @@ impl LanguageSettings { } } +// The settings for inlay hints. +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +pub struct InlayHintSettings { + /// Global switch to toggle hints on and off. + /// + /// Default: false + pub enabled: bool, + /// Global switch to toggle inline values on and off when debugging. + /// + /// Default: true + pub show_value_hints: bool, + /// Whether type hints should be shown. + /// + /// Default: true + pub show_type_hints: bool, + /// Whether parameter hints should be shown. + /// + /// Default: true + pub show_parameter_hints: bool, + /// Whether other hints should be shown. + /// + /// Default: true + pub show_other_hints: bool, + /// Whether to show a background for inlay hints. + /// + /// If set to `true`, the background will use the `hint.background` color + /// from the current theme. + /// + /// Default: false + pub show_background: bool, + /// Whether or not to debounce inlay hints updates after buffer edits. + /// + /// Set to 0 to disable debouncing. + /// + /// Default: 700 + pub edit_debounce_ms: u64, + /// Whether or not to debounce inlay hints updates after buffer scrolls. + /// + /// Set to 0 to disable debouncing. + /// + /// Default: 50 + pub scroll_debounce_ms: u64, + /// Toggles inlay hints (hides or shows) when the user presses the modifiers specified. + /// If only a subset of the modifiers specified is pressed, hints are not toggled. + /// If no modifiers are specified, this is equivalent to `None`. + /// + /// Default: None + pub toggle_on_modifiers_press: Option, +} + +impl InlayHintSettings { + /// Returns the kinds of inlay hints that are enabled based on the settings. + pub fn enabled_inlay_hint_kinds(&self) -> HashSet> { + let mut kinds = HashSet::default(); + if self.show_type_hints { + kinds.insert(Some(InlayHintKind::Type)); + } + if self.show_parameter_hints { + kinds.insert(Some(InlayHintKind::Parameter)); + } + if self.show_other_hints { + kinds.insert(None); + } + kinds + } +} + /// The settings for edit predictions, such as [GitHub Copilot](https://github.com/features/copilot) /// or [Supermaven](https://supermaven.com). #[derive(Clone, Debug, Default, SettingsUi)] @@ -377,6 +444,7 @@ impl settings::Settings for AllLanguageSettings { fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self { let all_languages = &content.project.all_languages; let defaults = all_languages.defaults.clone(); + let inlay_hints = defaults.inlay_hints.unwrap(); let default_language_settings = LanguageSettings { tab_size: defaults.tab_size.unwrap(), hard_tabs: defaults.hard_tabs.unwrap(), @@ -401,7 +469,17 @@ impl settings::Settings for AllLanguageSettings { show_whitespaces: defaults.show_whitespaces.unwrap(), whitespace_map: defaults.whitespace_map.unwrap(), extend_comment_on_newline: defaults.extend_comment_on_newline.unwrap(), - inlay_hints: defaults.inlay_hints.unwrap(), + inlay_hints: InlayHintSettings { + enabled: inlay_hints.enabled.unwrap(), + show_value_hints: inlay_hints.show_value_hints.unwrap(), + show_type_hints: inlay_hints.show_type_hints.unwrap(), + show_parameter_hints: inlay_hints.show_parameter_hints.unwrap(), + show_other_hints: inlay_hints.show_other_hints.unwrap(), + show_background: inlay_hints.show_background.unwrap(), + edit_debounce_ms: inlay_hints.edit_debounce_ms.unwrap(), + scroll_debounce_ms: inlay_hints.scroll_debounce_ms.unwrap(), + toggle_on_modifiers_press: inlay_hints.toggle_on_modifiers_press, + }, use_autoclose: defaults.use_autoclose.unwrap(), use_auto_surround: defaults.use_auto_surround.unwrap(), use_on_type_format: defaults.use_on_type_format.unwrap(), @@ -805,7 +883,44 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent settings .extend_comment_on_newline .merge_from(&src.extend_comment_on_newline); - settings.inlay_hints.merge_from(&src.inlay_hints.clone()); + if let Some(inlay_hints) = &src.inlay_hints { + settings + .inlay_hints + .enabled + .merge_from(&inlay_hints.enabled); + settings + .inlay_hints + .show_value_hints + .merge_from(&inlay_hints.show_value_hints); + settings + .inlay_hints + .show_type_hints + .merge_from(&inlay_hints.show_type_hints); + settings + .inlay_hints + .show_parameter_hints + .merge_from(&inlay_hints.show_parameter_hints); + settings + .inlay_hints + .show_other_hints + .merge_from(&inlay_hints.show_other_hints); + settings + .inlay_hints + .show_background + .merge_from(&inlay_hints.show_background); + settings + .inlay_hints + .edit_debounce_ms + .merge_from(&inlay_hints.edit_debounce_ms); + settings + .inlay_hints + .scroll_debounce_ms + .merge_from(&inlay_hints.scroll_debounce_ms); + if let Some(toggle_on_modifiers_press) = &inlay_hints.toggle_on_modifiers_press { + settings.inlay_hints.toggle_on_modifiers_press = + Some(toggle_on_modifiers_press.clone()); + } + } settings .show_completions_on_input .merge_from(&src.show_completions_on_input); diff --git a/crates/onboarding/src/basics_page.rs b/crates/onboarding/src/basics_page.rs index d705d64bfe0f7cdd65e18196bebcd888d5a2fb5f..b3b2dfc9af85cd1e3d8b8b2892ad4245fc047ca4 100644 --- a/crates/onboarding/src/basics_page.rs +++ b/crates/onboarding/src/basics_page.rs @@ -251,9 +251,7 @@ fn render_telemetry_section(tab_index: &mut isize, cx: &App) -> impl IntoElement fs.clone(), cx, move |setting, _| { - dbg!(&setting.telemetry); setting.telemetry.get_or_insert_default().metrics = Some(enabled); - dbg!(&setting.telemetry); } , ); @@ -295,9 +293,7 @@ fn render_telemetry_section(tab_index: &mut isize, cx: &App) -> impl IntoElement fs.clone(), cx, move |setting, _| { - dbg!(&setting.telemetry); setting.telemetry.get_or_insert_default().diagnostics = Some(enabled); - dbg!(&setting.telemetry); }, ); diff --git a/crates/onboarding/src/editing_page.rs b/crates/onboarding/src/editing_page.rs index 567444007bd75ae34709495103ac257a8c4701e0..404374dc06bd817f8084f320a107233b42232816 100644 --- a/crates/onboarding/src/editing_page.rs +++ b/crates/onboarding/src/editing_page.rs @@ -58,19 +58,14 @@ fn write_inlay_hints(enabled: bool, cx: &mut App) { curr_settings.defaults.inlay_hints.enabled = enabled; AllLanguageSettings::override_global(curr_settings, cx); - update_settings_file(fs, cx, move |settings, cx| { + update_settings_file(fs, cx, move |settings, _cx| { settings .project .all_languages .defaults .inlay_hints - .get_or_insert_with(|| { - AllLanguageSettings::get_global(cx) - .clone() - .defaults - .inlay_hints - }) - .enabled = enabled; + .get_or_insert_default() + .enabled = Some(enabled); }); } diff --git a/crates/settings/src/settings_content/language.rs b/crates/settings/src/settings_content/language.rs index 7a679a2a06caf4468d5872dc1c06fb2462c88735..74f3838efe38bc05c04f0445e35d86182840eeb0 100644 --- a/crates/settings/src/settings_content/language.rs +++ b/crates/settings/src/settings_content/language.rs @@ -218,7 +218,7 @@ pub struct LanguageSettingsContent { /// Default: true pub extend_comment_on_newline: Option, /// Inlay hint related settings. - pub inlay_hints: Option, + pub inlay_hints: Option, /// Whether to automatically type closing characters for you. For example, /// when you type (, Zed will automatically add a closing ) at the correct position. /// @@ -348,81 +348,55 @@ pub struct JsxTagAutoCloseSettings { /// The settings for inlay hints. /// todo!() the fields of this struct should likely be optional, /// and a similar struct exposed from the language crate. -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] -pub struct InlayHintSettings { +#[derive(Clone, Default, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] +pub struct InlayHintSettingsContent { /// Global switch to toggle hints on and off. /// /// Default: false - #[serde(default)] - pub enabled: bool, + pub enabled: Option, /// Global switch to toggle inline values on and off when debugging. /// /// Default: true - #[serde(default = "default_true")] - pub show_value_hints: bool, + pub show_value_hints: Option, /// Whether type hints should be shown. /// /// Default: true - #[serde(default = "default_true")] - pub show_type_hints: bool, + pub show_type_hints: Option, /// Whether parameter hints should be shown. /// /// Default: true - #[serde(default = "default_true")] - pub show_parameter_hints: bool, + pub show_parameter_hints: Option, /// Whether other hints should be shown. /// /// Default: true - #[serde(default = "default_true")] - pub show_other_hints: bool, + pub show_other_hints: Option, /// Whether to show a background for inlay hints. /// /// If set to `true`, the background will use the `hint.background` color /// from the current theme. /// /// Default: false - #[serde(default)] - pub show_background: bool, + pub show_background: Option, /// Whether or not to debounce inlay hints updates after buffer edits. /// /// Set to 0 to disable debouncing. /// /// Default: 700 - #[serde(default = "edit_debounce_ms")] - pub edit_debounce_ms: u64, + pub edit_debounce_ms: Option, /// Whether or not to debounce inlay hints updates after buffer scrolls. /// /// Set to 0 to disable debouncing. /// /// Default: 50 - #[serde(default = "scroll_debounce_ms")] - pub scroll_debounce_ms: u64, + pub scroll_debounce_ms: Option, /// Toggles inlay hints (hides or shows) when the user presses the modifiers specified. /// If only a subset of the modifiers specified is pressed, hints are not toggled. - /// If no modifiers are specified, this is equivalent to `None`. + /// If no modifiers are specified, this is equivalent to `null`. /// - /// Default: None - #[serde(default)] + /// Default: null pub toggle_on_modifiers_press: Option, } -impl InlayHintSettings { - /// Returns the kinds of inlay hints that are enabled based on the settings. - pub fn enabled_inlay_hint_kinds(&self) -> HashSet> { - let mut kinds = HashSet::default(); - if self.show_type_hints { - kinds.insert(Some(InlayHintKind::Type)); - } - if self.show_parameter_hints { - kinds.insert(Some(InlayHintKind::Parameter)); - } - if self.show_other_hints { - kinds.insert(None); - } - kinds - } -} - /// The kind of an inlay hint. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum InlayHintKind { @@ -433,7 +407,7 @@ pub enum InlayHintKind { } impl InlayHintKind { - /// Returns the [`InlayHintKind`] from the given name. + /// Returns the [`InlayHintKind`]fromthe given name. /// /// Returns `None` if `name` does not match any of the expected /// string representations. @@ -454,15 +428,7 @@ impl InlayHintKind { } } -fn edit_debounce_ms() -> u64 { - 700 -} - -fn scroll_debounce_ms() -> u64 { - 50 -} - -/// Controls how completions are processed for this language. +/// Controls how completions are processedfor this anguage. #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub struct CompletionSettings { diff --git a/crates/settings/src/settings_store.rs b/crates/settings/src/settings_store.rs index 15d7ef280c2e81bd428860f3d0390519731b5201..33158d44173ee9f360a21f9a0bcd5c7aa284708d 100644 --- a/crates/settings/src/settings_store.rs +++ b/crates/settings/src/settings_store.rs @@ -424,7 +424,6 @@ impl SettingsStore { async move { let res = async move { let old_text = Self::load_settings(&fs).await?; - dbg!(&old_text); let new_text = update(old_text, cx)?; let settings_path = paths::settings_file().as_path(); if fs.is_file(settings_path).await { @@ -555,10 +554,8 @@ impl SettingsStore { text: &str, update: impl FnOnce(&mut SettingsContent), ) -> Vec<(Range, String)> { - dbg!(&text); let old_content: UserSettingsContent = parse_json_with_comments(text).log_err().unwrap_or_default(); - dbg!(&old_content); let mut new_content = old_content.clone(); update(&mut new_content.content);