Skip to content

Commit 6a23ecf

Browse files
committed
[IMP] test diagnostics update on additional_languages config change
This commits factors out the config update handling logic from `Odoo::check_handle_config_file_update` into a dedicated `Odoo::handle_config_update`. This has two benefits: - better separation of concerns (one handles the config **file** update, while the other handles the replacement of the current config with a new ConfigEntry) - it allows for easier testing of config updates without needing to go through the file update logic Based on this, this commit introduces a test for checking whether the OLS05058 diagnostic (unknown language code) is refreshed correctly when the additional_languages config is updated.
1 parent 79a1ae5 commit 6a23ecf

2 files changed

Lines changed: 77 additions & 17 deletions

File tree

server/src/core/odoo.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,22 +2068,7 @@ impl Odoo {
20682068

20692069
match config_result {
20702070
Ok((new_config, cfg_file)) => {
2071-
if config::needs_restart(&session.sync_odoo.config, &new_config) {
2072-
// Changes require a restart, ask the client to restart the server
2073-
session.send_notification("$Odoo/restartNeeded", ());
2074-
} else {
2075-
// Changes can be applied without restart
2076-
let languages_changed = session.sync_odoo.config.additional_languages != new_config.additional_languages;
2077-
session.sync_odoo.config_file = Some(cfg_file);
2078-
session.sync_odoo.config = new_config;
2079-
// Recalculate diagnostic filters
2080-
session.sync_odoo.get_file_mgr().borrow_mut().update_all_file_diagnostic_filters(session);
2081-
session.update_delay_thread_delay_duration(session.sync_odoo.config.auto_refresh_delay);
2082-
if languages_changed {
2083-
session.sync_odoo.revalidate_language_dependents();
2084-
SyncOdoo::process_rebuilds(session, false);
2085-
}
2086-
}
2071+
Odoo::handle_config_update(session, new_config, cfg_file);
20872072
}
20882073
Err(err) => {
20892074
// Invalid config, send a notification to the user and add the error to the logs
@@ -2099,4 +2084,22 @@ impl Odoo {
20992084
}
21002085
}
21012086

2087+
pub fn handle_config_update(session: &mut SessionInfo, new_config: ConfigEntry, cfg_file: ConfigFile) {
2088+
if config::needs_restart(&session.sync_odoo.config, &new_config) {
2089+
// Changes require a restart, ask the client to restart the server
2090+
session.send_notification("$Odoo/restartNeeded", ());
2091+
return;
2092+
}
2093+
// Changes can be applied without restart
2094+
let languages_changed = session.sync_odoo.config.additional_languages != new_config.additional_languages;
2095+
session.sync_odoo.config_file = Some(cfg_file);
2096+
// Recalculate diagnostic filters
2097+
session.sync_odoo.config = new_config;
2098+
session.sync_odoo.get_file_mgr().borrow_mut().update_all_file_diagnostic_filters(session);
2099+
session.update_delay_thread_delay_duration(session.sync_odoo.config.auto_refresh_delay);
2100+
if languages_changed {
2101+
session.sync_odoo.revalidate_language_dependents();
2102+
SyncOdoo::process_rebuilds(session, false);
2103+
}
2104+
}
21022105
}

server/tests/test_language_updates.rs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use std::collections::HashSet;
1+
use std::collections::{HashMap, HashSet};
22
use std::path::PathBuf;
33

44
use lsp_types::{TextDocumentContentChangeEvent, VersionedTextDocumentIdentifier};
5+
use odoo_ls_server::core::config::ConfigFile;
56
use odoo_ls_server::core::file_mgr::FileMgr;
67
use odoo_ls_server::core::odoo::Odoo;
78
use odoo_ls_server::threads::SessionInfo;
@@ -231,3 +232,59 @@ fn test_additional_languages_config() {
231232
languages
232233
);
233234
}
235+
236+
/// Test that changing additional_languages via config update clears/restores OLS05058 diagnostics.
237+
#[test]
238+
fn test_config_additional_languages_updates_diagnostics() {
239+
let (mut odoo, config) = setup_server(true);
240+
let mut session = create_init_session(&mut odoo, config);
241+
242+
let items_xml_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
243+
.join("tests/data/addons/module_lang_test/data/lang_test_items.xml")
244+
.sanitize();
245+
246+
let file_mgr = session.sync_odoo.get_file_mgr();
247+
let file_info = file_mgr.borrow().get_file_info(&items_xml_path).unwrap();
248+
let force_republish_diagnostic = |session: &mut SessionInfo| {
249+
let mut file_info_borrow = file_info.borrow_mut();
250+
// This does not rebuild validation steps. It just sets need_push to true.
251+
file_info_borrow.update_validation_diagnostics(HashMap::new());
252+
file_info_borrow.publish_diagnostics(session);
253+
};
254+
255+
// Verify OLS05058 is present initially (nl_WV is unknown)
256+
let diagnostics = get_diagnostics_for_path(&mut session, &items_xml_path);
257+
assert!(
258+
has_diagnostic_code(&diagnostics, "OLS05058"),
259+
"Initial: OLS05058 should be present for nl_WV. Diagnostics: {:?}",
260+
diagnostics
261+
);
262+
263+
// Add nl_WV and nl to additional_languages via config update
264+
let mut new_config = session.sync_odoo.config.clone();
265+
new_config.additional_languages = HashSet::from(["nl_WV".to_string(), "nl".to_string()]);
266+
Odoo::handle_config_update(&mut session, new_config, ConfigFile::new());
267+
268+
// OLS05058 should be gone now
269+
// We need to force republish diagnostics to avoid a false negative, as the
270+
// previous check consumes the messages.
271+
force_republish_diagnostic(&mut session);
272+
let diagnostics = get_diagnostics_for_path(&mut session, &items_xml_path);
273+
assert!(
274+
!has_diagnostic_code(&diagnostics, "OLS05058"),
275+
"After adding nl_WV to additional_languages: OLS05058 should be CLEARED. Diagnostics: {:?}",
276+
diagnostics
277+
);
278+
279+
// Restore original config (without nl_WV) and verify diagnostic reappears
280+
let mut restored_config = session.sync_odoo.config.clone();
281+
restored_config.additional_languages = HashSet::new();
282+
Odoo::handle_config_update(&mut session, restored_config, ConfigFile::new());
283+
284+
let diagnostics = get_diagnostics_for_path(&mut session, &items_xml_path);
285+
assert!(
286+
has_diagnostic_code(&diagnostics, "OLS05058"),
287+
"After removing nl_WV from additional_languages: OLS05058 should REAPPEAR. Diagnostics: {:?}",
288+
diagnostics
289+
);
290+
}

0 commit comments

Comments
 (0)