Skip to content
Open
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
156 changes: 81 additions & 75 deletions server/src/core/evaluation.rs

Large diffs are not rendered by default.

191 changes: 109 additions & 82 deletions server/src/core/import_resolver.rs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion server/src/core/odoo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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 Down
102 changes: 52 additions & 50 deletions server/src/core/python_arch_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,69 +180,71 @@ impl PythonArchBuilder {
}
let mut all_name_allowed = true;
let mut name_filter: Vec<OYarn> = vec![];
if let Some(all) = import_result.symbol.borrow().get_content_symbol("__all__", u32::MAX).symbols.first().cloned() {
let all_value = Symbol::follow_ref(&EvaluationSymbolPtr::WEAK(EvaluationSymbolWeak::new(
Rc::downgrade(&all), None, false
)), session, &mut None, false, true, None);
if let Some(all_value_first) = all_value.get(0) {
if !all_value_first.is_expired_if_weak() {
let all_upgraded = all_value_first.upgrade_weak();
if let Some(all_upgraded_unwrapped) = all_upgraded {
let all_upgraded_unwrapped_bw = (*all_upgraded_unwrapped).borrow();
if all_upgraded_unwrapped_bw.evaluations().is_some() && all_upgraded_unwrapped_bw.evaluations().unwrap().len() == 1 {
let value = &all_upgraded_unwrapped_bw.evaluations().unwrap()[0].value;
if value.is_some() {
let (nf, parse_error) = self.extract_all_symbol_eval_values(&value.as_ref());
if parse_error {
warn!("error during parsing __all__ import in file {}", (*import_result.symbol).borrow().paths()[0] )
for import_symbol in import_result.symbols{
if let Some(all) = import_symbol.borrow().get_content_symbol("__all__", u32::MAX).symbols.first().cloned() {
let all_value = Symbol::follow_ref(&EvaluationSymbolPtr::WEAK(EvaluationSymbolWeak::new(
Rc::downgrade(&all), None, false
)), session, &mut None, false, true, None, None);
if let Some(all_value_first) = all_value.get(0) {
if !all_value_first.is_expired_if_weak() {
let all_upgraded = all_value_first.upgrade_weak();
if let Some(all_upgraded_unwrapped) = all_upgraded {
let all_upgraded_unwrapped_bw = (*all_upgraded_unwrapped).borrow();
if all_upgraded_unwrapped_bw.evaluations().is_some() && all_upgraded_unwrapped_bw.evaluations().unwrap().len() == 1 {
let value = &all_upgraded_unwrapped_bw.evaluations().unwrap()[0].value;
if value.is_some() {
let (nf, parse_error) = self.extract_all_symbol_eval_values(&value.as_ref());
if parse_error {
warn!("error during parsing __all__ import in file {}", import_symbol.borrow().paths()[0] )
}
name_filter = nf;
all_name_allowed = false;
} else {
warn!("invalid __all__ import in file {} - no value found", import_symbol.borrow().paths()[0])
}
name_filter = nf;
all_name_allowed = false;
} else {
warn!("invalid __all__ import in file {} - no value found", (*import_result.symbol).borrow().paths()[0])
warn!("invalid __all__ import in file {} - multiple evaluation found", import_symbol.borrow().paths()[0])
}
} else {
warn!("invalid __all__ import in file {} - multiple evaluation found", (*import_result.symbol).borrow().paths()[0])
warn!("invalid __all__ import in file {} - localizedSymbol not found", import_symbol.borrow().paths()[0])
}
} else {
warn!("invalid __all__ import in file {} - localizedSymbol not found", (*import_result.symbol).borrow().paths()[0])
warn!("invalid __all__ import in file {} - expired symbol", import_symbol.borrow().paths()[0])
}
} else {
warn!("invalid __all__ import in file {} - expired symbol", (*import_result.symbol).borrow().paths()[0])
warn!("invalid __all__ import in file {} - no symbol found", import_symbol.borrow().paths()[0])
}
} else {
warn!("invalid __all__ import in file {} - no symbol found", (*import_result.symbol).borrow().paths()[0])
}
}
let mut dep_to_add = vec![];
let sym_type = import_result.symbol.borrow().typ();
if sym_type != SymType::COMPILED {
if !Rc::ptr_eq(self.sym_stack.last().unwrap(), &import_result.symbol) { /*We have to check that the imported symbol is not the current one. It can
happen for example in a .pyi that is importing the .pyd file with the same name. As both exists, odools will try to import the pyi a second time in the same file,
and so create a borrow error here
*/
let symbol = import_result.symbol.borrow();
for (name, loc_syms) in symbol.iter_symbols() {
if all_name_allowed || name_filter.contains(&name) {
let variable = self.sym_stack.last().unwrap().borrow_mut().add_new_variable(session, OYarn::from(name.clone()), &import_result.range);
let mut loc = variable.borrow_mut();
loc.as_variable_mut().is_import_variable = true;
loc.as_variable_mut().evaluations = Evaluation::from_sections(&symbol, loc_syms);
dep_to_add.push(variable.clone());
let mut dep_to_add = vec![];
let sym_type = import_symbol.borrow().typ();
if sym_type != SymType::COMPILED {
if !Rc::ptr_eq(self.sym_stack.last().unwrap(), &import_symbol) { /*We have to check that the imported symbol is not the current one. It can
happen for example in a .pyi that is importing the .pyd file with the same name. As both exists, odools will try to import the pyi a second time in the same file,
and so create a borrow error here
*/
let symbol = import_symbol.borrow();
for (name, loc_syms) in symbol.iter_symbols() {
if all_name_allowed || name_filter.contains(&name) {
let variable = self.sym_stack.last().unwrap().borrow_mut().add_new_variable(session, OYarn::from(name.clone()), &import_result.range);
let mut loc = variable.borrow_mut();
loc.as_variable_mut().is_import_variable = true;
loc.as_variable_mut().evaluations = Evaluation::from_sections(&symbol, loc_syms);
dep_to_add.push(variable.clone());
}
}
}
}
}
for sym in dep_to_add {
let mut sym_bw = sym.borrow_mut();
let evaluation = &sym_bw.as_variable_mut().evaluations[0];
let evaluated_type = &evaluation.symbol;
let evaluated_type = evaluated_type.get_symbol_as_weak(session, &mut None, &mut self.diagnostics, None).weak;
if !evaluated_type.is_expired() {
let evaluated_type = evaluated_type.upgrade().unwrap();
let evaluated_type_file = evaluated_type.borrow().get_file().unwrap().clone().upgrade().unwrap();
if !Rc::ptr_eq(&self.file, &evaluated_type_file) {
self.file.borrow_mut().add_dependency(&mut evaluated_type_file.borrow_mut(), self.current_step, BuildSteps::ARCH);
for sym in dep_to_add {
let mut sym_bw = sym.borrow_mut();
let evaluation = &sym_bw.as_variable_mut().evaluations[0];
let evaluated_type = &evaluation.symbol;
let evaluated_type = evaluated_type.get_symbol_as_weak(session, &mut None, &mut self.diagnostics, None).weak;
if !evaluated_type.is_expired() {
let evaluated_type = evaluated_type.upgrade().unwrap();
let evaluated_type_file = evaluated_type.borrow().get_file().unwrap().clone().upgrade().unwrap();
if !Rc::ptr_eq(&self.file, &evaluated_type_file) {
self.file.borrow_mut().add_dependency(&mut evaluated_type_file.borrow_mut(), self.current_step, BuildSteps::ARCH);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/core/python_arch_builder_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static arch_class_hooks: Lazy<Vec<PythonArchClassHook>> = Lazy::new(|| {vec![
],
func: |session: &mut SessionInfo, _entry_point: &Rc<RefCell<EntryPoint>>, symbol: Rc<RefCell<Symbol>>| {
let range = symbol.borrow().range().clone();
// ----------- env.cr ------------
// ----------- global ------------
symbol.borrow_mut().add_new_variable(session, Sy!("global"), &range);
}
},
Expand Down Expand Up @@ -240,4 +240,4 @@ impl PythonArchBuilderHooks {
}
}
}
}
}
Loading