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
2 changes: 1 addition & 1 deletion server/src/core/csv_arch_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl CsvArchBuilder {
pub fn load_csv(&mut self, session: &mut SessionInfo, csv_symbol: Rc<RefCell<Symbol>>, content: &String) -> Vec<Diagnostic> {
let diagnostics = vec![];
csv_symbol.borrow_mut().set_build_status(BuildSteps::ARCH, BuildStatus::IN_PROGRESS);
let model_name_pb = PathBuf::from(&csv_symbol.borrow().paths()[0]);
let model_name_pb = PathBuf::from(&csv_symbol.borrow().path().to_single_string());
let model_name = Sy!(model_name_pb.file_stem().unwrap().to_str().unwrap().to_string());
let csv_module = csv_symbol.borrow().find_module();
let Some(csv_module) = &csv_module else {
Expand Down
2 changes: 1 addition & 1 deletion server/src/core/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl EntryPointMgr {
} else {
// There was an __init__.py, that was renamed or deleted.
// Another notification will come for the deletion of the file, so we just warn here.
warn_or_panic!("Trying to create a custom entrypoint on a namespace symbol: {:?}", new_sym.borrow().paths());
warn_or_panic!("Trying to create a custom entrypoint on a namespace symbol: {:?}", new_sym.borrow().path().to_multiple_vec());
}
return false;
}
Expand Down
28 changes: 17 additions & 11 deletions server/src/core/import_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ fn resolve_import_stmt_hook(alias: &Alias, from_symbol: &Option<Rc<RefCell<Symbo
* Helper to manually import a symbol. Do not forget to use level instead of '.' in the from_stmt parameter.
*/
pub fn manual_import(session: &mut SessionInfo, source_file_symbol: &Rc<RefCell<Symbol>>, from_stmt:Option<String>, name: &str, asname: Option<String>, level: u32, diagnostics: &mut Option<&mut Vec<Diagnostic>>) -> Vec<ImportResult> {
if source_file_symbol.borrow().path().to_vec().len() > 1 {
panic!("Importing from a multi-path namespace symbol is not supported in manual_import");
}
let name_aliases = vec![Alias {
name: Identifier { id: Name::new(name), range: TextRange::new(TextSize::new(0), TextSize::new(0)), node_index: AtomicNodeIndex::default() },
asname: match asname {
Expand All @@ -82,7 +85,8 @@ pub fn resolve_from_stmt(session: &mut SessionInfo, source_file_symbol: &Rc<RefC
level,
from_stmt);
drop(_source_file_symbol_lock);
let source_path = source_file_symbol.borrow().paths()[0].clone();
// source_file_symbol is either a file or a namespace with a single path
let source_path = source_file_symbol.borrow().path().to_vec()[0].clone();
let mut start_symbol = None;
if level != 0 {
//if level is 0, resolve_packages already built a full tree, so we can start from root
Expand Down Expand Up @@ -139,7 +143,8 @@ pub fn resolve_import_stmt(session: &mut SessionInfo, source_file_symbol: &Rc<Re
} else {
vec![]
};
let source_path = source_file_symbol.borrow().paths()[0].clone();
// source_file_symbol is either a file or a namespace with a single path
let source_path = source_file_symbol.borrow().path().to_vec()[0].clone();
let name_last_name: Vec<OYarn> = vec![name_split.last().unwrap().clone()];
let (mut next_symbol, mut fallback_sym) = _get_or_create_symbol(
session,
Expand Down Expand Up @@ -223,7 +228,7 @@ pub fn resolve_import_stmt(session: &mut SessionInfo, source_file_symbol: &Rc<Re
}

pub fn find_module(session: &mut SessionInfo, odoo_addons: Rc<RefCell<Symbol>>, name: &OYarn) -> Option<Rc<RefCell<Symbol>>> {
let paths = (*odoo_addons).borrow().paths().clone();
let paths = (*odoo_addons).borrow().path().to_vec();
for path in paths.iter() {
let full_path = Path::new(path.as_str()).join(name.as_str());
if !is_dir_cs(full_path.sanitize()) {
Expand All @@ -243,7 +248,7 @@ fn _resolve_packages(from_file: &Symbol, level: u32, from_stmt: Option<&Identifi
let mut first_part_tree: Vec<OYarn> = vec![];
if level > 0 {
let mut lvl = level;
if lvl > Path::new(&from_file.paths()[0]).components().count() as u32 {
if lvl > Path::new(&from_file.path().to_single_string()).components().count() as u32 {
panic!("Level is too high!")
}
if matches!(from_file.typ(), SymType::PACKAGE(_)) {
Expand Down Expand Up @@ -390,7 +395,7 @@ fn _resolve_new_symbol(session: &mut SessionInfo, parent: Rc<RefCell<Symbol>>, n
if (*parent).borrow().typ() == SymType::COMPILED {
return Ok((*parent).borrow_mut().add_new_compiled(session, &sym_name, &S!("")));
}
let paths = (*parent).borrow().paths().clone();
let paths = (*parent).borrow().path().to_vec();
for path in paths.iter() {
let mut full_path = Path::new(path.as_str()).join(name.to_string());
for stub in session.sync_odoo.stubs_dirs.iter() {
Expand Down Expand Up @@ -477,7 +482,7 @@ pub fn get_all_valid_names(session: &mut SessionInfo, source_file_symbol: &Rc<Re
let source_root = source_file_symbol.borrow().get_root().as_ref().unwrap().upgrade().unwrap();
let entry = source_root.borrow().get_entry().unwrap();
let (mut from_symbol, _fallback_sym, file_tree) = resolve_from_stmt(session, source_file_symbol, identifier_from.as_ref(), level);
let source_path = source_file_symbol.borrow().paths()[0].clone();
let source_path = source_file_symbol.borrow().path().to_single_string();
let mut result = HashMap::new();
let mut symbols_to_browse = vec![];
if from_symbol.is_none() {
Expand Down Expand Up @@ -548,15 +553,16 @@ fn valid_names_for_a_symbol(_session: &mut SessionInfo, symbol: &Rc<RefCell<Symb
}
res.extend(valid_name_from_symbol(symbol, start_filter));
},
SymType::NAMESPACE | SymType::DISK_DIR => {
for path in symbol.borrow().paths().iter() {
SymType::NAMESPACE => {
for path in symbol.borrow().path().to_multiple_vec().iter() {
res.extend(valid_name_from_disk(path, start_filter));
}
},
SymType::DISK_DIR => {
res.extend(valid_name_from_disk(&symbol.borrow().path().to_single_string(), start_filter));
}
SymType::PACKAGE(_) => {
for path in symbol.borrow().paths().iter() {
res.extend(valid_name_from_disk(path, start_filter));
}
res.extend(valid_name_from_disk(&symbol.borrow().path().to_single_string(), start_filter));
if only_on_disk {
return res;
}
Expand Down
30 changes: 18 additions & 12 deletions server/src/core/odoo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::core::diagnostics::{create_diagnostic, DiagnosticCode};
use crate::core::entry_point::EntryPointType;
use crate::core::file_mgr::AstType;
use crate::core::symbols::symbol::SymbolPath;
use crate::core::xml_data::OdooData;
use crate::core::xml_validation::XmlValidator;
use crate::features::document_symbols::DocumentSymbolFeature;
Expand Down Expand Up @@ -443,7 +444,7 @@ impl SyncOdoo {
let addon_symbol = addon_symbol[0].clone();
if odoo_addon_path.exists() {
if session.sync_odoo.load_odoo_addons {
addon_symbol.borrow_mut().add_path(
addon_symbol.borrow_mut().as_namespace_mut().add_path(
odoo_addon_path.sanitize()
);
EntryPointMgr::add_entry_to_addons(session, odoo_addon_path.sanitize(),
Expand All @@ -457,7 +458,7 @@ impl SyncOdoo {
for addon in session.sync_odoo.config.addons_paths.clone().iter() {
let addon_path = PathBuf::from(addon);
if addon_path.exists() {
addon_symbol.borrow_mut().add_path(
addon_symbol.borrow_mut().as_namespace_mut().add_path(
addon_path.sanitize()
);
EntryPointMgr::add_entry_to_addons(session, addon.clone(),
Expand All @@ -472,8 +473,10 @@ impl SyncOdoo {
fn build_modules(session: &mut SessionInfo) {
{
let addons_symbol = session.sync_odoo.get_symbol(session.sync_odoo.config.odoo_path.as_ref().unwrap(), &tree(vec!["odoo", "addons"], vec![]), u32::MAX)[0].clone();
let addons_path = addons_symbol.borrow().paths().clone();
for addon_path in addons_path.iter() {
let SymbolPath::Multiple(addons_paths) = addons_symbol.borrow().path() else {
panic!("Odoo addons symbol paths should be a namespace");
};
Comment on lines +476 to +478
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fda-odoo we wrote this together.
But since then SymbolPath::as_multiple has been introduced.
Shall I replace this by simply let addon_paths = addons_symbol.borrow().path().as_multiple()?

for addon_path in addons_paths.iter() {
info!("searching modules in {}", addon_path);
if PathBuf::from(addon_path).exists() {
//browse all dir in path
Expand Down Expand Up @@ -760,7 +763,7 @@ impl SyncOdoo {

pub fn add_to_rebuild_arch(&mut self, symbol: Rc<RefCell<Symbol>>) {
if DEBUG_THREADS {
trace!("ADDED TO ARCH - {}", symbol.borrow().paths().first().unwrap_or(&symbol.borrow().name().to_string()));
trace!("ADDED TO ARCH - {} - {:?}", symbol.borrow().name(), symbol.borrow().path());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fda-odoo I had shown you a Symbol::debug_paths() just for this cases.
But I decided to drop it , and use this instead (leveraging the derived debug trait on SymbolPath and always displaying the symbol's name anyway). What do you think?

}
if symbol.borrow().build_status(BuildSteps::ARCH) != BuildStatus::IN_PROGRESS {
let sym_clone = symbol.clone();
Expand All @@ -774,7 +777,7 @@ impl SyncOdoo {

pub fn add_to_rebuild_arch_eval(&mut self, symbol: Rc<RefCell<Symbol>>) {
if DEBUG_THREADS {
trace!("ADDED TO EVAL - {}", symbol.borrow().paths().first().unwrap_or(&symbol.borrow().name().to_string()));
trace!("ADDED TO EVAL - {} - {:?}", symbol.borrow().name(), symbol.borrow().path());
}
if symbol.borrow().build_status(BuildSteps::ARCH_EVAL) != BuildStatus::IN_PROGRESS {
let sym_clone = symbol.clone();
Expand All @@ -787,7 +790,7 @@ impl SyncOdoo {

pub fn add_to_validations(&mut self, symbol: Rc<RefCell<Symbol>>) {
if DEBUG_THREADS {
trace!("ADDED TO VALIDATION - {}", symbol.borrow().paths().first().unwrap_or(&symbol.borrow().name().to_string()));
trace!("ADDED TO VALIDATION - {} - {:?}", symbol.borrow().name(), symbol.borrow().path());
}
if symbol.borrow().build_status(BuildSteps::VALIDATION) != BuildStatus::IN_PROGRESS {
symbol.borrow_mut().set_build_status(BuildSteps::VALIDATION, BuildStatus::PENDING);
Expand All @@ -809,10 +812,10 @@ impl SyncOdoo {
}
if DEBUG_REBUILD_NOW {
if symbol.borrow().build_status(step) == BuildStatus::INVALID {
panic!("Trying to build an invalid symbol: {}", symbol.borrow().paths().first().unwrap_or(&symbol.borrow().name().to_string()));
panic!("Trying to build an invalid symbol: {} - {:?}", symbol.borrow().name(), symbol.borrow().path());
}
if symbol.borrow().build_status(step) == BuildStatus::IN_PROGRESS && !session.sync_odoo.is_in_rebuild(&symbol, step) {
error!("Trying to build a symbol that is NOT in the queue: {}", symbol.borrow().paths().first().unwrap_or(&symbol.borrow().name().to_string()));
error!("Trying to build a symbol that is NOT in the queue: {} - {:?}", symbol.borrow().name(), symbol.borrow().path());
}
}
if symbol.borrow().build_status(step) == BuildStatus::PENDING && symbol.borrow().previous_step_done(step) {
Expand All @@ -826,7 +829,7 @@ impl SyncOdoo {
} else if step == BuildSteps::ARCH_EVAL {
if DEBUG_REBUILD_NOW {
if symbol.borrow().build_status(BuildSteps::ARCH) != BuildStatus::DONE {
panic!("An evaluation has been requested on a non-arched symbol: {}", symbol.borrow().paths().first().unwrap_or(&symbol.borrow().name().to_string()));
panic!("An evaluation has been requested on a non-arched symbol: {} - {:?}", symbol.borrow().name(), symbol.borrow().path());
}
}
let mut builder = PythonArchEval::new(entry_point, symbol.clone());
Expand All @@ -835,7 +838,7 @@ impl SyncOdoo {
} else if step == BuildSteps::VALIDATION {
if DEBUG_REBUILD_NOW {
if symbol.borrow().build_status(BuildSteps::ARCH) != BuildStatus::DONE || symbol.borrow().build_status(BuildSteps::ARCH_EVAL) != BuildStatus::DONE {
panic!("An evaluation has been requested on a non-arched symbol: {}", symbol.borrow().paths().first().unwrap_or(&symbol.borrow().name().to_string()));
panic!("An evaluation has been requested on a non-arched symbol: {} - {:?}", symbol.borrow().name(), symbol.borrow().path());
}
}
let mut validator = PythonValidator::new(entry_point, symbol.clone());
Expand Down Expand Up @@ -951,7 +954,10 @@ impl SyncOdoo {
let mut to_del = Vec::from_iter(path_symbol.borrow().all_module_symbol().map(|x| x.clone()));
let mut index = 0;
while index < to_del.len() {
FileMgr::delete_path(session, &to_del[index].borrow().paths()[0]);
match to_del[index].borrow().path() {
SymbolPath::Single(p) => FileMgr::delete_path(session, &p),
SymbolPath::Multiple(_) | SymbolPath::None => {}
}
let mut to_del_child = Vec::from_iter(to_del[index].borrow().all_module_symbol().map(|x| x.clone()));
to_del.append(&mut to_del_child);
index += 1;
Expand Down
16 changes: 8 additions & 8 deletions server/src/core/python_arch_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ impl PythonArchBuilder {
self.current_step = if self.file_mode {BuildSteps::ARCH} else {BuildSteps::VALIDATION};
}
if DEBUG_STEPS && (!DEBUG_STEPS_ONLY_INTERNAL || !symbol.borrow().is_external()) {
trace!("building {} - {}", self.file.borrow().paths().first().unwrap_or(&S!("No path found")), symbol.borrow().name());
trace!("building {} - {}", self.file.borrow().path().to_single_string(), symbol.borrow().name());
}
symbol.borrow_mut().set_build_status(BuildSteps::ARCH, BuildStatus::IN_PROGRESS);
let path = self.file.borrow().get_symbol_first_path();
let path = self.file.borrow().get_file_path();
if self.file_mode {
let in_workspace = (self.file.borrow().parent().is_some() &&
self.file.borrow().parent().as_ref().unwrap().upgrade().is_some() &&
Expand Down Expand Up @@ -194,24 +194,24 @@ impl PythonArchBuilder {
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] )
warn!("error during parsing __all__ import in file {}", (*import_result.symbol).borrow().path().to_single_string())
}
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 {} - no value found", (*import_result.symbol).borrow().path().to_single_string())
}
} else {
warn!("invalid __all__ import in file {} - multiple evaluation found", (*import_result.symbol).borrow().paths()[0])
warn!("invalid __all__ import in file {} - multiple evaluation found", (*import_result.symbol).borrow().path().to_single_string())
}
} else {
warn!("invalid __all__ import in file {} - localizedSymbol not found", (*import_result.symbol).borrow().paths()[0])
warn!("invalid __all__ import in file {} - localizedSymbol not found", (*import_result.symbol).borrow().path().to_single_string())
}
} else {
warn!("invalid __all__ import in file {} - expired symbol", (*import_result.symbol).borrow().paths()[0])
warn!("invalid __all__ import in file {} - expired symbol", (*import_result.symbol).borrow().path().to_single_string())
}
} else {
warn!("invalid __all__ import in file {} - no symbol found", (*import_result.symbol).borrow().paths()[0])
warn!("invalid __all__ import in file {} - no symbol found", (*import_result.symbol).borrow().path().to_single_string())
}
}
let mut dep_to_add = vec![];
Expand Down
6 changes: 3 additions & 3 deletions server/src/core/python_arch_builder_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ impl PythonArchBuilderHooks {
let name = symbol.borrow().name().clone();
if name == "release" {
if symbol.borrow().get_main_entry_tree(session) == (vec![Sy!("odoo"), Sy!("release")], vec![]) {
let (maj, min, mic) = SyncOdoo::read_version(session, PathBuf::from(symbol.borrow().paths()[0].clone()));
let (maj, min, mic) = SyncOdoo::read_version(session, PathBuf::from(symbol.borrow().path().to_single_string()));
if maj != session.sync_odoo.version_major || min != session.sync_odoo.version_minor || mic != session.sync_odoo.version_micro {
session.sync_odoo.need_rebuild = true;
}
}
} else if name == "init" {
if compare_semver(session.sync_odoo.full_version.as_str(), "18.1") != Ordering::Less {
if symbol.borrow().get_main_entry_tree(session) == (vec![Sy!("odoo"), Sy!("init")], vec![]) {
let odoo_namespace = session.sync_odoo.get_symbol(symbol.borrow().paths()[0].as_str(), &(vec![Sy!("odoo")], vec![]), u32::MAX);
let odoo_namespace = session.sync_odoo.get_symbol(&symbol.borrow().path().to_single_string(), &(vec![Sy!("odoo")], vec![]), u32::MAX);
if let Some(odoo_namespace) = odoo_namespace.get(0) {
// create _ and Command as ext_symbols
let owner = symbol.clone();
Expand All @@ -199,7 +199,7 @@ impl PythonArchBuilderHooks {
} else if name == "werkzeug" {
if symbol.borrow().get_main_entry_tree(session) == (vec![Sy!("odoo"), Sy!("_monkeypatches"), Sy!("werkzeug")], vec![]) {
//doing this patch like this imply that an odoo project will make these functions available for all entrypoints, but heh
let werkzeug_url = session.sync_odoo.get_symbol(symbol.borrow().paths()[0].as_str(), &(vec![Sy!("werkzeug"), Sy!("urls")], vec![]), u32::MAX);
let werkzeug_url = session.sync_odoo.get_symbol(&symbol.borrow().path().to_single_string(), &(vec![Sy!("werkzeug"), Sy!("urls")], vec![]), u32::MAX);
if let Some(werkzeug_url) = werkzeug_url.first() {
let url_join = werkzeug_url.borrow().get_symbol(&(vec![], vec![Sy!("url_join")]), u32::MAX);
if url_join.is_empty() { //else, installed version is already patched
Expand Down
Loading