vize_l0 0.535.0

L0 - the Davinci foundation level: ids, side tables, keys, dumps, diagnostics, passes and facts
Documentation
//! An in-memory configuration document, independent of host discovery or evaluation.

mod entries;
mod linter;
#[cfg(test)]
mod tests;

use serde::Deserialize;

use super::model::{
    ConfigExperimentalVueFlags, ConfigFeatureFlags, ConfigLintRuleOptions,
    LanguageServerUnstableFlags, LibConfig, RawVizeConfig, VizeConfig, VueVersion,
};

/// One deserialized configuration value and its pure projections.
///
/// The raw representation stays private. Hosts supply JSON bytes after reading
/// or evaluating their input; projections preserve the existing alias and
/// declaration-order rules without another parse or serialization roundtrip.
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(transparent)]
pub struct ConfigDocument(
    RawVizeConfig,
    #[serde(skip)] Vec<crate::String>,
    #[serde(skip)] Option<serde_json::Value>,
);

impl ConfigDocument {
    /// Complete evaluated canonical payload, solely for editor authority identity.
    /// Native deserialization without an evaluated payload keeps this absent.
    pub fn evaluated_policy(&self) -> Option<&serde_json::Value> {
        self.2.as_ref()
    }

    /// Retain the payload already validated by the host, without another parse.
    pub fn set_evaluated_policy(&mut self, value: serde_json::Value) {
        self.2 = Some(value);
    }

    /// Defaults for projects without dedicated Vize configuration.
    ///
    /// Keep `Default` unchanged for existing dedicated configuration files.
    pub fn project_defaults() -> Self {
        Self(RawVizeConfig::project_defaults(), Vec::new(), None)
    }

    /// Files read by the host while evaluating this snapshot.
    ///
    /// Host metadata is never accepted from authored configuration values.
    pub fn config_dependencies(&self) -> &[crate::String] {
        &self.1
    }

    /// Retain host-observed dependencies without changing configuration semantics.
    pub fn set_config_dependencies(
        &mut self,
        dependencies: impl IntoIterator<Item = impl Into<crate::String>>,
    ) {
        self.1 = dependencies.into_iter().map(Into::into).collect();
    }

    /// Project identity supplied by the Vite host projection.
    pub fn project_root(&self) -> Option<&str> {
        self.0.project_root.as_deref()
    }

    /// Discard host identity when reading a dedicated native config file.
    ///
    /// This reserved key was formerly an ignored extension field; native files
    /// cannot change their established path contract by authoring its value.
    pub fn clear_project_root(&mut self) {
        self.0.project_root = None;
    }

    /// Borrow configured import sorting without changing the stable formatter model.
    pub fn formatter_sort_imports(&self) -> Option<&crate::config::SortImportsSetting> {
        self.0.formatter.sort_imports.as_ref()
    }

    /// Authored formatter options with the preset applied, including options
    /// outside the stable formatter model.
    pub fn formatter_profile(&self) -> &crate::config::FormatterProfile {
        self.0.formatter_profile()
    }

    /// Normalize the effective model and its feature flags once.
    pub fn into_config_and_features(self) -> (VizeConfig, ConfigFeatureFlags) {
        self.0.into_config_and_features()
    }

    /// Stable compiler template syntax when explicitly supplied.
    pub fn compiler_template_syntax(&self) -> Option<&'static str> {
        self.0
            .compiler
            .template_syntax
            .map(|template_syntax| template_syntax.as_str())
    }

    /// Documented template whitespace mode, without changing the effective model.
    pub fn compiler_whitespace(&self) -> Option<&'static str> {
        match self.0.compiler.whitespace.as_deref() {
            Some("preserve") => Some("preserve"),
            Some("condense") => Some("condense"),
            Some("vue2-line-breaks") => Some("vue2-line-breaks"),
            Some("vue2-preserve") => Some("vue2-preserve"),
            _ => None,
        }
    }

    /// Stable compiler compatibility dialect, before legacy fallback.
    pub fn compiler_compatibility_vue_version(&self) -> Option<VueVersion> {
        self.0.compiler.compatibility.vue_version
    }

    /// Legacy top-level compatibility dialect.
    pub fn legacy_compatibility_vue_version(&self) -> Option<VueVersion> {
        self.0.compatibility.vue_version
    }

    /// Stable host compiler selection when explicitly supplied.
    pub fn compiler_host_compiler(&self) -> Option<bool> {
        self.0.compiler.compatibility.host_compiler
    }

    /// Stable Vapor selection takes precedence over the experimental alias.
    pub fn compiler_vapor(&self) -> Option<bool> {
        self.0
            .compiler
            .vapor
            .or_else(|| self.0.experimentals.vapor_enabled().then_some(true))
    }

    /// Stable SSR selection when explicitly supplied.
    pub fn compiler_ssr(&self) -> Option<bool> {
        self.0.compiler.ssr
    }

    /// Consume the declared custom-element patterns without cloning them.
    pub fn into_compiler_custom_elements(self) -> Vec<crate::String> {
        self.0.compiler.custom_elements
    }

    /// Experimental Vue switches not represented by stable model fields.
    pub fn experimental_vue_flags(&self) -> ConfigExperimentalVueFlags {
        self.0.experimental_vue_flags()
    }

    /// Editor timeout after the existing default and minimum are applied.
    pub fn lsp_request_timeout_ms(&self) -> u64 {
        self.0.lsp_request_timeout_ms()
    }

    /// Editor switches after the existing stable/legacy precedence is applied.
    pub fn language_server_unstable_flags(&self) -> LanguageServerUnstableFlags {
        self.0.language_server_unstable_flags()
    }

    /// Borrow typed rule options from this same deserialization.
    pub fn lint_rule_options(&self) -> &ConfigLintRuleOptions {
        self.0.linter.rule_options()
    }

    /// Consume the library section without cloning it.
    pub fn into_lib_config(self) -> LibConfig {
        self.0.lib
    }
}