Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions server/src/core/odoo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use crate::core::xml_validation::XmlValidator;
use crate::features::document_symbols::DocumentSymbolFeature;
use crate::features::references::ReferenceFeature;
use crate::features::workspace_symbols::WorkspaceSymbolFeature;
use crate::fifo_ptr_weak_hash_set::FifoPtrWeakHashSet;
use crate::threads::SessionInfo;
use crate::features::completion::CompletionFeature;
use crate::features::definition::DefinitionFeature;
use crate::features::hover::HoverFeature;
use std::collections::HashMap;
use std::cell::RefCell;
use std::ffi::OsStr;
use std::rc::{Rc, Weak};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
Expand All @@ -27,7 +27,6 @@ use serde_json::Value;
use tracing::{error, warn, info, trace};

use std::collections::HashSet;
use weak_table::PtrWeakHashSet;
use std::process::Command;
use std::fs;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -86,9 +85,9 @@ pub struct SyncOdoo {
pub current_request_id: Option<RequestId>,
pub running_request_ids: Arc<Mutex<Vec<RequestId>>>, //Arc to Server mutex for cancellation support
pub watched_file_updates: u32,
rebuild_arch: PtrWeakHashSet<Weak<RefCell<Symbol>>>,
rebuild_arch_eval: PtrWeakHashSet<Weak<RefCell<Symbol>>>,
rebuild_validation: PtrWeakHashSet<Weak<RefCell<Symbol>>>,
rebuild_arch: FifoPtrWeakHashSet<RefCell<Symbol>>,
rebuild_arch_eval: FifoPtrWeakHashSet<RefCell<Symbol>>,
rebuild_validation: FifoPtrWeakHashSet<RefCell<Symbol>>,
pub state_init: InitState,
pub must_reload_paths: Vec<(Weak<RefCell<Symbol>>, String)>,
pub load_odoo_addons: bool, //indicate if we want to load odoo addons or not
Expand Down Expand Up @@ -131,9 +130,9 @@ impl SyncOdoo {
current_request_id: None,
running_request_ids: Arc::new(Mutex::new(vec![])),
watched_file_updates: 0,
rebuild_arch: PtrWeakHashSet::new(),
rebuild_arch_eval: PtrWeakHashSet::new(),
rebuild_validation: PtrWeakHashSet::new(),
rebuild_arch: FifoPtrWeakHashSet::new(),
rebuild_arch_eval: FifoPtrWeakHashSet::new(),
rebuild_validation: FifoPtrWeakHashSet::new(),
state_init: InitState::NOT_READY,
must_reload_paths: vec![],
load_odoo_addons: true,
Expand Down Expand Up @@ -161,9 +160,9 @@ impl SyncOdoo {
session.sync_odoo.stdlib_dir = SyncOdoo::default_stdlib();
session.sync_odoo.modules = HashMap::new();
session.sync_odoo.models = HashMap::new();
session.sync_odoo.rebuild_arch = PtrWeakHashSet::new();
session.sync_odoo.rebuild_arch_eval = PtrWeakHashSet::new();
session.sync_odoo.rebuild_validation = PtrWeakHashSet::new();
session.sync_odoo.rebuild_arch = FifoPtrWeakHashSet::new();
session.sync_odoo.rebuild_arch_eval = FifoPtrWeakHashSet::new();
session.sync_odoo.rebuild_validation = FifoPtrWeakHashSet::new();
session.sync_odoo.state_init = InitState::NOT_READY;
session.sync_odoo.load_odoo_addons = true;
session.sync_odoo.need_rebuild = false;
Expand Down Expand Up @@ -537,7 +536,7 @@ impl SyncOdoo {
let mut selected_sym: Option<Rc<RefCell<Symbol>>> = None;
let mut selected_count: u32 = 999999999;
let mut current_count: u32;
for sym in set {
for sym in set.iter() {
current_count = 0;
let file = sym.borrow().get_file().unwrap().upgrade().unwrap();
let file = file.borrow();
Expand Down
57 changes: 57 additions & 0 deletions server/src/fifo_ptr_weak_hash_set.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use std::{collections::VecDeque, hash::RandomState, rc::{Rc, Weak}};
use weak_table::{PtrWeakHashSet};

#[derive(Debug)]
pub struct FifoPtrWeakHashSet<T> {
set: PtrWeakHashSet<Weak<T>, RandomState>,
queue: VecDeque<Weak<T>>,
}

impl<T> FifoPtrWeakHashSet<T>
{
pub fn new() -> Self {
Self {
set: PtrWeakHashSet::new(),
queue: VecDeque::new(),
}
}

pub fn insert(&mut self, v: Rc<T>) {
if !self.set.insert(v.clone()) { //it returns true if absent (wrong doc)
self.queue.push_back(Rc::downgrade(&v));
}
}

pub fn iter(&self) -> impl Iterator<Item = Rc<T>> {
self.queue.iter().filter_map(|weak| weak.upgrade())
}

pub fn contains(&self, v: &Rc<T>) -> bool {
self.set.contains(v)
}

pub fn clear(&mut self) {
self.set.clear();
self.queue.clear();
}

pub fn remove(&mut self, v: &Rc<T>) -> bool {
if self.set.remove(v) {
let weak = Rc::downgrade(v);
let pos = self.queue.iter().position(|x| Weak::ptr_eq(x, &weak));
if let Some(pos) = pos {
self.queue.remove(pos);
}
return true
}
false
}

pub fn is_empty(&self) -> bool {
self.set.is_empty()
}

pub fn len(&self) -> usize {
self.set.len()
}
}
1 change: 1 addition & 0 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod constants;
pub mod core;
pub mod threads;
pub mod features;
pub mod fifo_ptr_weak_hash_set;
pub mod server;
pub mod tasks;
pub mod utils;
Expand Down