use std::{borrow::Cow, num::NonZeroU32}; use collections::{HashMap, HashSet};use schemars::JsonSchema;use serde::{Deserialize, Serialize};use settings_macros::{MergeFrom, with_fallible_options};use std::sync::Arc; use crate::{DocumentFoldingRanges, DocumentSymbols, ExtendingSet, SemanticTokens, merge_from}; /// The state of the modifier keys at some point in time#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom)]pub struct ModifiersContent { /// The control key #[serde(default)] pub control: bool, /// The alt key /// Sometimes also known as the 'meta' key #[serde(default)] pub alt: bool, /// The shift key #[serde(default)] pub shift: bool, /// The command key, on macos /// the windows key, on windows /// the super key, on linux #[serde(default)] pub platform: bool, /// The function key #[serde(default)] pub function: bool,} #[with_fallible_options]#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]pub struct AllLanguageSettingsContent { /// The edit prediction settings. pub edit_predictions: Option<EditPredictionSettingsContent>, /// The default language settings. #[serde(flatten)] pub defaults: LanguageSettingsContent, /// The settings for individual languages. #[serde(default)] pub languages: LanguageToSettingsMap, /// Settings for associating file extensions and filenames /// with languages. pub file_types: Option<FileTypeMap>,} impl merge_from::MergeFrom for AllLanguageSettingsContent { fn merge_from(&mut self, other: &Self) { self.file_types.merge_from(&other.file_types); self.edit_predictions.merge_from(&other.edit_predictions); // A user's global settings override the default global settings and // all default language-specific settings. self.defaults.merge_from(&other.defaults); for language_settings in self.languages.0.values_mut() { let language_servers = language_settings.language_servers.take(); language_settings.merge_from(&other.defaults); language_settings.language_servers = language_servers; } // A user's language-specific settings override default language-specific settings. for (language_name, user_language_settings) in &other.languages.0 { if let Some(existing) = self.languages.0.get_mut(language_name) { existing.merge_from(&user_language_settings); } else { let mut new_settings = self.defaults.clone(); new_settings.language_servers = None; new_settings.merge_from(&user_language_settings); self.languages.0.insert(language_name.clone(), new_settings); } } }} /// The provider that supplies edit predictions.#[derive( Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom,)]#[serde(rename_all = "snake_case")]pub enum EditPredictionProvider { None, #[default] Copilot, Zed, Codestral, Ollama, OpenAiCompatibleApi, Mercury,} impl EditPredictionProvider { pub fn is_zed(&self) -> bool { match self { EditPredictionProvider::Zed => true, EditPredictionProvider::None | EditPredictionProvider::Copilot | EditPredictionProvider::Codestral | EditPredictionProvider::Ollama | EditPredictionProvider::OpenAiCompatibleApi | EditPredictionProvider::Mercury => false, } } pub fn display_name(&self) -> Option<&'static str> { match self { EditPredictionProvider::Zed => Some("Zed AI"), EditPredictionProvider::Copilot => Some("GitHub Copilot"), EditPredictionProvider::Codestral => Some("Codestral"), EditPredictionProvider::Mercury => Some("Mercury"), EditPredictionProvider::None => None, EditPredictionProvider::Ollama => Some("Ollama"), EditPredictionProvider::OpenAiCompatibleApi => Some("OpenAI-Compatible API"), } }} /// The contents of the edit prediction settings.#[with_fallible_options]#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]pub struct EditPredictionSettingsContent { /// Determines which edit prediction provider to use. pub provider: Option<EditPredictionProvider>, /// A list of globs representing files that edit predictions should be disabled for. /// This list adds to a pre-existing, sensible default set of globs. /// Any additional ones you add are combined with them. pub disabled_globs: Option<Vec<String>>, /// The mode used to display edit predictions in the buffer. /// Provider support required. pub mode: Option<EditPredictionsMode>, /// Settings specific to GitHub Copilot. pub copilot: Option<CopilotSettingsContent>, /// Settings specific to Codestral. pub codestral: Option<CodestralSettingsContent>, /// Settings specific to Ollama. pub ollama: Option<OllamaEditPredictionSettingsContent>, /// Settings specific to using custom OpenAI-compatible servers for edit prediction. pub open_ai_compatible_api: Option<CustomEditPredictionProviderSettingsContent>, /// Controls whether Zed may collect training data when using Zed's Edit Predictions. /// Data is only ever captured for files in projects that are detected as open source. /// /// - `"default"`: use the preference previously set via the status-bar toggle, /// or false if no preference has been stored. /// - `"yes"`: allow data collection for files in open-source projects. /// - `"no"`: never allow data collection. pub allow_data_collection: Option<EditPredictionDataCollectionChoice>,} #[with_fallible_options]#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]pub struct CustomEditPredictionProviderSettingsContent { /// Api URL to use for completions. /// /// Default: "" pub api_url: Option<String>, /// The prompt format to use for completions. Set to `""` to have the format be derived from the model name. /// /// Default: "" pub prompt_format: Option<EditPredictionPromptFormatContent>, /// The name of the model. /// /// Default: "" pub model: Option<String>, /// Maximum tokens to generate. /// /// Default: 256 pub max_output_tokens: Option<u32>,} #[derive( Copy, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames,)]#[serde(rename_all = "snake_case")]pub enum EditPredictionPromptFormatContent { #[default] Infer, Zeta, Zeta2, Zeta2_1, CodeLlama, StarCoder, DeepseekCoder, Qwen, CodeGemma, Codestral, Glm,} #[with_fallible_options]#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]pub struct CopilotSettingsContent { /// HTTP/HTTPS proxy to use for Copilot. /// /// Default: none pub proxy: Option<String>, /// Disable certificate verification for the proxy (not recommended). /// /// Default: false pub proxy_no_verify: Option<bool>, /// Enterprise URI for Copilot. /// /// Default: none pub enterprise_uri: Option<String>, /// Whether the Copilot Next Edit Suggestions feature is enabled. /// /// Default: true pub enable_next_edit_suggestions: Option<bool>,} #[with_fallible_options]#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]pub struct CodestralSettingsContent { /// Model to use for completions. /// /// Default: "codestral-latest" pub model: Option<String>, /// Maximum tokens to generate. /// /// Default: 150 pub max_tokens: Option<u32>, /// Api URL to use for completions. /// /// Default: "https://codestral.mistral.ai" pub api_url: Option<String>,} /// Ollama model name for edit predictions.#[with_fallible_options]#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]#[serde(transparent)]pub struct OllamaModelName(pub String); impl AsRef<str> for OllamaModelName { fn as_ref(&self) -> &str { &self.0 }} impl From<String> for OllamaModelName { fn from(value: String) -> Self { Self(value) }} impl From<OllamaModelName> for String { fn from(value: OllamaModelName) -> Self { value.0 }} #[with_fallible_options]#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]pub struct OllamaEditPredictionSettingsContent { /// Model to use for completions. /// /// Default: none pub model: Option<OllamaModelName>, /// Maximum tokens to generate for FIM models. /// /// Default: 256 pub max_output_tokens: Option<u32>, /// Api URL to use for completions. /// /// Default: "http://localhost:11434" pub api_url: Option<String>, /// The prompt format to use for completions. Set to `""` to have the format be derived from the model name. /// /// Default: "" pub prompt_format: Option<EditPredictionPromptFormatContent>,} /// Controls whether Zed collects training data when using Zed's Edit Predictions.#[derive( Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames,)]#[serde(rename_all = "snake_case")]pub enum EditPredictionDataCollectionChoice { /// Use the preference previously set via the status-bar toggle, or false /// if no preference has been stored. #[default] Default, /// Allow Zed to collect training data from open-source projects. Yes, /// Never allow training data collection. No,} /// The mode in which edit predictions should be displayed.#[derive( Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames,)]#[serde(rename_all = "snake_case")]pub enum EditPredictionsMode { /// If provider supports it, display inline when holding modifier key (e.g., alt). /// Otherwise, eager preview is used. #[serde(alias = "auto")] Subtle, /// Display inline when there are no language server completions available. #[default] #[serde(alias = "eager_preview")] Eager,} /// Controls the soft-wrapping behavior in the editor.#[derive( Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames,)]#[serde(rename_all = "snake_case")]pub enum AutoIndentMode { /// Adjusts indentation based on syntax context when typing. /// Uses tree-sitter to analyze code structure and indent accordingly. SyntaxAware, /// Preserve the indentation of the current line when creating new lines, /// but don't adjust based on syntax context. PreserveIndent, /// No automatic indentation. New lines start at column 0. None,} /// Controls the soft-wrapping behavior in the editor.#[derive( Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames,)]#[serde(rename_all = "snake_case")]pub enum SoftWrap { /// Prefer a single line generally, unless an overly long line is encountered. None, /// Deprecated: use None instead. Left to avoid breaking existing users' configs. /// Prefer a single line generally, unless an overly long line is encountered. PreferLine, /// Soft wrap lines that exceed the editor width. EditorWidth, /// Soft wrap line at the preferred line length or the editor width (whichever is smaller). #[serde(alias = "preferred_line_length")] Bounded,} pub const REST_OF_LANGUAGE_SERVERS: &str = "..."; #[derive(Clone, Debug, PartialEq, Eq, JsonSchema)]#[schemars(with = "String")]pub struct ConfiguredLanguageServer { pub name: Arc<str>, pub disabled: bool,} impl ConfiguredLanguageServer { const DISABLED_CHAR: char = '!'; pub fn new(name: impl Into<Arc<str>>) -> Self { Self { name: name.into(), disabled: false, } } pub fn new_disabled(name: impl Into<Arc<str>>) -> Self { Self { name: name.into(), disabled: true, } }} impl From<&str> for ConfiguredLanguageServer { fn from(value: &str) -> Self { match value.strip_prefix(Self::DISABLED_CHAR) { Some(name) => Self::new_disabled(name), None => Self::new(value), } }} impl Serialize for ConfiguredLanguageServer { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer, { if self.disabled { serializer.collect_str(&format_args!("{}{}", Self::DISABLED_CHAR, self.name)) } else { serializer.serialize_str(&self.name) } }} impl<'de> Deserialize<'de> for ConfiguredLanguageServer { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de>, { let value = Cow::<'de, str>::deserialize(deserializer)?; Ok(Self::from(value.as_ref())) }} /// The settings for a particular language.#[with_fallible_options]#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]pub struct LanguageSettingsContent { /// How many columns a tab should occupy. /// /// Default: 4 #[schemars(range(min = 1, max = 128))] pub tab_size: Option<NonZeroU32>, /// Whether to indent lines using tab characters, as opposed to multiple /// spaces. /// /// Default: false pub hard_tabs: Option<bool>, /// How to soft-wrap long lines of text. /// /// Default: none pub soft_wrap: Option<SoftWrap>, /// The column at which to soft-wrap lines, for buffers where soft-wrap /// is enabled. /// /// Default: 80 pub preferred_line_length: Option<u32>, /// Whether to show wrap guides in the editor. Setting this to true will /// show a guide at the 'preferred_line_length' value if softwrap is set to /// 'preferred_line_length', and will show any additional guides as specified /// by the 'wrap_guides' setting. /// /// Default: true pub show_wrap_guides: Option<bool>, /// Character counts at which to show wrap guides in the editor. /// /// Default: [] pub wrap_guides: Option<Vec<usize>>, /// Indent guide related settings. pub indent_guides: Option<IndentGuideSettingsContent>, /// Whether or not to perform a buffer format before saving. /// /// Default: on pub format_on_save: Option<FormatOnSave>, /// Whether or not to remove any trailing whitespace from lines of a buffer /// before saving it. /// /// Default: true pub remove_trailing_whitespace_on_save: Option<bool>, /// Whether or not to ensure there's a single newline at the end of a buffer /// when saving it.Lines 1–500 of 1602. Load more
use std::{borrow::Cow, num::NonZeroU32}; use collections::{HashMap, HashSet}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use settings_macros::{MergeFrom, with_fallible_options}; use std::sync::Arc; use crate::{DocumentFoldingRanges, DocumentSymbols, ExtendingSet, SemanticTokens, merge_from}; /// The state of the modifier keys at some point in time #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom)] pub struct ModifiersContent { /// The control key #[serde(default)] pub control: bool, /// The alt key /// Sometimes also known as the 'meta' key #[serde(default)] pub alt: bool, /// The shift key #[serde(default)] pub shift: bool, /// The command key, on macos /// the windows key, on windows /// the super key, on linux #[serde(default)] pub platform: bool, /// The function key #[serde(default)] pub function: bool, } #[with_fallible_options] #[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct AllLanguageSettingsContent { /// The edit prediction settings. pub edit_predictions: Option<EditPredictionSettingsContent>, /// The default language settings. #[serde(flatten)] pub defaults: LanguageSettingsContent, /// The settings for individual languages. #[serde(default)] pub languages: LanguageToSettingsMap, /// Settings for associating file extensions and filenames /// with languages. pub file_types: Option<FileTypeMap>, } impl merge_from::MergeFrom for AllLanguageSettingsContent { fn merge_from(&mut self, other: &Self) { self.file_types.merge_from(&other.file_types); self.edit_predictions.merge_from(&other.edit_predictions); // A user's global settings override the default global settings and // all default language-specific settings. self.defaults.merge_from(&other.defaults); for language_settings in self.languages.0.values_mut() { let language_servers = language_settings.language_servers.take(); language_settings.merge_from(&other.defaults); language_settings.language_servers = language_servers; } // A user's language-specific settings override default language-specific settings. for (language_name, user_language_settings) in &other.languages.0 { if let Some(existing) = self.languages.0.get_mut(language_name) { existing.merge_from(&user_language_settings); } else { let mut new_settings = self.defaults.clone(); new_settings.language_servers = None; new_settings.merge_from(&user_language_settings); self.languages.0.insert(language_name.clone(), new_settings); } } } } /// The provider that supplies edit predictions. #[derive( Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom, )] #[serde(rename_all = "snake_case")] pub enum EditPredictionProvider { None, #[default] Copilot, Zed, Codestral, Ollama, OpenAiCompatibleApi, Mercury, } impl EditPredictionProvider { pub fn is_zed(&self) -> bool { match self { EditPredictionProvider::Zed => true, EditPredictionProvider::None | EditPredictionProvider::Copilot | EditPredictionProvider::Codestral | EditPredictionProvider::Ollama | EditPredictionProvider::OpenAiCompatibleApi | EditPredictionProvider::Mercury => false, } } pub fn display_name(&self) -> Option<&'static str> { match self { EditPredictionProvider::Zed => Some("Zed AI"), EditPredictionProvider::Copilot => Some("GitHub Copilot"), EditPredictionProvider::Codestral => Some("Codestral"), EditPredictionProvider::Mercury => Some("Mercury"), EditPredictionProvider::None => None, EditPredictionProvider::Ollama => Some("Ollama"), EditPredictionProvider::OpenAiCompatibleApi => Some("OpenAI-Compatible API"), } } } /// The contents of the edit prediction settings. #[with_fallible_options] #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)] pub struct EditPredictionSettingsContent { /// Determines which edit prediction provider to use. pub provider: Option<EditPredictionProvider>, /// A list of globs representing files that edit predictions should be disabled for. /// This list adds to a pre-existing, sensible default set of globs. /// Any additional ones you add are combined with them. pub disabled_globs: Option<Vec<String>>, /// The mode used to display edit predictions in the buffer. /// Provider support required. pub mode: Option<EditPredictionsMode>, /// Settings specific to GitHub Copilot. pub copilot: Option<CopilotSettingsContent>, /// Settings specific to Codestral. pub codestral: Option<CodestralSettingsContent>, /// Settings specific to Ollama. pub ollama: Option<OllamaEditPredictionSettingsContent>, /// Settings specific to using custom OpenAI-compatible servers for edit prediction. pub open_ai_compatible_api: Option<CustomEditPredictionProviderSettingsContent>, /// Controls whether Zed may collect training data when using Zed's Edit Predictions. /// Data is only ever captured for files in projects that are detected as open source. /// /// - `"default"`: use the preference previously set via the status-bar toggle, /// or false if no preference has been stored. /// - `"yes"`: allow data collection for files in open-source projects. /// - `"no"`: never allow data collection. pub allow_data_collection: Option<EditPredictionDataCollectionChoice>, } #[with_fallible_options] #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)] pub struct CustomEditPredictionProviderSettingsContent { /// Api URL to use for completions. /// /// Default: "" pub api_url: Option<String>, /// The prompt format to use for completions. Set to `""` to have the format be derived from the model name. /// /// Default: "" pub prompt_format: Option<EditPredictionPromptFormatContent>, /// The name of the model. /// /// Default: "" pub model: Option<String>, /// Maximum tokens to generate. /// /// Default: 256 pub max_output_tokens: Option<u32>, } #[derive( Copy, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum EditPredictionPromptFormatContent { #[default] Infer, Zeta, Zeta2, Zeta2_1, CodeLlama, StarCoder, DeepseekCoder, Qwen, CodeGemma, Codestral, Glm, } #[with_fallible_options] #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)] pub struct CopilotSettingsContent { /// HTTP/HTTPS proxy to use for Copilot. /// /// Default: none pub proxy: Option<String>, /// Disable certificate verification for the proxy (not recommended). /// /// Default: false pub proxy_no_verify: Option<bool>, /// Enterprise URI for Copilot. /// /// Default: none pub enterprise_uri: Option<String>, /// Whether the Copilot Next Edit Suggestions feature is enabled. /// /// Default: true pub enable_next_edit_suggestions: Option<bool>, } #[with_fallible_options] #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)] pub struct CodestralSettingsContent { /// Model to use for completions. /// /// Default: "codestral-latest" pub model: Option<String>, /// Maximum tokens to generate. /// /// Default: 150 pub max_tokens: Option<u32>, /// Api URL to use for completions. /// /// Default: "https://codestral.mistral.ai" pub api_url: Option<String>, } /// Ollama model name for edit predictions. #[with_fallible_options] #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)] #[serde(transparent)] pub struct OllamaModelName(pub String); impl AsRef<str> for OllamaModelName { fn as_ref(&self) -> &str { &self.0 } } impl From<String> for OllamaModelName { fn from(value: String) -> Self { Self(value) } } impl From<OllamaModelName> for String { fn from(value: OllamaModelName) -> Self { value.0 } } #[with_fallible_options] #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)] pub struct OllamaEditPredictionSettingsContent { /// Model to use for completions. /// /// Default: none pub model: Option<OllamaModelName>, /// Maximum tokens to generate for FIM models. /// /// Default: 256 pub max_output_tokens: Option<u32>, /// Api URL to use for completions. /// /// Default: "http://localhost:11434" pub api_url: Option<String>, /// The prompt format to use for completions. Set to `""` to have the format be derived from the model name. /// /// Default: "" pub prompt_format: Option<EditPredictionPromptFormatContent>, } /// Controls whether Zed collects training data when using Zed's Edit Predictions. #[derive( Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum EditPredictionDataCollectionChoice { /// Use the preference previously set via the status-bar toggle, or false /// if no preference has been stored. #[default] Default, /// Allow Zed to collect training data from open-source projects. Yes, /// Never allow training data collection. No, } /// The mode in which edit predictions should be displayed. #[derive( Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum EditPredictionsMode { /// If provider supports it, display inline when holding modifier key (e.g., alt). /// Otherwise, eager preview is used. #[serde(alias = "auto")] Subtle, /// Display inline when there are no language server completions available. #[default] #[serde(alias = "eager_preview")] Eager, } /// Controls the soft-wrapping behavior in the editor. #[derive( Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum AutoIndentMode { /// Adjusts indentation based on syntax context when typing. /// Uses tree-sitter to analyze code structure and indent accordingly. SyntaxAware, /// Preserve the indentation of the current line when creating new lines, /// but don't adjust based on syntax context. PreserveIndent, /// No automatic indentation. New lines start at column 0. None, } /// Controls the soft-wrapping behavior in the editor. #[derive( Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum SoftWrap { /// Prefer a single line generally, unless an overly long line is encountered. None, /// Deprecated: use None instead. Left to avoid breaking existing users' configs. /// Prefer a single line generally, unless an overly long line is encountered. PreferLine, /// Soft wrap lines that exceed the editor width. EditorWidth, /// Soft wrap line at the preferred line length or the editor width (whichever is smaller). #[serde(alias = "preferred_line_length")] Bounded, } pub const REST_OF_LANGUAGE_SERVERS: &str = "..."; #[derive(Clone, Debug, PartialEq, Eq, JsonSchema)] #[schemars(with = "String")] pub struct ConfiguredLanguageServer { pub name: Arc<str>, pub disabled: bool, } impl ConfiguredLanguageServer { const DISABLED_CHAR: char = '!'; pub fn new(name: impl Into<Arc<str>>) -> Self { Self { name: name.into(), disabled: false, } } pub fn new_disabled(name: impl Into<Arc<str>>) -> Self { Self { name: name.into(), disabled: true, } } } impl From<&str> for ConfiguredLanguageServer { fn from(value: &str) -> Self { match value.strip_prefix(Self::DISABLED_CHAR) { Some(name) => Self::new_disabled(name), None => Self::new(value), } } } impl Serialize for ConfiguredLanguageServer { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer, { if self.disabled { serializer.collect_str(&format_args!("{}{}", Self::DISABLED_CHAR, self.name)) } else { serializer.serialize_str(&self.name) } } } impl<'de> Deserialize<'de> for ConfiguredLanguageServer { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de>, { let value = Cow::<'de, str>::deserialize(deserializer)?; Ok(Self::from(value.as_ref())) } } /// The settings for a particular language. #[with_fallible_options] #[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)] pub struct LanguageSettingsContent { /// How many columns a tab should occupy. /// /// Default: 4 #[schemars(range(min = 1, max = 128))] pub tab_size: Option<NonZeroU32>, /// Whether to indent lines using tab characters, as opposed to multiple /// spaces. /// /// Default: false pub hard_tabs: Option<bool>, /// How to soft-wrap long lines of text. /// /// Default: none pub soft_wrap: Option<SoftWrap>, /// The column at which to soft-wrap lines, for buffers where soft-wrap /// is enabled. /// /// Default: 80 pub preferred_line_length: Option<u32>, /// Whether to show wrap guides in the editor. Setting this to true will /// show a guide at the 'preferred_line_length' value if softwrap is set to /// 'preferred_line_length', and will show any additional guides as specified /// by the 'wrap_guides' setting. /// /// Default: true pub show_wrap_guides: Option<bool>, /// Character counts at which to show wrap guides in the editor. /// /// Default: [] pub wrap_guides: Option<Vec<usize>>, /// Indent guide related settings. pub indent_guides: Option<IndentGuideSettingsContent>, /// Whether or not to perform a buffer format before saving. /// /// Default: on pub format_on_save: Option<FormatOnSave>, /// Whether or not to remove any trailing whitespace from lines of a buffer /// before saving it. /// /// Default: true pub remove_trailing_whitespace_on_save: Option<bool>, /// Whether or not to ensure there's a single newline at the end of a buffer /// when saving it.