Skip to content

Commit fe6ed81

Browse files
committed
[IMP] remove refresh_mode setting
Refresh_mode setting is creating caches errors if Off or OnSave option are selected. Off is not really useful, nor OnSave, so we will only use adaptive for everyone starting from now. Next commit will fix these cache invalidation issue in adaptive mode. That fix is not doable in Off or OnSave mode, adding argument to the deletion of these options
1 parent 4449f9e commit fe6ed81

File tree

6 files changed

+24
-121
lines changed

6 files changed

+24
-121
lines changed

server/src/cli_backend.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ impl CliBackend {
5555
let mut config = ConfigEntry::new();
5656
config.addons_paths = addons_paths.into_iter().map(|p| fs::canonicalize(p).unwrap_or_else(|_| PathBuf::from(S!(""))).sanitize()).collect();
5757
config.odoo_path = Some(fs::canonicalize(community_path.unwrap_or(S!(""))).unwrap_or_else(|_| PathBuf::from(S!(""))).sanitize());
58-
config.refresh_mode = crate::core::config::RefreshMode::Off;
5958
config.diag_missing_imports = DiagMissingImportsMode::All;
6059
config.no_typeshed_stubs = self.cli.no_typeshed_stubs;
6160
config.additional_stubs = self.cli.stubs.clone().unwrap_or(vec![]).into_iter().map(|p| fs::canonicalize(p).unwrap_or_else(|_| PathBuf::from(S!(""))).sanitize()).collect();

server/src/core/config.rs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,6 @@ static VERSION_REGEX: std::sync::LazyLock<Regex> = std::sync::LazyLock::new(|| {
2222
Regex::new(r#"^(\D+~)?\d+\.\d+$"#).unwrap()
2323
});
2424

25-
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone, JsonSchema)]
26-
#[serde(rename_all = "snake_case")]
27-
pub enum RefreshMode {
28-
OnSave,
29-
Adaptive,
30-
Off
31-
}
32-
impl Default for RefreshMode {
33-
fn default() -> Self {
34-
RefreshMode::Adaptive
35-
}
36-
}
37-
38-
impl FromStr for RefreshMode {
39-
40-
type Err = ();
41-
42-
fn from_str(input: &str) -> Result<RefreshMode, Self::Err> {
43-
match input {
44-
"afterDelay" => Ok(RefreshMode::Adaptive),
45-
"onSave" => Ok(RefreshMode::OnSave),
46-
"adaptive" => Ok(RefreshMode::Adaptive),
47-
"off" => Ok(RefreshMode::Off),
48-
_ => Err(()),
49-
}
50-
}
51-
}
52-
5325
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize, Clone, JsonSchema)]
5426
#[serde(rename_all = "snake_case")]
5527
pub enum DiagMissingImportsMode {
@@ -620,10 +592,6 @@ pub struct ConfigEntryRaw {
620592
#[schemars(with = "Option<MergeMethod>")]
621593
additional_stubs_merge: Option<Sourced<MergeMethod>>,
622594

623-
#[serde(default, serialize_with = "serialize_option_as_default")]
624-
#[schemars(with = "Option<RefreshMode>")]
625-
refresh_mode: Option<Sourced<RefreshMode>>,
626-
627595
#[serde(default, serialize_with = "serialize_file_cache")]
628596
#[schemars(with = "Option<bool>")]
629597
file_cache: Option<Sourced<bool>>,
@@ -708,7 +676,6 @@ impl Default for ConfigEntryRaw {
708676
python_path: None,
709677
additional_stubs: None,
710678
additional_stubs_merge: None,
711-
refresh_mode: None,
712679
file_cache: None,
713680
diag_missing_imports: None,
714681
ac_filter_model_names: None,
@@ -754,7 +721,6 @@ pub struct ConfigEntry {
754721
pub addons_paths: HashSet<String>,
755722
pub python_path: String,
756723
pub additional_stubs: HashSet<String>,
757-
pub refresh_mode: RefreshMode,
758724
pub file_cache: bool,
759725
pub diag_missing_imports: DiagMissingImportsMode,
760726
pub ac_filter_model_names: bool,
@@ -774,7 +740,6 @@ impl Default for ConfigEntry {
774740
addons_paths: HashSet::new(),
775741
python_path: S!(get_python_command().unwrap_or_default()),
776742
additional_stubs: HashSet::new(),
777-
refresh_mode: RefreshMode::default(),
778743
file_cache: true,
779744
diag_missing_imports: DiagMissingImportsMode::default(),
780745
ac_filter_model_names: true,
@@ -915,7 +880,6 @@ fn read_config_from_file<P: AsRef<Path>>(path: P) -> Result<HashMap<String, Conf
915880
// Add initial source to all fields
916881
entry.addons_merge.as_mut().map(|sourced| sourced.sources.insert(path.sanitize()));
917882
entry.additional_stubs_merge.as_mut().map(|sourced| sourced.sources.insert(path.sanitize()));
918-
entry.refresh_mode.as_mut().map(|sourced| sourced.sources.insert(path.sanitize()));
919883
entry.file_cache.as_mut().map(|sourced| sourced.sources.insert(path.sanitize()));
920884
entry.diag_missing_imports.as_mut().map(|sourced| sourced.sources.insert(path.sanitize()));
921885
entry.ac_filter_model_names.as_mut().map(|sourced| sourced.sources.insert(path.sanitize()));
@@ -992,7 +956,6 @@ fn apply_merge(child: &ConfigEntryRaw, parent: &ConfigEntryRaw) -> ConfigEntryRa
992956
},
993957
MergeMethod::Override => child.additional_stubs.clone(),
994958
};
995-
let refresh_mode = child.refresh_mode.clone().or(parent.refresh_mode.clone());
996959
let file_cache = child.file_cache.clone().or(parent.file_cache.clone());
997960
let diag_missing_imports = child.diag_missing_imports.clone().or(parent.diag_missing_imports.clone());
998961
let ac_filter_model_names = child.ac_filter_model_names.clone().or(parent.ac_filter_model_names.clone());
@@ -1013,7 +976,6 @@ fn apply_merge(child: &ConfigEntryRaw, parent: &ConfigEntryRaw) -> ConfigEntryRa
1013976
python_path,
1014977
addons_paths,
1015978
additional_stubs,
1016-
refresh_mode,
1017979
file_cache,
1018980
diag_missing_imports,
1019981
ac_filter_model_names,
@@ -1314,12 +1276,6 @@ fn merge_all_workspaces(
13141276
(Some(paths), None) | (None, Some(paths)) => Some(paths),
13151277
(None, None) => None,
13161278
};
1317-
merged_entry.refresh_mode = merge_sourced_options(
1318-
merged_entry.refresh_mode.clone(),
1319-
raw_entry.refresh_mode.clone(),
1320-
key.clone(),
1321-
"refresh_mode".to_string(),
1322-
)?;
13231279
merged_entry.file_cache = merge_sourced_options(
13241280
merged_entry.file_cache.clone(),
13251281
raw_entry.file_cache.clone(),
@@ -1393,7 +1349,6 @@ fn merge_all_workspaces(
13931349
addons_paths: raw_entry.addons_paths.into_iter().flatten().map(|op| op.value).collect(),
13941350
python_path: raw_entry.python_path.map(|op| op.value).unwrap_or(S!(get_python_command().unwrap_or_default())),
13951351
additional_stubs: raw_entry.additional_stubs.into_iter().flatten().map(|op| op.value).collect(),
1396-
refresh_mode: raw_entry.refresh_mode.map(|op| op.value).unwrap_or_default(),
13971352
file_cache: raw_entry.file_cache.map(|op| op.value).unwrap_or(true),
13981353
diag_missing_imports: raw_entry.diag_missing_imports.map(|op| op.value).unwrap_or_default(),
13991354
ac_filter_model_names: raw_entry.ac_filter_model_names.map(|op| op.value).unwrap_or(true),

server/src/core/odoo.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::path::{Path, PathBuf};
3030
use std::env;
3131
use regex::Regex;
3232
use crate::{constants::*, oyarn, Sy};
33-
use super::config::{self, default_profile_name, get_configuration, ConfigEntry, ConfigFile, RefreshMode};
33+
use super::config::{self, default_profile_name, get_configuration, ConfigEntry, ConfigFile};
3434
use super::entry_point::{EntryPoint, EntryPointMgr};
3535
use super::file_mgr::FileMgr;
3636
use super::import_resolver::ImportCache;
@@ -1372,7 +1372,7 @@ impl Odoo {
13721372
}
13731373

13741374
fn handle_file_update(session: &mut SessionInfo, file_uris: &Vec<Uri>) {
1375-
if session.sync_odoo.config.refresh_mode == RefreshMode::Off || session.sync_odoo.state_init == InitState::NOT_READY {
1375+
if session.sync_odoo.state_init == InitState::NOT_READY {
13761376
return
13771377
}
13781378
for uri in file_uris.iter() {
@@ -1383,7 +1383,7 @@ impl Odoo {
13831383
session.log_message(MessageType::INFO, format!("File update: {}", path.sanitize()));
13841384
let (valid, updated) = Odoo::update_file_cache(session, path.clone(), None, -100);
13851385
if valid && updated {
1386-
Odoo::update_file_index(session, path, true, false, true);
1386+
Odoo::update_file_index(session, path, false, true);
13871387
}
13881388
}
13891389
}
@@ -1399,7 +1399,7 @@ impl Odoo {
13991399
text: params.text_document.text}]), params.text_document.version);
14001400
if valid {
14011401
session.sync_odoo.opened_files.push(path.sanitize());
1402-
if session.sync_odoo.config.refresh_mode == RefreshMode::Off || session.sync_odoo.state_init == InitState::NOT_READY {
1402+
if session.sync_odoo.state_init == InitState::NOT_READY {
14031403
return
14041404
}
14051405
let tree = session.sync_odoo.path_to_main_entry_tree(&path);
@@ -1413,15 +1413,15 @@ impl Odoo {
14131413
for custom_entry in ep_mgr.borrow().custom_entry_points.iter() {
14141414
if custom_entry.borrow().path == tree_path.sanitize() {
14151415
if updated{
1416-
Odoo::update_file_index(session, path,true, true, false);
1416+
Odoo::update_file_index(session, path, true, false);
14171417
}
14181418
return;
14191419
}
14201420
}
14211421
EntryPointMgr::create_new_custom_entry_for_path(session, &tree_path.sanitize(), &path.sanitize());
14221422
SyncOdoo::process_rebuilds(session);
14231423
} else if updated {
1424-
Odoo::update_file_index(session, path,true, true, false);
1424+
Odoo::update_file_index(session, path, true, false);
14251425
}
14261426
}
14271427
}
@@ -1487,7 +1487,7 @@ impl Odoo {
14871487
}
14881488

14891489
pub fn handle_did_rename(session: &mut SessionInfo, params: RenameFilesParams) {
1490-
if session.sync_odoo.config.refresh_mode == RefreshMode::Off || session.sync_odoo.state_init == InitState::NOT_READY {
1490+
if session.sync_odoo.state_init == InitState::NOT_READY {
14911491
return
14921492
}
14931493
for f in params.files.iter() {
@@ -1518,7 +1518,7 @@ impl Odoo {
15181518
}
15191519

15201520
pub fn handle_did_create(session: &mut SessionInfo, params: CreateFilesParams) {
1521-
if session.sync_odoo.config.refresh_mode == RefreshMode::Off || session.sync_odoo.state_init == InitState::NOT_READY {
1521+
if session.sync_odoo.state_init == InitState::NOT_READY {
15221522
return
15231523
}
15241524
for f in params.files.iter() {
@@ -1543,7 +1543,7 @@ impl Odoo {
15431543
}
15441544

15451545
pub fn handle_did_delete(session: &mut SessionInfo, params: DeleteFilesParams) {
1546-
if session.sync_odoo.config.refresh_mode == RefreshMode::Off || session.sync_odoo.state_init == InitState::NOT_READY {
1546+
if session.sync_odoo.state_init == InitState::NOT_READY {
15471547
return
15481548
}
15491549
for f in params.files.iter() {
@@ -1563,10 +1563,10 @@ impl Odoo {
15631563
let version = params.text_document.version;
15641564
let (valid, updated) = Odoo::update_file_cache(session, path.clone(), Some(&params.content_changes), version);
15651565
if valid && updated {
1566-
if (matches!(session.sync_odoo.config.refresh_mode, RefreshMode::Off | RefreshMode::OnSave)) || session.sync_odoo.state_init == InitState::NOT_READY {
1566+
if session.sync_odoo.state_init == InitState::NOT_READY {
15671567
return
15681568
}
1569-
Odoo::update_file_index(session, path, false, false, false);
1569+
Odoo::update_file_index(session, path, false, false);
15701570
}
15711571
}
15721572
}
@@ -1577,10 +1577,9 @@ impl Odoo {
15771577
return; //config file update, handled by the config file handler
15781578
}
15791579
session.log_message(MessageType::INFO, format!("File saved: {}", path.sanitize()));
1580-
if session.sync_odoo.config.refresh_mode != RefreshMode::OnSave || session.sync_odoo.state_init == InitState::NOT_READY {
1581-
return
1582-
}
1583-
Odoo::update_file_index(session, path,true, false, false);
1580+
return;
1581+
//No need to update the index on save, as the file change event will do it
1582+
//Odoo::update_file_index(session, path,true, false, false);
15841583
}
15851584

15861585
// return (valid, updated) booleans
@@ -1595,9 +1594,9 @@ impl Odoo {
15951594
(false, false)
15961595
}
15971596

1598-
pub fn update_file_index(session: &mut SessionInfo, path: PathBuf, is_save: bool, _is_open: bool, force_delay: bool) {
1597+
pub fn update_file_index(session: &mut SessionInfo, path: PathBuf, _is_open: bool, force_delay: bool) {
15991598
if matches!(path.extension().and_then(OsStr::to_str), Some(ext) if ["py", "xml", "csv"].contains(&ext)) || Odoo::is_config_workspace_file(session, &path){
1600-
SessionInfo::request_update_file_index(session, &path, is_save, force_delay);
1599+
SessionInfo::request_update_file_index(session, &path, force_delay);
16011600
}
16021601
}
16031602

server/src/threads.rs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use serde::{de::DeserializeOwned, Serialize};
99
use serde_json::Value;
1010
use tracing::{error, info, warn};
1111

12-
use crate::{core::{config::RefreshMode, file_mgr::NoqaInfo, odoo::{Odoo, SyncOdoo}}, server::ServerError, utils::PathSanitizer, S};
12+
use crate::{core::{file_mgr::NoqaInfo, odoo::{Odoo, SyncOdoo}}, server::ServerError, utils::PathSanitizer, S};
1313

1414
pub struct SessionInfo<'a> {
1515
sender: Sender<Message>,
@@ -93,36 +93,21 @@ impl <'a> SessionInfo<'a> {
9393
/*
9494
* Request an update of the file in the index.
9595
* path: path of the file
96-
* process_now: indicate if the current action is due to a save action
9796
* forced_delay: indicate that we want to force a delay
9897
*/
99-
pub fn request_update_file_index(session: &mut SessionInfo, path: &PathBuf, is_save: bool, forced_delay: bool) {
98+
pub fn request_update_file_index(session: &mut SessionInfo, path: &PathBuf, forced_delay: bool) {
10099
if (!forced_delay || session.delayed_process_sender.is_none()) && !session.sync_odoo.need_rebuild {
101-
if session.sync_odoo.config.refresh_mode == RefreshMode::OnSave {
102-
if is_save {
103-
let _ = SyncOdoo::_unload_path(session, &path, false);
104-
Odoo::search_symbols_to_rebuild(session, &path.sanitize());
105-
SyncOdoo::process_rebuilds(session);
106-
}
107-
return;
108-
}
109-
if session.sync_odoo.config.refresh_mode == RefreshMode::Adaptive &&
110-
session.sync_odoo.get_rebuild_queue_size() < 10 {
100+
if session.sync_odoo.get_rebuild_queue_size() < 10 {
111101
let _ = SyncOdoo::_unload_path(session, &path, false);
112102
Odoo::search_symbols_to_rebuild(session, &path.sanitize());
113103
SyncOdoo::process_rebuilds(session);
114-
} else {
115-
if forced_delay {
116-
session.sync_odoo.watched_file_updates.store(session.sync_odoo.watched_file_updates.load(Ordering::SeqCst) + 1, Ordering::SeqCst);
117-
}
118-
let _ = session.delayed_process_sender.as_ref().unwrap().send(DelayedProcessingMessage::UPDATE_FILE_INDEX(UpdateFileIndexData { path: path.clone(), time: std::time::Instant::now(), forced_delay}));
119-
}
120-
} else {
121-
if forced_delay {
122-
session.sync_odoo.watched_file_updates.store(session.sync_odoo.watched_file_updates.load(Ordering::SeqCst) + 1, Ordering::SeqCst);
104+
return;
123105
}
124-
let _ = session.delayed_process_sender.as_ref().unwrap().send(DelayedProcessingMessage::UPDATE_FILE_INDEX(UpdateFileIndexData { path: path.clone(), time: std::time::Instant::now(), forced_delay}));
106+
}
107+
if forced_delay {
108+
session.sync_odoo.watched_file_updates.store(session.sync_odoo.watched_file_updates.load(Ordering::SeqCst) + 1, Ordering::SeqCst);
125109
}
110+
let _ = session.delayed_process_sender.as_ref().unwrap().send(DelayedProcessingMessage::UPDATE_FILE_INDEX(UpdateFileIndexData { path: path.clone(), time: std::time::Instant::now(), forced_delay}));
126111
}
127112

128113
pub fn request_reload(session: &mut SessionInfo) {

server/tests/config_tests.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -561,40 +561,6 @@ fn test_no_conflict_when_config_files_point_to_same_odoo_path() {
561561
assert_eq!(config.odoo_path.as_ref().unwrap(), &ws1.path().sanitize());
562562
}
563563

564-
#[test]
565-
fn test_conflict_between_config_files_on_refresh_mode() {
566-
let temp = TempDir::new().unwrap();
567-
let ws1 = temp.child("ws1");
568-
let ws2 = temp.child("ws2");
569-
ws1.create_dir_all().unwrap();
570-
ws2.create_dir_all().unwrap();
571-
572-
// ws1 config: refresh_mode = "onSave"
573-
let ws1_toml = r#"
574-
[[config]]
575-
name = "default"
576-
refresh_mode = "on_save"
577-
"#;
578-
ws1.child("odools.toml").write_str(ws1_toml).unwrap();
579-
580-
// ws2 config: refresh_mode = "adaptive"
581-
let ws2_toml = r#"
582-
[[config]]
583-
name = "default"
584-
refresh_mode = "adaptive"
585-
"#;
586-
ws2.child("odools.toml").write_str(ws2_toml).unwrap();
587-
588-
let mut ws_folders = HashMap::new();
589-
ws_folders.insert(S!("ws1"), ws1.path().sanitize().to_string());
590-
ws_folders.insert(S!("ws2"), ws2.path().sanitize().to_string());
591-
592-
// Should error due to conflicting refresh_mode values
593-
let result = get_configuration(&ws_folders, &None);
594-
assert!(result.is_err());
595-
assert!(result.err().unwrap().contains("Conflict detected"));
596-
}
597-
598564
#[test]
599565
fn test_merge_different_odoo_paths_and_addons_paths() {
600566
let temp = TempDir::new().unwrap();

server/tests/setup/setup.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ pub fn setup_server(with_odoo: bool) -> SyncOdoo {
5151
panic!("Python not found")
5252
};
5353
config.python_path = python_cmd;
54-
config.refresh_mode = odoo_ls_server::core::config::RefreshMode::Off;
5554
config.diag_missing_imports = DiagMissingImportsMode::All;
5655

5756
let (s, r) = crossbeam_channel::unbounded();

0 commit comments

Comments
 (0)