1208 lines · 39.8 KB · Rust
RawDownload
use std::{num::NonZeroU32, path::Path}; use collections::{HashMap, HashSet};use schemars::JsonSchema;use serde::{Deserialize, Serialize, de::Error as _};use settings_macros::{MergeFrom, with_fallible_options};use std::sync::Arc; use crate::{DocumentFoldingRanges, DocumentSymbols, ExtendingVec, 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<HashMap<Arc<str>, ExtendingVec<String>>>,} 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() {            language_settings.merge_from(&other.defaults);        }         // 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.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, JsonSchema, MergeFrom)]#[serde(rename_all = "snake_case")]pub enum EditPredictionProvider {    None,    #[default]    Copilot,    Zed,    Codestral,    Ollama,    OpenAiCompatibleApi,    Mercury,    Experimental(&'static str),} const EXPERIMENTAL_ZETA2_EDIT_PREDICTION_PROVIDER_NAME: &str = "zeta2"; impl<'de> Deserialize<'de> for EditPredictionProvider {    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>    where        D: serde::Deserializer<'de>,    {        #[derive(Deserialize)]        #[serde(rename_all = "snake_case")]        pub enum Content {            None,            Copilot,            Zed,            Codestral,            Ollama,            OpenAiCompatibleApi,            Mercury,            Experimental(String),        }         Ok(match Content::deserialize(deserializer)? {            Content::None => EditPredictionProvider::None,            Content::Copilot => EditPredictionProvider::Copilot,            Content::Zed => EditPredictionProvider::Zed,            Content::Codestral => EditPredictionProvider::Codestral,            Content::Ollama => EditPredictionProvider::Ollama,            Content::OpenAiCompatibleApi => EditPredictionProvider::OpenAiCompatibleApi,            Content::Mercury => EditPredictionProvider::Mercury,            Content::Experimental(name)                if name == EXPERIMENTAL_ZETA2_EDIT_PREDICTION_PROVIDER_NAME =>            {                EditPredictionProvider::Zed            }            Content::Experimental(name) => {                return Err(D::Error::custom(format!(                    "Unknown experimental edit prediction provider: {}",                    name                )));            }        })    }} 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            | EditPredictionProvider::Experimental(_) => 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::Experimental(_) | 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>,    /// The directory where manually captured edit prediction examples are stored.    pub examples_dir: Option<Arc<Path>>,} #[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<EditPredictionPromptFormat>,    /// 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 EditPredictionPromptFormat {    #[default]    Infer,    Zeta,    Zeta2,    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<EditPredictionPromptFormat>,} /// 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 lines at the preferred line length.    PreferredLineLength,    /// Soft wrap line at the preferred line length or the editor width (whichever is smaller).    Bounded,} /// 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.    ///    /// Default: true    pub ensure_final_newline_on_save: Option<bool>,    /// How to perform a buffer format.    ///    /// Default: auto    pub formatter: Option<FormatterList>,    /// 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    pub prettier: Option<PrettierSettingsContent>,    /// Whether to automatically close JSX tags.    pub jsx_tag_auto_close: Option<JsxTagAutoCloseSettingsContent>,    /// Whether to use language servers to provide code intelligence.    ///    /// Default: true    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: ["..."]    pub language_servers: Option<Vec<String>>,    /// Controls how semantic tokens from language servers are used for syntax highlighting.    ///    /// Options:    /// - "off": Do not request semantic tokens from language servers.    /// - "combined": Use LSP semantic tokens together with tree-sitter highlighting.    /// - "full": Use LSP semantic tokens exclusively, replacing tree-sitter highlighting.    ///    /// Default: "off"    pub semantic_tokens: Option<SemanticTokens>,    /// Controls whether folding ranges from language servers are used instead of    /// tree-sitter and indent-based folding.    ///    /// Options:    /// - "off": Use tree-sitter and indent-based folding (default).    /// - "on": Use LSP folding wherever possible, falling back to tree-sitter and indent-based folding when no results were returned by the server.    ///    /// Default: "off"    pub document_folding_ranges: Option<DocumentFoldingRanges>,    /// Controls the source of document symbols used for outlines and breadcrumbs.    ///    /// Options:    /// - "off": Use tree-sitter queries to compute document symbols (default).    /// - "on": Use the language server's `textDocument/documentSymbol` LSP response. When enabled, tree-sitter is not used for document symbols.

Lines 1–500 of 1208.