Skip to content

Commit d1af2d1

Browse files
committed
[IMP] hover and definition for module names in manifest
1 parent 4449f9e commit d1af2d1

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

server/src/core/symbols/module_symbol.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ impl ModuleSymbol {
415415
symbol.borrow().as_module_package().dir_name == *dir_name || symbol.borrow().as_module_package().all_depends.contains(dir_name)
416416
}
417417

418+
pub fn get_all_depends(&self) -> &HashSet<OYarn> {
419+
&self.all_depends
420+
}
421+
418422
pub fn get_dependencies(&self, step: usize, level: usize) -> Option<&PtrWeakHashSet<Weak<RefCell<Symbol>>>>
419423
{
420424
self.dependencies.get(step)?.get(level)?.as_ref()

server/src/features/definition.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ruff_text_size::TextSize;
44
use std::path::PathBuf;
55
use std::{cell::RefCell, rc::Rc};
66

7-
use crate::constants::SymType;
7+
use crate::constants::{PackageType, SymType};
88
use crate::core::evaluation::{Evaluation, EvaluationValue};
99
use crate::core::file_mgr::{FileInfo, FileMgr};
1010
use crate::core::odoo::SyncOdoo;
@@ -90,6 +90,33 @@ impl DefinitionFeature {
9090
model_found
9191
}
9292

93+
fn check_for_module_string(session: &mut SessionInfo, eval: &Evaluation, file_symbol: &Rc<RefCell<Symbol>>, links: &mut Vec<LocationLink>) -> bool {
94+
if file_symbol.borrow().typ() != SymType::PACKAGE(PackageType::MODULE) {
95+
// If not on manifest, we don't check for modules
96+
return false;
97+
};
98+
let value = if let Some(eval_value) = eval.value.as_ref() {
99+
if let EvaluationValue::CONSTANT(Expr::StringLiteral(expr)) = eval_value {
100+
oyarn!("{}", expr.value.to_string())
101+
} else {
102+
return false;
103+
}
104+
} else {
105+
return false;
106+
};
107+
let Some(module) = session.sync_odoo.modules.get(&oyarn!("{}", value)).and_then(|m| m.upgrade()) else {
108+
return false;
109+
};
110+
let path = PathBuf::from(module.borrow().paths()[0].clone()).join("__manifest__.py").sanitize();
111+
links.push(LocationLink{
112+
origin_selection_range: None,
113+
target_uri: FileMgr::pathname2uri(&path),
114+
target_selection_range: Range::default(),
115+
target_range: Range::default(),
116+
});
117+
true
118+
}
119+
93120
fn check_for_xml_id_string(session: &mut SessionInfo, eval: &Evaluation, file_symbol: &Rc<RefCell<Symbol>>, links: &mut Vec<LocationLink>) -> bool {
94121
let value = if let Some(eval_value) = eval.value.as_ref() {
95122
if let EvaluationValue::CONSTANT(Expr::StringLiteral(expr)) = eval_value {
@@ -166,6 +193,7 @@ impl DefinitionFeature {
166193
let eval = evaluations[index].clone();
167194
if DefinitionFeature::check_for_domain_field(session, &eval, file_symbol, &call_expr, offset, &mut links) ||
168195
DefinitionFeature::check_for_compute_string(session, &eval, file_symbol,&call_expr, offset, &mut links) ||
196+
DefinitionFeature::check_for_module_string(session, &eval, file_symbol, &mut links) ||
169197
DefinitionFeature::check_for_model_string(session, &eval, file_symbol, &mut links) ||
170198
DefinitionFeature::check_for_xml_id_string(session, &eval, file_symbol, &mut links) {
171199
index += 1;

server/src/features/features_utils.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::path::PathBuf;
1111
use std::rc::Weak;
1212
use std::{cell::RefCell, rc::Rc};
1313

14-
use crate::constants::SymType;
14+
use crate::constants::{PackageType, SymType};
1515
use crate::constants::OYarn;
1616
use crate::core::evaluation::{Context, ContextValue, Evaluation, EvaluationSymbolPtr, EvaluationSymbolWeak, EvaluationValue};
1717
use crate::core::symbols::symbol::Symbol;
@@ -339,6 +339,20 @@ impl FeaturesUtils {
339339
if let Some(EvaluationValue::CONSTANT(Expr::StringLiteral(expr))) = eval.value.as_ref() {
340340
let mut block = S!("");
341341
let str = expr.value.to_string();
342+
if let Some(SymType::PACKAGE(PackageType::MODULE)) = file_symbol.as_ref().map(|fs| fs.borrow().typ()) {
343+
// If we are in manifest, we check if the string is a module and list the underlying module dependencies
344+
if let Some(module) = session.sync_odoo.modules.get(&oyarn!("{}", str)).and_then(|m| m.upgrade()) {
345+
block += format!("Module: {}", module.borrow().name()).as_str();
346+
let module_ref = module.borrow();
347+
let dependencies = module_ref.as_module_package().get_all_depends();
348+
if !dependencies.is_empty() {
349+
block += " \n*** \nDependencies: \n";
350+
block += &dependencies.iter().map(|dep| format!("- {}", dep)).join(" \n");
351+
}
352+
}
353+
blocks.push(block);
354+
continue;
355+
}
342356
let from_module = file_symbol.as_ref().and_then(|file_symbol| file_symbol.borrow().find_module());
343357
if let (Some(call_expression), Some(file_sym), Some(offset)) = (call_expr, file_symbol.as_ref(), offset){
344358
let mut special_string_syms = FeaturesUtils::check_for_string_special_syms(session, &str, call_expression, offset, expr.range, file_sym);
@@ -622,7 +636,7 @@ impl FeaturesUtils {
622636
}
623637

624638
/// Finds and returns useful links for an evaluation
625-
fn get_useful_link(session: &mut SessionInfo, typ: &EvaluationSymbolPtr) -> String {
639+
fn get_useful_link(_session: &mut SessionInfo, typ: &EvaluationSymbolPtr) -> String {
626640
// Possibly add more links in the future
627641
let Some(typ) = typ.upgrade_weak() else {
628642
return S!("")

0 commit comments

Comments
 (0)