config: reexport table and value types

These types will be replaced with toml_edit::Table and ::Value respectively.
This commit is contained in:
Yuya Nishihara 2024-11-29 23:34:23 +09:00
parent 824cd132cc
commit ba07c3bc54
3 changed files with 12 additions and 5 deletions

View file

@ -25,6 +25,7 @@ use jj_lib::backend::BackendError;
use jj_lib::backend::CommitId;
use jj_lib::backend::FileId;
use jj_lib::backend::TreeValue;
use jj_lib::config::ConfigValue;
use jj_lib::fileset;
use jj_lib::fileset::FilesetDiagnostics;
use jj_lib::fileset::FilesetExpression;
@ -470,7 +471,7 @@ fn get_tools_config(ui: &mut Ui, settings: &UserSettings) -> Result<ToolsConfig,
command = {}
patterns = ["all()"]
"###,
to_toml_value(&settings.get::<config::Value>("fix.tool-command").unwrap()).unwrap()
to_toml_value(&settings.get::<ConfigValue>("fix.tool-command").unwrap()).unwrap()
)?;
}
if let Ok(tools_table) = settings.raw_config().get_table("fix.tools") {

View file

@ -26,6 +26,7 @@ use jj_lib::config::ConfigError;
use jj_lib::config::ConfigLayer;
use jj_lib::config::ConfigNamePathBuf;
use jj_lib::config::ConfigSource;
use jj_lib::config::ConfigValue;
use jj_lib::config::StackedConfig;
use jj_lib::settings::ConfigResultExt as _;
use regex::Captures;
@ -51,7 +52,7 @@ pub fn parse_toml_value_or_bare_string(value_str: &str) -> toml_edit::Value {
}
}
pub fn to_toml_value(value: &config::Value) -> Result<toml_edit::Value, ConfigError> {
pub fn to_toml_value(value: &ConfigValue) -> Result<toml_edit::Value, ConfigError> {
fn type_error<T: fmt::Display>(message: T) -> ConfigError {
ConfigError::Message(message.to_string())
}
@ -93,7 +94,7 @@ pub struct AnnotatedValue {
/// Dotted name path to the configuration variable.
pub name: ConfigNamePathBuf,
/// Configuration value.
pub value: config::Value,
pub value: ConfigValue,
/// Source of the configuration value.
pub source: ConfigSource,
// TODO: add source file path

View file

@ -27,6 +27,11 @@ use itertools::Itertools as _;
use crate::file_util::IoResultExt as _;
/// Table of config key and value pairs.
pub type ConfigTable = config::Map<String, config::Value>;
/// Generic config value.
pub type ConfigValue = config::Value;
/// Error that can occur when accessing configuration.
// TODO: will be replaced with our custom error type
pub type ConfigError = config::ConfigError;
@ -63,11 +68,11 @@ impl ConfigNamePathBuf {
/// This is a workaround for the `config.get()` API, which doesn't support
/// literal path expression. If we implement our own config abstraction,
/// this method should be moved there.
pub fn lookup_value(&self, config: &config::Config) -> Result<config::Value, ConfigError> {
pub fn lookup_value(&self, config: &config::Config) -> Result<ConfigValue, ConfigError> {
// Use config.get() if the TOML keys can be converted to config path
// syntax. This should be cheaper than cloning the whole config map.
let (key_prefix, components) = self.split_safe_prefix();
let value: config::Value = match &key_prefix {
let value: ConfigValue = match &key_prefix {
Some(key) => config.get(key)?,
None => config.collect()?.into(),
};