//! Provides `language`-related settings. use crate::{File, Language, LanguageName, LanguageServerName};use anyhow::Result;use collections::{HashMap, HashSet};use core::slice;use ec4rs::{ property::{FinalNewline, IndentSize, IndentStyle, TabWidth, TrimTrailingWs}, Properties as EditorconfigProperties,};use globset::{Glob, GlobMatcher, GlobSet, GlobSetBuilder};use gpui::{App, Modifiers};use itertools::{Either, Itertools};use schemars::{ schema::{InstanceType, ObjectValidation, Schema, SchemaObject, SingleOrVec}, JsonSchema,};use serde::{ de::{self, IntoDeserializer, MapAccess, SeqAccess, Visitor}, Deserialize, Deserializer, Serialize,};use serde_json::Value;use settings::{ add_references_to_properties, Settings, SettingsLocation, SettingsSources, SettingsStore,};use std::{borrow::Cow, num::NonZeroU32, path::Path, sync::Arc};use util::serde::default_true; /// Initializes the language settings.pub fn init(cx: &mut App) { AllLanguageSettings::register(cx);} /// Returns the settings for the specified language from the provided file.pub fn language_settings<'a>( language: Option<LanguageName>, file: Option<&'a Arc<dyn File>>, cx: &'a App,) -> Cow<'a, LanguageSettings> { let location = file.map(|f| SettingsLocation { worktree_id: f.worktree_id(cx), path: f.path().as_ref(), }); AllLanguageSettings::get(location, cx).language(location, language.as_ref(), cx)} /// Returns the settings for all languages from the provided file.pub fn all_language_settings<'a>( file: Option<&'a Arc<dyn File>>, cx: &'a App,) -> &'a AllLanguageSettings { let location = file.map(|f| SettingsLocation { worktree_id: f.worktree_id(cx), path: f.path().as_ref(), }); AllLanguageSettings::get(location, cx)} /// The settings for all languages.#[derive(Debug, Clone)]pub struct AllLanguageSettings { /// The edit prediction settings. pub edit_predictions: EditPredictionSettings, defaults: LanguageSettings, languages: HashMap<LanguageName, LanguageSettings>, pub(crate) file_types: HashMap<Arc<str>, GlobSet>,} /// The settings for a particular language.#[derive(Debug, Clone, Deserialize)]pub struct LanguageSettings { /// How many columns a tab should occupy. pub tab_size: NonZeroU32, /// Whether to indent lines using tab characters, as opposed to multiple /// spaces. pub hard_tabs: bool, /// How to soft-wrap long lines of text. pub soft_wrap: SoftWrap, /// The column at which to soft-wrap lines, for buffers where soft-wrap /// is enabled. pub preferred_line_length: u32, // Whether to show wrap guides (vertical rulers) 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. pub show_wrap_guides: bool, /// Character counts at which to show wrap guides (vertical rulers) in the editor. pub wrap_guides: Vec<usize>, /// Indent guide related settings. pub indent_guides: IndentGuideSettings, /// Whether or not to perform a buffer format before saving. pub format_on_save: FormatOnSave, /// Whether or not to remove any trailing whitespace from lines of a buffer /// before saving it. pub remove_trailing_whitespace_on_save: bool, /// Whether or not to ensure there's a single newline at the end of a buffer /// when saving it. pub ensure_final_newline_on_save: bool, /// How to perform a buffer format. pub formatter: SelectedFormatter, /// Zed's Prettier integration settings. pub prettier: PrettierSettings, /// Whether to automatically close JSX tags. pub jsx_tag_auto_close: JsxTagAutoCloseSettings, /// Whether to use language servers to provide code intelligence. pub enable_language_server: bool, /// The list of language servers to use (or disable) for this language. /// /// This array should consist of language server IDs, as well as the following /// special tokens: /// - `"!<language_server_id>"` - A language server ID prefixed with a `!` will be disabled. /// - `"..."` - A placeholder to refer to the **rest** of the registered language servers for this language. pub language_servers: Vec<String>, /// Controls where the `editor::Rewrap` action is allowed for this language. /// /// Note: This setting has no effect in Vim mode, as rewrap is already /// allowed everywhere. pub allow_rewrap: RewrapBehavior, /// Controls whether edit predictions are shown immediately (true) /// or manually by triggering `editor::ShowEditPrediction` (false). pub show_edit_predictions: bool, /// Controls whether edit predictions are shown in the given language /// scopes. pub edit_predictions_disabled_in: Vec<String>, /// Whether to show tabs and spaces in the editor. pub show_whitespaces: ShowWhitespaceSetting, /// 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: InlayHintSettings, /// Whether to automatically close brackets. 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, /// Whether indentation of pasted content should be adjusted based on the context. pub auto_indent_on_paste: bool, // Controls how the editor handles the autoclosed characters. pub always_treat_brackets_as_autoclosed: bool, /// Which code actions to run on save pub code_actions_on_format: HashMap<String, bool>, /// Whether to perform linked edits pub linked_edits: bool, /// Task configuration for this language. pub tasks: LanguageTaskConfig, /// Whether to pop the completions menu while typing in an editor without /// explicitly requesting it. pub show_completions_on_input: bool, /// Whether to display inline and alongside documentation for items in the /// completions menu. pub show_completion_documentation: bool,} impl LanguageSettings { /// A token representing the rest of the available language servers. const REST_OF_LANGUAGE_SERVERS: &'static str = "..."; /// Returns the customized list of language servers from the list of /// available language servers. pub fn customized_language_servers( &self, available_language_servers: &[LanguageServerName], ) -> Vec<LanguageServerName> { Self::resolve_language_servers(&self.language_servers, available_language_servers) } pub(crate) fn resolve_language_servers( configured_language_servers: &[String], available_language_servers: &[LanguageServerName], ) -> Vec<LanguageServerName> { let (disabled_language_servers, enabled_language_servers): ( Vec<LanguageServerName>, Vec<LanguageServerName>, ) = configured_language_servers.iter().partition_map( |language_server| match language_server.strip_prefix('!') { Some(disabled) => Either::Left(LanguageServerName(disabled.to_string().into())), None => Either::Right(LanguageServerName(language_server.clone().into())), }, ); let rest = available_language_servers .iter() .filter(|&available_language_server| { !disabled_language_servers.contains(&available_language_server) && !enabled_language_servers.contains(&available_language_server) }) .cloned() .collect::<Vec<_>>(); enabled_language_servers .into_iter() .flat_map(|language_server| { if language_server.0.as_ref() == Self::REST_OF_LANGUAGE_SERVERS { rest.clone() } else { vec![language_server.clone()] } }) .collect::<Vec<_>>() }} /// The provider that supplies edit predictions.#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum EditPredictionProvider { None, #[default] Copilot, Supermaven, Zed,} impl EditPredictionProvider { pub fn is_zed(&self) -> bool { match self { EditPredictionProvider::Zed => true, EditPredictionProvider::None | EditPredictionProvider::Copilot | EditPredictionProvider::Supermaven => false, } }} /// The settings for edit predictions, such as [GitHub Copilot](https://github.com/features/copilot)/// or [Supermaven](https://supermaven.com).#[derive(Clone, Debug, Default)]pub struct EditPredictionSettings { /// The provider that supplies edit predictions. pub provider: 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: Vec<DisabledGlob>, /// Configures how edit predictions are displayed in the buffer. pub mode: EditPredictionsMode, /// Settings specific to GitHub Copilot. pub copilot: CopilotSettings, /// Whether edit predictions are enabled in the assistant panel. /// This setting has no effect if globally disabled. pub enabled_in_assistant: bool,} impl EditPredictionSettings { /// Returns whether edit predictions are enabled for the given path. pub fn enabled_for_file(&self, file: &Arc<dyn File>, cx: &App) -> bool { !self.disabled_globs.iter().any(|glob| { if glob.is_absolute { file.as_local() .map_or(false, |local| glob.matcher.is_match(local.abs_path(cx))) } else { glob.matcher.is_match(file.path()) } }) }} #[derive(Clone, Debug)]pub struct DisabledGlob { matcher: GlobMatcher, is_absolute: bool,} /// The mode in which edit predictions should be displayed.#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]#[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,} #[derive(Clone, Debug, Default)]pub struct CopilotSettings { /// HTTP/HTTPS proxy to use for Copilot. pub proxy: Option<String>, /// Disable certificate verification for proxy (not recommended). pub proxy_no_verify: Option<bool>,} /// The settings for all languages.#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]pub struct AllLanguageSettingsContent { /// The settings for enabling/disabling features. #[serde(default)] pub features: Option<FeaturesContent>, /// The edit prediction settings. #[serde(default)] pub edit_predictions: Option<EditPredictionSettingsContent>, /// The default language settings. #[serde(flatten)] pub defaults: LanguageSettingsContent, /// The settings for individual languages. #[serde(default)] pub languages: HashMap<LanguageName, LanguageSettingsContent>, /// Settings for associating file extensions and filenames /// with languages. #[serde(default)] pub file_types: HashMap<Arc<str>, Vec<String>>,} /// The settings for a particular language.#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]pub struct LanguageSettingsContent { /// How many columns a tab should occupy. /// /// Default: 4 #[serde(default)] pub tab_size: Option<NonZeroU32>, /// Whether to indent lines using tab characters, as opposed to multiple /// spaces. /// /// Default: false #[serde(default)] pub hard_tabs: Option<bool>, /// How to soft-wrap long lines of text. /// /// Default: none #[serde(default)] pub soft_wrap: Option<SoftWrap>, /// The column at which to soft-wrap lines, for buffers where soft-wrap /// is enabled. /// /// Default: 80 #[serde(default)] 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 #[serde(default)] pub show_wrap_guides: Option<bool>, /// Character counts at which to show wrap guides in the editor. /// /// Default: [] #[serde(default)] pub wrap_guides: Option<Vec<usize>>, /// Indent guide related settings. #[serde(default)] pub indent_guides: Option<IndentGuideSettings>, /// Whether or not to perform a buffer format before saving. /// /// Default: on #[serde(default)] pub format_on_save: Option<FormatOnSave>, /// Whether or not to remove any trailing whitespace from lines of a buffer /// before saving it. /// /// Default: true #[serde(default)] 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. /// /// Default: true #[serde(default)] pub ensure_final_newline_on_save: Option<bool>, /// How to perform a buffer format. /// /// Default: auto #[serde(default)] pub formatter: Option<SelectedFormatter>, /// Zed's Prettier integration settings. /// Allows to enable/disable formatting with Prettier /// and configure default Prettier, used when no project-level Prettier installation is found. /// /// Default: off #[serde(default)] pub prettier: Option<PrettierSettings>, /// Whether to automatically close JSX tags. #[serde(default)] pub jsx_tag_auto_close: Option<JsxTagAutoCloseSettings>, /// Whether to use language servers to provide code intelligence. /// /// Default: true #[serde(default)] pub enable_language_server: Option<bool>, /// The list of language servers to use (or disable) for this language. /// /// This array should consist of language server IDs, as well as the following /// special tokens: /// - `"!<language_server_id>"` - A language server ID prefixed with a `!` will be disabled. /// - `"..."` - A placeholder to refer to the **rest** of the registered language servers for this language. /// /// Default: ["..."] #[serde(default)] pub language_servers: Option<Vec<String>>, /// Controls where the `editor::Rewrap` action is allowed for this language. /// /// Note: This setting has no effect in Vim mode, as rewrap is already /// allowed everywhere. /// /// Default: "in_comments" #[serde(default)] pub allow_rewrap: Option<RewrapBehavior>, /// Controls whether edit predictions are shown immediately (true) /// or manually by triggering `editor::ShowEditPrediction` (false). /// /// Default: true #[serde(default)] pub show_edit_predictions: Option<bool>, /// Controls whether edit predictions are shown in the given language /// scopes. /// /// Example: ["string", "comment"] /// /// Default: [] #[serde(default)] pub edit_predictions_disabled_in: Option<Vec<String>>, /// Whether to show tabs and spaces in the editor. #[serde(default)] pub show_whitespaces: Option<ShowWhitespaceSetting>, /// Whether to start a new line with a comment when a previous line is a comment as well. /// /// Default: true #[serde(default)] pub extend_comment_on_newline: Option<bool>, /// Inlay hint related settings. #[serde(default)] pub inlay_hints: Option<InlayHintSettings>, /// Whether to automatically type closing characters for you. For example, /// when you type (, Zed will automatically add a closing ) at the correct position. /// /// Default: true pub use_autoclose: Option<bool>, /// Whether to automatically surround text with characters for you. For example, /// when you select text and type (, Zed will automatically surround text with (). /// /// Default: true pub use_auto_surround: Option<bool>, /// Controls how the editor handles the autoclosed characters. /// When set to `false`(default), skipping over and auto-removing of the closing characters /// happen only for auto-inserted characters. /// Otherwise(when `true`), the closing characters are always skipped over and auto-removed /// no matter how they were inserted. /// /// 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. /// /// Default: {} (or {"source.organizeImports": true} for Go). pub code_actions_on_format: Option<HashMap<String, bool>>, /// Whether to perform linked edits of associated ranges, if the language server supports it. /// For example, when editing opening <html> tag, the contents of the closing </html> tag will be edited as well. /// /// Default: true pub linked_edits: Option<bool>, /// Whether indentation of pasted content should be adjusted based on the context. /// /// Default: true pub auto_indent_on_paste: Option<bool>, /// Task configuration for this language. /// /// Default: {} pub tasks: Option<LanguageTaskConfig>, /// Whether to pop the completions menu while typing in an editor without /// explicitly requesting it. /// /// Default: true pub show_completions_on_input: Option<bool>, /// Whether to display inline and alongside documentation for items in the /// completions menu. /// /// Default: true pub show_completion_documentation: Option<bool>,} /// The behavior of `editor::Rewrap`.#[derive(Debug, PartialEq, Clone, Copy, Default, Serialize, Deserialize, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum RewrapBehavior { /// Only rewrap within comments. #[default] InComments, /// Only rewrap within the current selection(s). InSelections, /// Allow rewrapping anywhere. Anywhere,} /// The contents of the edit prediction settings.#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq)]pub struct EditPredictionSettingsContent { /// 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.Lines 1–500 of 1670. Load more
//! Provides `language`-related settings. use crate::{File, Language, LanguageName, LanguageServerName}; use anyhow::Result; use collections::{HashMap, HashSet}; use core::slice; use ec4rs::{ property::{FinalNewline, IndentSize, IndentStyle, TabWidth, TrimTrailingWs}, Properties as EditorconfigProperties, }; use globset::{Glob, GlobMatcher, GlobSet, GlobSetBuilder}; use gpui::{App, Modifiers}; use itertools::{Either, Itertools}; use schemars::{ schema::{InstanceType, ObjectValidation, Schema, SchemaObject, SingleOrVec}, JsonSchema, }; use serde::{ de::{self, IntoDeserializer, MapAccess, SeqAccess, Visitor}, Deserialize, Deserializer, Serialize, }; use serde_json::Value; use settings::{ add_references_to_properties, Settings, SettingsLocation, SettingsSources, SettingsStore, }; use std::{borrow::Cow, num::NonZeroU32, path::Path, sync::Arc}; use util::serde::default_true; /// Initializes the language settings. pub fn init(cx: &mut App) { AllLanguageSettings::register(cx); } /// Returns the settings for the specified language from the provided file. pub fn language_settings<'a>( language: Option<LanguageName>, file: Option<&'a Arc<dyn File>>, cx: &'a App, ) -> Cow<'a, LanguageSettings> { let location = file.map(|f| SettingsLocation { worktree_id: f.worktree_id(cx), path: f.path().as_ref(), }); AllLanguageSettings::get(location, cx).language(location, language.as_ref(), cx) } /// Returns the settings for all languages from the provided file. pub fn all_language_settings<'a>( file: Option<&'a Arc<dyn File>>, cx: &'a App, ) -> &'a AllLanguageSettings { let location = file.map(|f| SettingsLocation { worktree_id: f.worktree_id(cx), path: f.path().as_ref(), }); AllLanguageSettings::get(location, cx) } /// The settings for all languages. #[derive(Debug, Clone)] pub struct AllLanguageSettings { /// The edit prediction settings. pub edit_predictions: EditPredictionSettings, defaults: LanguageSettings, languages: HashMap<LanguageName, LanguageSettings>, pub(crate) file_types: HashMap<Arc<str>, GlobSet>, } /// The settings for a particular language. #[derive(Debug, Clone, Deserialize)] pub struct LanguageSettings { /// How many columns a tab should occupy. pub tab_size: NonZeroU32, /// Whether to indent lines using tab characters, as opposed to multiple /// spaces. pub hard_tabs: bool, /// How to soft-wrap long lines of text. pub soft_wrap: SoftWrap, /// The column at which to soft-wrap lines, for buffers where soft-wrap /// is enabled. pub preferred_line_length: u32, // Whether to show wrap guides (vertical rulers) 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. pub show_wrap_guides: bool, /// Character counts at which to show wrap guides (vertical rulers) in the editor. pub wrap_guides: Vec<usize>, /// Indent guide related settings. pub indent_guides: IndentGuideSettings, /// Whether or not to perform a buffer format before saving. pub format_on_save: FormatOnSave, /// Whether or not to remove any trailing whitespace from lines of a buffer /// before saving it. pub remove_trailing_whitespace_on_save: bool, /// Whether or not to ensure there's a single newline at the end of a buffer /// when saving it. pub ensure_final_newline_on_save: bool, /// How to perform a buffer format. pub formatter: SelectedFormatter, /// Zed's Prettier integration settings. pub prettier: PrettierSettings, /// Whether to automatically close JSX tags. pub jsx_tag_auto_close: JsxTagAutoCloseSettings, /// Whether to use language servers to provide code intelligence. pub enable_language_server: bool, /// The list of language servers to use (or disable) for this language. /// /// This array should consist of language server IDs, as well as the following /// special tokens: /// - `"!<language_server_id>"` - A language server ID prefixed with a `!` will be disabled. /// - `"..."` - A placeholder to refer to the **rest** of the registered language servers for this language. pub language_servers: Vec<String>, /// Controls where the `editor::Rewrap` action is allowed for this language. /// /// Note: This setting has no effect in Vim mode, as rewrap is already /// allowed everywhere. pub allow_rewrap: RewrapBehavior, /// Controls whether edit predictions are shown immediately (true) /// or manually by triggering `editor::ShowEditPrediction` (false). pub show_edit_predictions: bool, /// Controls whether edit predictions are shown in the given language /// scopes. pub edit_predictions_disabled_in: Vec<String>, /// Whether to show tabs and spaces in the editor. pub show_whitespaces: ShowWhitespaceSetting, /// 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: InlayHintSettings, /// Whether to automatically close brackets. 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, /// Whether indentation of pasted content should be adjusted based on the context. pub auto_indent_on_paste: bool, // Controls how the editor handles the autoclosed characters. pub always_treat_brackets_as_autoclosed: bool, /// Which code actions to run on save pub code_actions_on_format: HashMap<String, bool>, /// Whether to perform linked edits pub linked_edits: bool, /// Task configuration for this language. pub tasks: LanguageTaskConfig, /// Whether to pop the completions menu while typing in an editor without /// explicitly requesting it. pub show_completions_on_input: bool, /// Whether to display inline and alongside documentation for items in the /// completions menu. pub show_completion_documentation: bool, } impl LanguageSettings { /// A token representing the rest of the available language servers. const REST_OF_LANGUAGE_SERVERS: &'static str = "..."; /// Returns the customized list of language servers from the list of /// available language servers. pub fn customized_language_servers( &self, available_language_servers: &[LanguageServerName], ) -> Vec<LanguageServerName> { Self::resolve_language_servers(&self.language_servers, available_language_servers) } pub(crate) fn resolve_language_servers( configured_language_servers: &[String], available_language_servers: &[LanguageServerName], ) -> Vec<LanguageServerName> { let (disabled_language_servers, enabled_language_servers): ( Vec<LanguageServerName>, Vec<LanguageServerName>, ) = configured_language_servers.iter().partition_map( |language_server| match language_server.strip_prefix('!') { Some(disabled) => Either::Left(LanguageServerName(disabled.to_string().into())), None => Either::Right(LanguageServerName(language_server.clone().into())), }, ); let rest = available_language_servers .iter() .filter(|&available_language_server| { !disabled_language_servers.contains(&available_language_server) && !enabled_language_servers.contains(&available_language_server) }) .cloned() .collect::<Vec<_>>(); enabled_language_servers .into_iter() .flat_map(|language_server| { if language_server.0.as_ref() == Self::REST_OF_LANGUAGE_SERVERS { rest.clone() } else { vec![language_server.clone()] } }) .collect::<Vec<_>>() } } /// The provider that supplies edit predictions. #[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum EditPredictionProvider { None, #[default] Copilot, Supermaven, Zed, } impl EditPredictionProvider { pub fn is_zed(&self) -> bool { match self { EditPredictionProvider::Zed => true, EditPredictionProvider::None | EditPredictionProvider::Copilot | EditPredictionProvider::Supermaven => false, } } } /// The settings for edit predictions, such as [GitHub Copilot](https://github.com/features/copilot) /// or [Supermaven](https://supermaven.com). #[derive(Clone, Debug, Default)] pub struct EditPredictionSettings { /// The provider that supplies edit predictions. pub provider: 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: Vec<DisabledGlob>, /// Configures how edit predictions are displayed in the buffer. pub mode: EditPredictionsMode, /// Settings specific to GitHub Copilot. pub copilot: CopilotSettings, /// Whether edit predictions are enabled in the assistant panel. /// This setting has no effect if globally disabled. pub enabled_in_assistant: bool, } impl EditPredictionSettings { /// Returns whether edit predictions are enabled for the given path. pub fn enabled_for_file(&self, file: &Arc<dyn File>, cx: &App) -> bool { !self.disabled_globs.iter().any(|glob| { if glob.is_absolute { file.as_local() .map_or(false, |local| glob.matcher.is_match(local.abs_path(cx))) } else { glob.matcher.is_match(file.path()) } }) } } #[derive(Clone, Debug)] pub struct DisabledGlob { matcher: GlobMatcher, is_absolute: bool, } /// The mode in which edit predictions should be displayed. #[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] #[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, } #[derive(Clone, Debug, Default)] pub struct CopilotSettings { /// HTTP/HTTPS proxy to use for Copilot. pub proxy: Option<String>, /// Disable certificate verification for proxy (not recommended). pub proxy_no_verify: Option<bool>, } /// The settings for all languages. #[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct AllLanguageSettingsContent { /// The settings for enabling/disabling features. #[serde(default)] pub features: Option<FeaturesContent>, /// The edit prediction settings. #[serde(default)] pub edit_predictions: Option<EditPredictionSettingsContent>, /// The default language settings. #[serde(flatten)] pub defaults: LanguageSettingsContent, /// The settings for individual languages. #[serde(default)] pub languages: HashMap<LanguageName, LanguageSettingsContent>, /// Settings for associating file extensions and filenames /// with languages. #[serde(default)] pub file_types: HashMap<Arc<str>, Vec<String>>, } /// The settings for a particular language. #[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct LanguageSettingsContent { /// How many columns a tab should occupy. /// /// Default: 4 #[serde(default)] pub tab_size: Option<NonZeroU32>, /// Whether to indent lines using tab characters, as opposed to multiple /// spaces. /// /// Default: false #[serde(default)] pub hard_tabs: Option<bool>, /// How to soft-wrap long lines of text. /// /// Default: none #[serde(default)] pub soft_wrap: Option<SoftWrap>, /// The column at which to soft-wrap lines, for buffers where soft-wrap /// is enabled. /// /// Default: 80 #[serde(default)] 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 #[serde(default)] pub show_wrap_guides: Option<bool>, /// Character counts at which to show wrap guides in the editor. /// /// Default: [] #[serde(default)] pub wrap_guides: Option<Vec<usize>>, /// Indent guide related settings. #[serde(default)] pub indent_guides: Option<IndentGuideSettings>, /// Whether or not to perform a buffer format before saving. /// /// Default: on #[serde(default)] pub format_on_save: Option<FormatOnSave>, /// Whether or not to remove any trailing whitespace from lines of a buffer /// before saving it. /// /// Default: true #[serde(default)] 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. /// /// Default: true #[serde(default)] pub ensure_final_newline_on_save: Option<bool>, /// How to perform a buffer format. /// /// Default: auto #[serde(default)] pub formatter: Option<SelectedFormatter>, /// Zed's Prettier integration settings. /// Allows to enable/disable formatting with Prettier /// and configure default Prettier, used when no project-level Prettier installation is found. /// /// Default: off #[serde(default)] pub prettier: Option<PrettierSettings>, /// Whether to automatically close JSX tags. #[serde(default)] pub jsx_tag_auto_close: Option<JsxTagAutoCloseSettings>, /// Whether to use language servers to provide code intelligence. /// /// Default: true #[serde(default)] pub enable_language_server: Option<bool>, /// The list of language servers to use (or disable) for this language. /// /// This array should consist of language server IDs, as well as the following /// special tokens: /// - `"!<language_server_id>"` - A language server ID prefixed with a `!` will be disabled. /// - `"..."` - A placeholder to refer to the **rest** of the registered language servers for this language. /// /// Default: ["..."] #[serde(default)] pub language_servers: Option<Vec<String>>, /// Controls where the `editor::Rewrap` action is allowed for this language. /// /// Note: This setting has no effect in Vim mode, as rewrap is already /// allowed everywhere. /// /// Default: "in_comments" #[serde(default)] pub allow_rewrap: Option<RewrapBehavior>, /// Controls whether edit predictions are shown immediately (true) /// or manually by triggering `editor::ShowEditPrediction` (false). /// /// Default: true #[serde(default)] pub show_edit_predictions: Option<bool>, /// Controls whether edit predictions are shown in the given language /// scopes. /// /// Example: ["string", "comment"] /// /// Default: [] #[serde(default)] pub edit_predictions_disabled_in: Option<Vec<String>>, /// Whether to show tabs and spaces in the editor. #[serde(default)] pub show_whitespaces: Option<ShowWhitespaceSetting>, /// Whether to start a new line with a comment when a previous line is a comment as well. /// /// Default: true #[serde(default)] pub extend_comment_on_newline: Option<bool>, /// Inlay hint related settings. #[serde(default)] pub inlay_hints: Option<InlayHintSettings>, /// Whether to automatically type closing characters for you. For example, /// when you type (, Zed will automatically add a closing ) at the correct position. /// /// Default: true pub use_autoclose: Option<bool>, /// Whether to automatically surround text with characters for you. For example, /// when you select text and type (, Zed will automatically surround text with (). /// /// Default: true pub use_auto_surround: Option<bool>, /// Controls how the editor handles the autoclosed characters. /// When set to `false`(default), skipping over and auto-removing of the closing characters /// happen only for auto-inserted characters. /// Otherwise(when `true`), the closing characters are always skipped over and auto-removed /// no matter how they were inserted. /// /// 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. /// /// Default: {} (or {"source.organizeImports": true} for Go). pub code_actions_on_format: Option<HashMap<String, bool>>, /// Whether to perform linked edits of associated ranges, if the language server supports it. /// For example, when editing opening <html> tag, the contents of the closing </html> tag will be edited as well. /// /// Default: true pub linked_edits: Option<bool>, /// Whether indentation of pasted content should be adjusted based on the context. /// /// Default: true pub auto_indent_on_paste: Option<bool>, /// Task configuration for this language. /// /// Default: {} pub tasks: Option<LanguageTaskConfig>, /// Whether to pop the completions menu while typing in an editor without /// explicitly requesting it. /// /// Default: true pub show_completions_on_input: Option<bool>, /// Whether to display inline and alongside documentation for items in the /// completions menu. /// /// Default: true pub show_completion_documentation: Option<bool>, } /// The behavior of `editor::Rewrap`. #[derive(Debug, PartialEq, Clone, Copy, Default, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum RewrapBehavior { /// Only rewrap within comments. #[default] InComments, /// Only rewrap within the current selection(s). InSelections, /// Allow rewrapping anywhere. Anywhere, } /// The contents of the edit prediction settings. #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq)] pub struct EditPredictionSettingsContent { /// 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.