pub struct SourcedConfig<State = ConfigLoaded> {
pub global: SourcedGlobalConfig,
pub per_file_ignores: SourcedValue<BTreeMap<String, Vec<String>>>,
pub per_file_flavor: SourcedValue<IndexMap<String, MarkdownFlavor>>,
pub code_block_tools: SourcedValue<CodeBlockToolsConfig>,
pub rules: BTreeMap<String, SourcedRuleConfig>,
pub loaded_files: Vec<String>,
pub unknown_keys: Vec<(String, String, Option<String>)>,
pub project_root: Option<PathBuf>,
pub discovery_warnings: Vec<String>,
pub validation_warnings: Vec<ConfigValidationWarning>,
/* private fields */
}Expand description
Configuration with provenance tracking for values.
The State type parameter encodes the validation state:
ConfigLoaded: Config has been loaded but not validatedConfigValidated: Config has been validated and can be converted toConfig
§Typestate Pattern
This uses the typestate pattern to ensure validation happens before conversion:
let loaded: SourcedConfig<ConfigLoaded> = SourcedConfig::load_with_discovery(...)?;
let validated: SourcedConfig<ConfigValidated> = loaded.validate(®istry)?;
let config: Config = validated.into(); // Only works on ConfigValidated!Attempting to convert a ConfigLoaded config directly to Config is a compile error.
Fields§
§global: SourcedGlobalConfig§per_file_ignores: SourcedValue<BTreeMap<String, Vec<String>>>§per_file_flavor: SourcedValue<IndexMap<String, MarkdownFlavor>>§code_block_tools: SourcedValue<CodeBlockToolsConfig>§rules: BTreeMap<String, SourcedRuleConfig>§loaded_files: Vec<String>Every config file that contributed, by resolved path, in load order.
A file reached through extends appears here as the path its reference
expanded to, unlike every message about such a file (see ConfigOrigin).
This list is not a message: it exists to
answer which files took effect, which rumdl config is asked directly and
a language server answers for the editor that started it, and the resolved
path is the answer.
unknown_keys: Vec<(String, String, Option<String>)>(section, key, display_name), as on SourcedConfigFragment.
project_root: Option<PathBuf>Project root directory (parent of config file), used for resolving relative paths
discovery_warnings: Vec<String>Warnings produced while finding and reading config files: a rumdl.toml
shadowed by a sibling .rumdl.toml, or a setting a file could not
contribute (see SourcedConfigFragment::load_warnings). Shadowing is
reported by auto-discovery only, so an explicit --config path and
--no-config/--isolated see only the reading half.
validation_warnings: Vec<ConfigValidationWarning>Validation warnings (populated after validate() is called)
Implementations§
Source§impl SourcedConfig<ConfigLoaded>
impl SourcedConfig<ConfigLoaded>
Sourcepub fn load(
config_path: Option<&str>,
cli_overrides: Option<&SourcedGlobalConfig>,
) -> Result<Self, ConfigError>
pub fn load( config_path: Option<&str>, cli_overrides: Option<&SourcedGlobalConfig>, ) -> Result<Self, ConfigError>
Load and merge configurations from files and CLI overrides.
Sourcepub fn load_discovered(
config_file: &Path,
user_config_dir: Option<&Path>,
home_dir: Option<&Path>,
) -> Result<Self, DiscoveredConfigError>
pub fn load_discovered( config_file: &Path, user_config_dir: Option<&Path>, home_dir: Option<&Path>, ) -> Result<Self, DiscoveredConfigError>
Load a config file that the caller discovered by walking the tree itself.
The LSP cannot use load_with_discovery: that walk starts at the process
working directory, while the server resolves a config per document and stops
at the workspace root. It finds the file with its own walk and hands it here,
so the discovered-config rules in load_discovered_config still apply.
project_root comes from the config file’s own location, which is what
per-file ignore globs are matched against.
user_config_dir and home_dir override the platform user-config directory
and the home directory; the server passes the home directory it already
resolved for its walk boundary, and tests pass both.
The error distinguishes an unusable discovered file from an unusable user config so a caller walking several candidates can tell “try the next one” from “nothing here will resolve correctly”.
Sourcepub fn load_for_workspace(
start_dir: &Path,
config_path: Option<&str>,
user_config_dir: Option<&Path>,
home_dir: Option<&Path>,
) -> Result<Self, ConfigError>
pub fn load_for_workspace( start_dir: &Path, config_path: Option<&str>, user_config_dir: Option<&Path>, home_dir: Option<&Path>, ) -> Result<Self, ConfigError>
Load the configuration that applies to a directory, as if the CLI had run there.
Discovery normally walks up from the process working directory, which is the
scope the user chose when they typed rumdl check. A language server has no
such directory: the editor launches it from wherever it happens to be, which
may sit in an unrelated project. The workspace root is the scope the user
chose, so the server passes that here and resolves what rumdl check would
resolve inside it.
user_config_dir and home_dir override the platform user-config directory
and the home-directory walk boundary; the server passes the home directory it
already resolved for its per-file walk, and tests pass both.
Sourcepub fn load_with_discovery(
config_path: Option<&str>,
cli_overrides: Option<&SourcedGlobalConfig>,
skip_auto_discovery: bool,
) -> Result<Self, ConfigError>
pub fn load_with_discovery( config_path: Option<&str>, cli_overrides: Option<&SourcedGlobalConfig>, skip_auto_discovery: bool, ) -> Result<Self, ConfigError>
Load and merge configurations from files and CLI overrides. If skip_auto_discovery is true, only explicit config paths are loaded.
Sourcepub fn validate(
self,
registry: &RuleRegistry,
) -> Result<SourcedConfig<ConfigValidated>, ConfigError>
pub fn validate( self, registry: &RuleRegistry, ) -> Result<SourcedConfig<ConfigValidated>, ConfigError>
Validate the configuration against a rule registry.
This method transitions the config from ConfigLoaded to ConfigValidated state,
enabling conversion to Config. Validation warnings are stored in the config
and can be displayed to the user.
§Example
let loaded = SourcedConfig::load_with_discovery(path, None, false)?;
let validated = loaded.validate(®istry)?;
let config: Config = validated.into();Sourcepub fn validate_into(
self,
registry: &RuleRegistry,
) -> Result<(Config, Vec<ConfigValidationWarning>), ConfigError>
pub fn validate_into( self, registry: &RuleRegistry, ) -> Result<(Config, Vec<ConfigValidationWarning>), ConfigError>
Validate and convert to Config in one step (convenience method).
This combines validate() and into() for callers who want the
validation warnings separately.
Sourcepub fn into_validated_unchecked(self) -> SourcedConfig<ConfigValidated>
pub fn into_validated_unchecked(self) -> SourcedConfig<ConfigValidated>
Skip validation and convert directly to ConfigValidated state.
§Safety
This method bypasses validation. Use only when:
- You’ve already validated via
validate_config_sourced() - You’re in test code that doesn’t need validation
- You’re migrating legacy code and will add proper validation later
Prefer validate() for new code.
Sourcepub fn discover_config_for_dir(
dir: &Path,
project_root: &Path,
) -> Option<PathBuf>
pub fn discover_config_for_dir( dir: &Path, project_root: &Path, ) -> Option<PathBuf>
Discover the nearest config file for a specific directory,
walking upward to project_root (inclusive).
Searches for rumdl config files (.rumdl.toml, rumdl.toml,
.config/rumdl.toml, pyproject.toml with [tool.rumdl]) and
markdownlint config files at each directory level.
Returns the config file path if found. Does NOT use CWD.
Sourcepub fn load_sourced_for_path(
config_path: &Path,
project_root: &Path,
) -> Result<SourcedConfig<ConfigLoaded>, ConfigError>
pub fn load_sourced_for_path( config_path: &Path, project_root: &Path, ) -> Result<SourcedConfig<ConfigLoaded>, ConfigError>
Load a config from a specific file path, with extends resolution, returning
the still-Loaded SourcedConfig (before validation and conversion).
Used by per-directory resolution so the caller can layer CLI-level overrides
(e.g. inline --config) on top before converting to Config, matching the
precedence applied to the global config.
Sourcepub fn load_config_for_path(
config_path: &Path,
project_root: &Path,
) -> Result<Config, ConfigError>
pub fn load_config_for_path( config_path: &Path, project_root: &Path, ) -> Result<Config, ConfigError>
Load a config from a specific file path, with extends resolution, and convert
to Config. Used for per-directory config loading where each subdirectory
config is standalone.
Trait Implementations§
Source§impl<State: Clone> Clone for SourcedConfig<State>
impl<State: Clone> Clone for SourcedConfig<State>
Source§fn clone(&self) -> SourcedConfig<State>
fn clone(&self) -> SourcedConfig<State>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<State: Debug> Debug for SourcedConfig<State>
impl<State: Debug> Debug for SourcedConfig<State>
Source§impl Default for SourcedConfig<ConfigLoaded>
impl Default for SourcedConfig<ConfigLoaded>
Source§impl From<SourcedConfig<ConfigValidated>> for Config
Convert a validated configuration to the final Config type.
impl From<SourcedConfig<ConfigValidated>> for Config
Convert a validated configuration to the final Config type.
This implementation only exists for SourcedConfig<ConfigValidated>,
ensuring that validation must occur before conversion.