diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index e77f08e268d8c07364189e3e8ff076cc62008644..80fda5297a501405ed894f670580d963abf9c3aa 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -30,7 +30,7 @@ use language::{ }, tree_sitter_python, }; -use language_settings::{Formatter, IndentGuideSettings}; +use language_settings::{Formatter, IndentGuideSettingsContent}; use lsp::CompletionParams; use multi_buffer::{IndentGuide, PathKey}; use parking_lot::Mutex; @@ -19961,7 +19961,7 @@ fn indent_guide(buffer_id: BufferId, start_row: u32, end_row: u32, depth: u32) - end_row: MultiBufferRow(end_row), depth, tab_size: 4, - settings: IndentGuideSettings { + settings: IndentGuideSettingsContent { enabled: true, line_width: 1, active_line_width: 1, diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 30dfc7989a3640c73b55683e776c08b243e64d9c..7b6f26c85fb7619178c4ee364343763175f3c036 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -51,7 +51,7 @@ use gpui::{ transparent_black, }; use itertools::Itertools; -use language::language_settings::{IndentGuideSettings, ShowWhitespaceSetting}; +use language::language_settings::{IndentGuideSettingsContent, ShowWhitespaceSetting}; use markdown::Markdown; use multi_buffer::{ Anchor, ExcerptId, ExcerptInfo, ExpandExcerptDirection, ExpandInfo, MultiBufferPoint, @@ -10177,7 +10177,7 @@ pub struct IndentGuideLayout { single_indent_width: Pixels, depth: u32, active: bool, - settings: IndentGuideSettings, + settings: IndentGuideSettingsContent, } pub struct CursorLayout { diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index 3c951e50ff231a72e284da743bb3e5d409eb9c5e..291b5d3957cc7274bdd07b5260890c23b7a253d1 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -22,8 +22,8 @@ mod toolchain; #[cfg(test)] pub mod buffer_tests; -pub use crate::language_settings::EditPredictionsMode; use crate::language_settings::SoftWrap; +pub use crate::language_settings::{EditPredictionsMode, IndentGuideSettings}; use anyhow::{Context as _, Result}; use async_trait::async_trait; use collections::{HashMap, HashSet, IndexSet}; diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs index 149492e7f188ce43894c1a07d34c49ce589dc59e..a37e74b13f9cd789868e7bed5218e1e5efb0c7af 100644 --- a/crates/language/src/language_settings.rs +++ b/crates/language/src/language_settings.rs @@ -13,13 +13,13 @@ use schemars::json_schema; pub use settings::{ CompletionSettingsContent, EditPredictionProvider, EditPredictionsMode, FormatOnSave, - Formatter, FormatterList, IndentGuideSettings, InlayHintKind, LanguageSettingsContent, + Formatter, FormatterList, IndentGuideSettingsContent, InlayHintKind, LanguageSettingsContent, LspInsertMode, RewrapBehavior, SelectedFormatter, ShowWhitespaceSetting, SoftWrap, WordsCompletionMode, }; use settings::{ - ParameterizedJsonSchema, PrettierSettingsContent, Settings, SettingsContent, SettingsLocation, - SettingsStore, SettingsUi, + LanguageTaskSettingsContent, ParameterizedJsonSchema, PrettierSettingsContent, Settings, + SettingsContent, SettingsLocation, SettingsStore, SettingsUi, }; use shellexpand; use std::{borrow::Cow, num::NonZeroU32, path::Path, sync::Arc}; @@ -150,7 +150,7 @@ pub struct LanguageSettings { /// Whether to perform linked edits pub linked_edits: bool, /// Task configuration for this language. - pub tasks: settings::LanguageTaskConfig, + pub tasks: LanguageTaskSettings, /// Whether to pop the completions menu while typing in an editor without /// explicitly requesting it. pub show_completions_on_input: bool, @@ -202,6 +202,70 @@ impl CompletionSettings { } } +/// The settings for indent guides. +#[derive(Debug, Clone, PartialEq)] +pub struct IndentGuideSettings { + /// Whether to display indent guides in the editor. + /// + /// Default: true + pub enabled: bool, + /// The width of the indent guides in pixels, between 1 and 10. + /// + /// Default: 1 + pub line_width: u32, + /// The width of the active indent guide in pixels, between 1 and 10. + /// + /// Default: 1 + pub active_line_width: u32, + /// Determines how indent guides are colored. + /// + /// Default: Fixed + pub coloring: settings::IndentGuideColoring, + /// Determines how indent guide backgrounds are colored. + /// + /// Default: Disabled + pub background_coloring: settings::IndentGuideBackgroundColoring, +} + +impl IndentGuideSettings { + pub fn merge_from(&mut self, src: &Option) { + let Some(src) = src else { return }; + + self.enabled.merge_from(&src.enabled); + self.line_width.merge_from(&src.line_width); + self.active_line_width.merge_from(&src.active_line_width); + self.coloring.merge_from(&src.coloring); + self.background_coloring + .merge_from(&src.background_coloring); + } +} + +#[derive(Debug, Clone)] +pub struct LanguageTaskSettings { + /// Extra task variables to set for a particular language. + pub variables: HashMap, + pub enabled: bool, + /// Use LSP tasks over Zed language extension ones. + /// If no LSP tasks are returned due to error/timeout or regular execution, + /// Zed language extension tasks will be used instead. + /// + /// Other Zed tasks will still be shown: + /// * Zed task from either of the task config file + /// * Zed task from history (e.g. one-off task was spawned before) + pub prefer_lsp: bool, +} + +impl LanguageTaskSettings { + pub fn merge_from(&mut self, src: &Option) { + let Some(src) = src.clone() else { + return; + }; + self.variables.extend(src.variables); + self.enabled.merge_from(&src.enabled); + self.prefer_lsp.merge_from(&src.prefer_lsp); + } +} + /// Allows to enable/disable formatting with Prettier /// and configure default Prettier, used when no project-level Prettier installation is found. /// Prettier formatting is disabled by default. @@ -517,6 +581,8 @@ impl settings::Settings for AllLanguageSettings { let inlay_hints = defaults.inlay_hints.unwrap(); let completions = defaults.completions.unwrap(); let prettier = defaults.prettier.unwrap(); + let indent_guides = defaults.indent_guides.unwrap(); + let tasks = defaults.tasks.unwrap(); let default_language_settings = LanguageSettings { tab_size: defaults.tab_size.unwrap(), @@ -525,7 +591,13 @@ impl settings::Settings for AllLanguageSettings { preferred_line_length: defaults.preferred_line_length.unwrap(), show_wrap_guides: defaults.show_wrap_guides.unwrap(), wrap_guides: defaults.wrap_guides.unwrap(), - indent_guides: defaults.indent_guides.unwrap(), + indent_guides: IndentGuideSettings { + enabled: indent_guides.enabled.unwrap(), + line_width: indent_guides.line_width.unwrap(), + active_line_width: indent_guides.active_line_width.unwrap(), + coloring: indent_guides.coloring.unwrap(), + background_coloring: indent_guides.background_coloring.unwrap(), + }, format_on_save: defaults.format_on_save.unwrap(), remove_trailing_whitespace_on_save: defaults .remove_trailing_whitespace_on_save @@ -568,7 +640,11 @@ impl settings::Settings for AllLanguageSettings { .unwrap(), code_actions_on_format: defaults.code_actions_on_format.unwrap(), linked_edits: defaults.linked_edits.unwrap(), - tasks: defaults.tasks.unwrap(), + tasks: LanguageTaskSettings { + variables: tasks.variables, + enabled: tasks.enabled.unwrap(), + prefer_lsp: tasks.prefer_lsp.unwrap(), + }, show_completions_on_input: defaults.show_completions_on_input.unwrap(), show_completion_documentation: defaults.show_completion_documentation.unwrap(), completions: CompletionSettings { @@ -787,14 +863,7 @@ impl settings::Settings for AllLanguageSettings { d.wrap_guides = arr; } if let Some(b) = vscode.read_bool("editor.guides.indentation") { - if let Some(guide_settings) = d.indent_guides.as_mut() { - guide_settings.enabled = b; - } else { - d.indent_guides = Some(IndentGuideSettings { - enabled: b, - ..Default::default() - }); - } + d.indent_guides.get_or_insert_default().enabled = Some(b); } if let Some(b) = vscode.read_bool("editor.guides.formatOnSave") { @@ -918,7 +987,7 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent .code_actions_on_format .merge_from(&src.code_actions_on_format.clone()); settings.linked_edits.merge_from(&src.linked_edits); - settings.tasks.merge_from(&src.tasks.clone()); + settings.tasks.merge_from(&src.tasks); settings .preferred_line_length diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs index 272caf28c8b8e6d1516292e49fb34817f1a1d062..2ceeffc89061aa429727142a1659a392d6374b09 100644 --- a/crates/multi_buffer/src/multi_buffer.rs +++ b/crates/multi_buffer/src/multi_buffer.rs @@ -17,11 +17,11 @@ use gpui::{App, AppContext as _, Context, Entity, EntityId, EventEmitter, Task}; use itertools::Itertools; use language::{ AutoindentMode, Buffer, BufferChunks, BufferRow, BufferSnapshot, Capability, CharClassifier, - CharKind, Chunk, CursorShape, DiagnosticEntry, DiskState, File, IndentSize, Language, - LanguageScope, OffsetRangeExt, OffsetUtf16, Outline, OutlineItem, Point, PointUtf16, Selection, - TextDimension, TextObject, ToOffset as _, ToPoint as _, TransactionId, TreeSitterOptions, - Unclipped, - language_settings::{IndentGuideSettings, LanguageSettings, language_settings}, + CharKind, Chunk, CursorShape, DiagnosticEntry, DiskState, File, IndentGuideSettings, + IndentSize, Language, LanguageScope, OffsetRangeExt, OffsetUtf16, Outline, OutlineItem, Point, + PointUtf16, Selection, TextDimension, TextObject, ToOffset as _, ToPoint as _, TransactionId, + TreeSitterOptions, Unclipped, + language_settings::{LanguageSettings, language_settings}, }; use rope::DimensionPair; diff --git a/crates/settings/src/settings_content/language.rs b/crates/settings/src/settings_content/language.rs index 03e6c9cffeadb15a9bc0aaa387eb472559e9ff57..f1333d8e405bf492a2e3a69184d56184f378642d 100644 --- a/crates/settings/src/settings_content/language.rs +++ b/crates/settings/src/settings_content/language.rs @@ -154,7 +154,7 @@ pub struct LanguageSettingsContent { /// Default: [] pub wrap_guides: Option>, /// Indent guide related settings. - pub indent_guides: Option, + pub indent_guides: Option, /// Whether or not to perform a buffer format before saving. /// /// Default: on @@ -269,7 +269,7 @@ pub struct LanguageSettingsContent { /// Task configuration for this language. /// /// Default: {} - pub tasks: Option, + pub tasks: Option, /// Whether to pop the completions menu while typing in an editor without /// explicitly requesting it. /// @@ -757,55 +757,37 @@ pub enum Formatter { /// The settings for indent guides. #[skip_serializing_none] #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -pub struct IndentGuideSettings { +pub struct IndentGuideSettingsContent { /// Whether to display indent guides in the editor. /// /// Default: true - #[serde(default = "default_true")] - pub enabled: bool, + pub enabled: Option, /// The width of the indent guides in pixels, between 1 and 10. /// /// Default: 1 - #[serde(default = "line_width")] - pub line_width: u32, + pub line_width: Option, /// The width of the active indent guide in pixels, between 1 and 10. /// /// Default: 1 - #[serde(default = "active_line_width")] - pub active_line_width: u32, + pub active_line_width: Option, /// Determines how indent guides are colored. /// /// Default: Fixed - #[serde(default)] - pub coloring: IndentGuideColoring, + pub coloring: Option, /// Determines how indent guide backgrounds are colored. /// /// Default: Disabled - #[serde(default)] - pub background_coloring: IndentGuideBackgroundColoring, -} - -fn default_true() -> bool { - true -} - -fn line_width() -> u32 { - 1 -} - -fn active_line_width() -> u32 { - line_width() + pub background_coloring: Option, } /// The task settings for a particular language. #[skip_serializing_none] #[derive(Debug, Clone, Deserialize, PartialEq, Serialize, JsonSchema)] -pub struct LanguageTaskConfig { +pub struct LanguageTaskSettingsContent { /// Extra task variables to set for a particular language. #[serde(default)] pub variables: HashMap, - #[serde(default = "default_true")] - pub enabled: bool, + pub enabled: Option, /// Use LSP tasks over Zed language extension ones. /// If no LSP tasks are returned due to error/timeout or regular execution, /// Zed language extension tasks will be used instead. @@ -813,8 +795,7 @@ pub struct LanguageTaskConfig { /// Other Zed tasks will still be shown: /// * Zed task from either of the task config file /// * Zed task from history (e.g. one-off task was spawned before) - #[serde(default = "default_true")] - pub prefer_lsp: bool, + pub prefer_lsp: Option, } /// Map from language name to settings. Its `ParameterizedJsonSchema` allows only known language diff --git a/crates/settings/src/settings_content/language_model.rs b/crates/settings/src/settings_content/language_model.rs index 1039b505a37df9469d144f3574037a12dcf5f9f4..cad06d5fff78d1fa4ad9cd8830ab24a438d3c9ea 100644 --- a/crates/settings/src/settings_content/language_model.rs +++ b/crates/settings/src/settings_content/language_model.rs @@ -368,7 +368,6 @@ pub struct OpenRouterAvailableModel { #[skip_serializing_none] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct OpenRouterProvider { - #[serde(skip_serializing_if = "Option::is_none")] order: Option>, #[serde(default = "default_true")] allow_fallbacks: bool, @@ -376,13 +375,9 @@ pub struct OpenRouterProvider { require_parameters: bool, #[serde(default)] data_collection: DataCollection, - #[serde(skip_serializing_if = "Option::is_none")] only: Option>, - #[serde(skip_serializing_if = "Option::is_none")] ignore: Option>, - #[serde(skip_serializing_if = "Option::is_none")] quantizations: Option>, - #[serde(skip_serializing_if = "Option::is_none")] sort: Option, }