From 5647c4321daa89122794623927c270ecc5ea61c9 Mon Sep 17 00:00:00 2001 From: M Mahrous Date: Wed, 15 Oct 2025 15:55:55 +0200 Subject: [PATCH] [IMP] hover and definition for module names in manifest --- server/src/core/symbols/module_symbol.rs | 4 ++++ server/src/features/completion.rs | 2 +- server/src/features/definition.rs | 30 +++++++++++++++++++++++- server/src/features/features_utils.rs | 28 +++++++++++++++++++--- server/src/features/hover.rs | 4 ++-- 5 files changed, 61 insertions(+), 7 deletions(-) diff --git a/server/src/core/symbols/module_symbol.rs b/server/src/core/symbols/module_symbol.rs index a6c29f56..a043407e 100644 --- a/server/src/core/symbols/module_symbol.rs +++ b/server/src/core/symbols/module_symbol.rs @@ -460,6 +460,10 @@ impl ModuleSymbol { symbol.borrow().as_module_package().dir_name == *dir_name || symbol.borrow().as_module_package().all_depends.contains(dir_name) } + pub fn get_all_depends(&self) -> &HashSet { + &self.all_depends + } + pub fn get_dependencies(&self, step: usize, level: usize) -> Option<&PtrWeakHashSet>>> { self.dependencies.get(step)?.get(level)?.as_ref() diff --git a/server/src/features/completion.rs b/server/src/features/completion.rs index 54da9bda..bd6d2720 100644 --- a/server/src/features/completion.rs +++ b/server/src/features/completion.rs @@ -1112,7 +1112,7 @@ fn build_completion_item_from_symbol(session: &mut SessionInfo, symbols: Vec>, file_path: &String, links: &mut Vec) -> bool { + if file_symbol.borrow().typ() != SymType::PACKAGE(PackageType::MODULE) || !file_path.ends_with("__manifest__.py") { + // If not on manifest, we don't check for modules + return false; + }; + let value = if let Some(eval_value) = eval.value.as_ref() { + if let EvaluationValue::CONSTANT(Expr::StringLiteral(expr)) = eval_value { + oyarn!("{}", expr.value.to_string()) + } else { + return false; + } + } else { + return false; + }; + let Some(module) = session.sync_odoo.modules.get(&oyarn!("{}", value)).and_then(|m| m.upgrade()) else { + return false; + }; + let path = PathBuf::from(module.borrow().paths()[0].clone()).join("__manifest__.py").sanitize(); + links.push(LocationLink{ + origin_selection_range: None, + target_uri: FileMgr::pathname2uri(&path), + target_selection_range: Range::default(), + target_range: Range::default(), + }); + true + } + fn check_for_xml_id_string(session: &mut SessionInfo, eval: &Evaluation, file_symbol: &Rc>, links: &mut Vec) -> bool { let value = if let Some(eval_value) = eval.value.as_ref() { if let EvaluationValue::CONSTANT(Expr::StringLiteral(expr)) = eval_value { @@ -238,6 +265,7 @@ impl DefinitionFeature { let eval = evaluations[index].clone(); if DefinitionFeature::check_for_domain_field(session, &eval, file_symbol, &call_expr, offset, &mut links) || DefinitionFeature::check_for_compute_string(session, &eval, file_symbol,&call_expr, offset, &mut links) || + DefinitionFeature::check_for_module_string(session, &eval, file_symbol, &file_info.borrow().uri, &mut links) || DefinitionFeature::check_for_model_string(session, &eval, file_symbol, &mut links) || DefinitionFeature::check_for_xml_id_string(session, &eval, file_symbol, &mut links) { index += 1; diff --git a/server/src/features/features_utils.rs b/server/src/features/features_utils.rs index 95cb07d4..2593e9a3 100644 --- a/server/src/features/features_utils.rs +++ b/server/src/features/features_utils.rs @@ -11,7 +11,7 @@ use std::path::PathBuf; use std::rc::Weak; use std::{cell::RefCell, rc::Rc}; -use crate::constants::SymType; +use crate::constants::{PackageType, SymType}; use crate::constants::OYarn; use crate::core::evaluation::{Context, ContextValue, Evaluation, EvaluationSymbolPtr, EvaluationSymbolWeak, EvaluationValue}; use crate::core::symbols::symbol::Symbol; @@ -320,7 +320,14 @@ impl FeaturesUtils { vec![] } - pub fn build_markdown_description(session: &mut SessionInfo, file_symbol: Option>>, evals: &Vec, call_expr: &Option, offset: Option) -> String { + pub fn build_markdown_description( + session: &mut SessionInfo, + file_symbol: Option>>, + file_path: Option<&String>, + evals: &Vec, + call_expr: &Option, + offset: Option + ) -> String { #[derive(Debug, Eq, PartialEq, Hash)] struct SymbolKey { name: OYarn, @@ -339,6 +346,21 @@ impl FeaturesUtils { if let Some(EvaluationValue::CONSTANT(Expr::StringLiteral(expr))) = eval.value.as_ref() { let mut block = S!(""); let str = expr.value.to_string(); + if let Some(SymType::PACKAGE(PackageType::MODULE)) = file_symbol.as_ref().map(|fs| fs.borrow().typ()) + && file_path.map_or(false, |fp| fp.ends_with("__manifest__.py")) { + // If we are in manifest, we check if the string is a module and list the underlying module dependencies + if let Some(module) = session.sync_odoo.modules.get(&oyarn!("{}", str)).and_then(|m| m.upgrade()) { + block += format!("Module: {}", module.borrow().name()).as_str(); + let module_ref = module.borrow(); + let dependencies = module_ref.as_module_package().get_all_depends(); + if !dependencies.is_empty() { + block += " \n*** \nDependencies: \n"; + block += &dependencies.iter().map(|dep| format!("- {}", dep)).join(" \n"); + } + } + blocks.push(block); + continue; + } let from_module = file_symbol.as_ref().and_then(|file_symbol| file_symbol.borrow().find_module()); if let (Some(call_expression), Some(file_sym), Some(offset)) = (call_expr, file_symbol.as_ref(), offset){ let mut special_string_syms = FeaturesUtils::check_for_string_special_syms(session, &str, call_expression, offset, expr.range, file_sym); @@ -365,7 +387,7 @@ impl FeaturesUtils { .chain(evals.iter().take(index).cloned()) .chain(evals.iter().skip(index + 1).cloned()) .collect(); - let r = FeaturesUtils::build_markdown_description(session, file_symbol, &string_domain_fields_evals, call_expr, Some(offset)); + let r = FeaturesUtils::build_markdown_description(session, file_symbol, file_path, &string_domain_fields_evals, call_expr, Some(offset)); // remove the injected `base_attr` context value special_string_syms.iter_mut().for_each(|sym_rc| { sym_rc.borrow_mut().evaluations_mut().into_iter().flatten().for_each(|eval| { diff --git a/server/src/features/hover.rs b/server/src/features/hover.rs index 1caac494..81f3f434 100644 --- a/server/src/features/hover.rs +++ b/server/src/features/hover.rs @@ -29,7 +29,7 @@ impl HoverFeature { Some(Hover { contents: HoverContents::Markup(MarkupContent { kind: lsp_types::MarkupKind::Markdown, - value: FeaturesUtils::build_markdown_description(session, Some(file_symbol.clone()), &evals, &call_expr, Some(offset)) + value: FeaturesUtils::build_markdown_description(session, Some(file_symbol.clone()), Some(&file_info.borrow().uri), &evals, &call_expr, Some(offset)) }), range: range }) @@ -48,7 +48,7 @@ impl HoverFeature { return Some(Hover { contents: HoverContents::Markup(MarkupContent { kind: lsp_types::MarkupKind::Markdown, - value: FeaturesUtils::build_markdown_description(session, Some(file_symbol.clone()), &evals, &None, Some(offset)) + value: FeaturesUtils::build_markdown_description(session, Some(file_symbol.clone()), Some(&file_info.borrow().uri), &evals, &None, Some(offset)) }), range: range })