Fix project config diagnostics after an unknown setting (#63377)

## Why

When a project config contains an unknown key before an invalid setting,
deserializing the effective config directly can mask the type error users
need to fix.

## What changed

Reuse the TOML validation deserializer when diagnosing effective config
layers, with ignored-field path collection disabled.

## Testing

Extend the project config diagnostic test with an unknown key and verify
that the error still points to the invalid `tui.vim_mode_default` in the
current file after filtering out `tui.status_line_provider`.

GitOrigin-RevId: b124d0819ac34b2341f18fad7b6651ef0fe48379
This commit is contained in:
Charlie Marsh
2026-11-23 16:53:58 +00:00
committed by copyberry
parent 113e0c6d5e
commit 1589e80b28
3 changed files with 26 additions and 4 deletions
+11 -1
View File
@@ -8,6 +8,7 @@ use crate::ConfigLayerStack;
use crate::config_toml::ConfigToml;
use crate::format_config_layer_source;
use crate::shell_environment_policy::ShellEnvironmentPolicyFilterConfigToml;
use crate::strict_config::validate_toml_value;
use codex_utils_absolute_path::AbsolutePathBufGuard;
use serde_path_to_error::Path as SerdePath;
use serde_path_to_error::Segment as SerdeSegment;
@@ -179,7 +180,16 @@ fn config_error_from_typed_toml_for_source(
&& let Ok(raw) = toml::from_str(contents)
&& let std::borrow::Cow::Owned(effective) = layer.effective_values(&raw)
{
err = schema.deserialize_error(effective)?;
err = match schema {
DiagnosticSchema::Config => {
validate_toml_value::<ConfigToml>(effective, /*ignored_paths*/ None).err()
}
DiagnosticSchema::ShellEnvironmentFilters => serde_path_to_error::deserialize::<
_,
ShellEnvironmentPolicyFilterConfigToml,
>(effective)
.err(),
}?;
}
let path_hint = err.path().clone();
let toml_err: toml::de::Error = err.into_inner();
+2 -2
View File
@@ -576,12 +576,12 @@ async fn project_diagnostic_uses_the_current_file_and_ignores_its_provider() ->
);
std::fs::write(
&path,
"[tui]\nstatus_line_provider = 42\nvim_mode_default = 43\n",
"ignored_setting = true\n[tui]\nstatus_line_provider = 42\nvim_mode_default = 43\n",
)?;
let error = first_layer_config_error_from_entries(&[layer])
.await
.expect("invalid vim setting");
assert_eq!((error.path, error.range.start.line), (path, 3));
assert_eq!((error.path, error.range.start.line), (path, 4));
assert!(error.message.contains("43"), "{}", error.message);
Ok(())
}
+13 -1
View File
@@ -124,7 +124,19 @@ pub(crate) fn ignored_toml_value_fields<T: DeserializeOwned>(
value: TomlValue,
) -> Result<Vec<Vec<String>>, serde_path_to_error::Error<toml::de::Error>> {
let mut ignored_paths = Vec::new();
validate_toml_value::<T>(value, Some(&mut ignored_paths))?;
Ok(ignored_paths)
}
/// Keep the same deserializer type whether or not the caller needs ignored field paths.
pub(crate) fn validate_toml_value<T: DeserializeOwned>(
value: TomlValue,
mut ignored_paths: Option<&mut Vec<Vec<String>>>,
) -> Result<(), serde_path_to_error::Error<toml::de::Error>> {
let mut record_path = |path: serde_ignored::Path<'_>| {
let Some(ignored_paths) = &mut ignored_paths else {
return;
};
let segments = ignored_path_segments(&path);
if !segments.is_empty() {
ignored_paths.push(segments);
@@ -132,7 +144,7 @@ pub(crate) fn ignored_toml_value_fields<T: DeserializeOwned>(
};
let deserializer = serde_ignored::Deserializer::new(value, &mut record_path);
serde_path_to_error::deserialize::<_, T>(deserializer)?;
Ok(ignored_paths)
Ok(())
}
pub(crate) fn unknown_feature_toml_value_field(value: &TomlValue) -> Option<String> {