Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix `use_on_type_format` setting being unused per language (#18387)

Thorsten Ball3f415f3587b1
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index 6e5543132c8..730482b123b 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -3442,7 +3442,7 @@ impl Editor {
s.select(new_selections)
});
- if !bracket_inserted && EditorSettings::get_global(cx).use_on_type_format {
+ if !bracket_inserted {
if let Some(on_type_format_task) =
this.trigger_on_type_formatting(text.to_string(), cx)
{
@@ -4191,6 +4191,15 @@ impl Editor {
.read(cx)
.text_anchor_for_position(position, cx)?;
+ let settings = language_settings::language_settings(
+ buffer.read(cx).language_at(buffer_position).as_ref(),
+ buffer.read(cx).file(),
+ cx,
+ );
+ if !settings.use_on_type_format {
+ return None;
+ }
+
// OnTypeFormatting returns a list of edits, no need to pass them between Zed instances,
// hence we do LSP request & edit on host side only — add formats to host's history.
let push_to_lsp_host_history = true;
diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs
index d651e76c2c2..91376292414 100644
--- a/crates/editor/src/editor_settings.rs
+++ b/crates/editor/src/editor_settings.rs
@@ -13,7 +13,6 @@ pub struct EditorSettings {
pub show_completions_on_input: bool,
pub show_completion_documentation: bool,
pub completion_documentation_secondary_query_debounce: u64,
- pub use_on_type_format: bool,
pub toolbar: Toolbar,
pub scrollbar: Scrollbar,
pub gutter: Gutter,
@@ -209,11 +208,6 @@ pub struct EditorSettingsContent {
///
/// Default: 300 ms
pub completion_documentation_secondary_query_debounce: Option<u64>,
- /// Whether to use additional LSP queries to format (and amend) the code after
- /// every "trigger" symbol input, defined by LSP server capabilities.
- ///
- /// Default: true
- pub use_on_type_format: Option<bool>,
/// Toolbar related settings
pub toolbar: Option<ToolbarContent>,
/// Scrollbar related settings
diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs
index 735a9a60f87..f830c5f25c3 100644
--- a/crates/language/src/language_settings.rs
+++ b/crates/language/src/language_settings.rs
@@ -113,6 +113,9 @@ pub struct LanguageSettings {
pub use_autoclose: bool,
/// Whether to automatically surround text with brackets.
pub use_auto_surround: bool,
+ /// Whether to use additional LSP queries to format (and amend) the code after
+ /// every "trigger" symbol input, defined by LSP server capabilities.
+ pub use_on_type_format: bool,
// Controls how the editor handles the autoclosed characters.
pub always_treat_brackets_as_autoclosed: bool,
/// Which code actions to run on save
@@ -333,6 +336,11 @@ pub struct LanguageSettingsContent {
///
/// Default: false
pub always_treat_brackets_as_autoclosed: Option<bool>,
+ /// Whether to use additional LSP queries to format (and amend) the code after
+ /// every "trigger" symbol input, defined by LSP server capabilities.
+ ///
+ /// Default: true
+ pub use_on_type_format: Option<bool>,
/// Which code actions to run on save after the formatter.
/// These are not run if formatting is off.
///
@@ -1045,6 +1053,7 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent
merge(&mut settings.soft_wrap, src.soft_wrap);
merge(&mut settings.use_autoclose, src.use_autoclose);
merge(&mut settings.use_auto_surround, src.use_auto_surround);
+ merge(&mut settings.use_on_type_format, src.use_on_type_format);
merge(
&mut settings.always_treat_brackets_as_autoclosed,
src.always_treat_brackets_as_autoclosed,