mod entries;
mod linter;
#[cfg(test)]
mod tests;
use serde::Deserialize;
use super::model::{
ConfigExperimentalVueFlags, ConfigFeatureFlags, ConfigLintRuleOptions,
LanguageServerUnstableFlags, LibConfig, RawVizeConfig, VizeConfig, VueVersion,
};
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(transparent)]
pub struct ConfigDocument(
RawVizeConfig,
#[serde(skip)] Vec<crate::String>,
#[serde(skip)] Option<serde_json::Value>,
);
impl ConfigDocument {
pub fn evaluated_policy(&self) -> Option<&serde_json::Value> {
self.2.as_ref()
}
pub fn set_evaluated_policy(&mut self, value: serde_json::Value) {
self.2 = Some(value);
}
pub fn project_defaults() -> Self {
Self(RawVizeConfig::project_defaults(), Vec::new(), None)
}
pub fn config_dependencies(&self) -> &[crate::String] {
&self.1
}
pub fn set_config_dependencies(
&mut self,
dependencies: impl IntoIterator<Item = impl Into<crate::String>>,
) {
self.1 = dependencies.into_iter().map(Into::into).collect();
}
pub fn project_root(&self) -> Option<&str> {
self.0.project_root.as_deref()
}
pub fn clear_project_root(&mut self) {
self.0.project_root = None;
}
pub fn formatter_sort_imports(&self) -> Option<&crate::config::SortImportsSetting> {
self.0.formatter.sort_imports.as_ref()
}
pub fn into_config_and_features(self) -> (VizeConfig, ConfigFeatureFlags) {
self.0.into_config_and_features()
}
pub fn compiler_template_syntax(&self) -> Option<&'static str> {
self.0
.compiler
.template_syntax
.map(|template_syntax| template_syntax.as_str())
}
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,
}
}
pub fn compiler_compatibility_vue_version(&self) -> Option<VueVersion> {
self.0.compiler.compatibility.vue_version
}
pub fn legacy_compatibility_vue_version(&self) -> Option<VueVersion> {
self.0.compatibility.vue_version
}
pub fn compiler_host_compiler(&self) -> Option<bool> {
self.0.compiler.compatibility.host_compiler
}
pub fn compiler_vapor(&self) -> Option<bool> {
self.0
.compiler
.vapor
.or_else(|| self.0.experimentals.vapor_enabled().then_some(true))
}
pub fn into_compiler_custom_elements(self) -> Vec<crate::String> {
self.0.compiler.custom_elements
}
pub fn experimental_vue_flags(&self) -> ConfigExperimentalVueFlags {
self.0.experimental_vue_flags()
}
pub fn lsp_request_timeout_ms(&self) -> u64 {
self.0.lsp_request_timeout_ms()
}
pub fn language_server_unstable_flags(&self) -> LanguageServerUnstableFlags {
self.0.language_server_unstable_flags()
}
pub fn lint_rule_options(&self) -> &ConfigLintRuleOptions {
self.0.linter.rule_options()
}
pub fn into_lib_config(self) -> LibConfig {
self.0.lib
}
}