Give a warning when using per-project default units (#5956)

* Give a warning when using per-project default units

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Factor non-settings out of MetaSettings

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Fix formatting

* Fix code pane e2e test

* Fix callstack blowup in edit flow

* Avoid dumb timeout issue with command registration in test

* Use a safer way to wait for modeling command registration in test

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Pierre Jacquier <pierre@zoo.dev>
Co-authored-by: Frank Noirot <frankjohnson1993@gmail.com>
This commit is contained in:
Jonathan Tran
2025-03-26 01:59:43 -04:00
committed by GitHub
parent 736533a482
commit c53fa421ad
17 changed files with 104 additions and 52 deletions

View File

@ -992,7 +992,11 @@ mod tests {
use pretty_assertions::assert_eq;
use super::*;
use crate::{errors::KclErrorDetails, execution::memory::Stack, ModuleId};
use crate::{
errors::{KclErrorDetails, Severity},
execution::memory::Stack,
ModuleId,
};
/// Convenience function to get a JSON value from memory and unwrap.
#[track_caller]
@ -1595,6 +1599,34 @@ const inInches = 2.0 * inch()"#;
);
}
#[tokio::test(flavor = "multi_thread")]
async fn test_unit_suggest() {
let src = "foo = 42";
let program = crate::Program::parse_no_errs(src).unwrap();
let ctx = ExecutorContext {
engine: Arc::new(Box::new(
crate::engine::conn_mock::EngineConnection::new().await.unwrap(),
)),
fs: Arc::new(crate::fs::FileManager::new()),
stdlib: Arc::new(crate::std::StdLib::new()),
settings: ExecutorSettings {
units: UnitLength::Ft,
..Default::default()
},
context_type: ContextType::Mock,
};
let mut exec_state = ExecState::new(&ctx);
ctx.run(&program, &mut exec_state).await.unwrap();
let errs = exec_state.errors();
assert_eq!(errs.len(), 1, "{errs:?}");
let warn = &errs[0];
assert_eq!(warn.severity, Severity::Warning);
assert_eq!(
warn.apply_suggestion(src).unwrap(),
"@settings(defaultLengthUnit = ft)\nfoo = 42"
)
}
#[tokio::test(flavor = "multi_thread")]
async fn test_zero_param_fn() {
let ast = r#"const sigmaAllow = 35000 // psi