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
4 changes: 4 additions & 0 deletions server/src/core/symbols/module_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OYarn> {
&self.all_depends
}

pub fn get_dependencies(&self, step: usize, level: usize) -> Option<&PtrWeakHashSet<Weak<RefCell<Symbol>>>>
{
self.dependencies.get(step)?.get(level)?.as_ref()
Expand Down
2 changes: 1 addition & 1 deletion server/src/features/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ fn build_completion_item_from_symbol(session: &mut SessionInfo, symbols: Vec<Rc<
documentation: Some(
lsp_types::Documentation::MarkupContent(MarkupContent {
kind: lsp_types::MarkupKind::Markdown,
value: FeaturesUtils::build_markdown_description(session, None, &symbols.iter().map(|symbol|
value: FeaturesUtils::build_markdown_description(session, None, None, &symbols.iter().map(|symbol|
Evaluation {
symbol: EvaluationSymbol::new_with_symbol(Rc::downgrade(symbol), None,
context_of_symbol.clone(),
Expand Down
30 changes: 29 additions & 1 deletion server/src/features/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ruff_text_size::TextSize;
use std::path::PathBuf;
use std::{cell::RefCell, rc::Rc};

use crate::constants::SymType;
use crate::constants::{PackageType, SymType};
use crate::core::evaluation::{Evaluation, EvaluationValue, ExprOrIdent};
use crate::core::file_mgr::{FileInfo, FileMgr};
use crate::core::odoo::SyncOdoo;
Expand Down Expand Up @@ -91,6 +91,33 @@ impl DefinitionFeature {
model_found
}

fn check_for_module_string(session: &mut SessionInfo, eval: &Evaluation, file_symbol: &Rc<RefCell<Symbol>>, file_path: &String, links: &mut Vec<LocationLink>) -> 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<RefCell<Symbol>>, links: &mut Vec<LocationLink>) -> bool {
let value = if let Some(eval_value) = eval.value.as_ref() {
if let EvaluationValue::CONSTANT(Expr::StringLiteral(expr)) = eval_value {
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 25 additions & 3 deletions server/src/features/features_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -320,7 +320,14 @@ impl FeaturesUtils {
vec![]
}

pub fn build_markdown_description(session: &mut SessionInfo, file_symbol: Option<Rc<RefCell<Symbol>>>, evals: &Vec<Evaluation>, call_expr: &Option<ExprCall>, offset: Option<usize>) -> String {
pub fn build_markdown_description(
session: &mut SessionInfo,
file_symbol: Option<Rc<RefCell<Symbol>>>,
file_path: Option<&String>,
evals: &Vec<Evaluation>,
call_expr: &Option<ExprCall>,
offset: Option<usize>
) -> String {
#[derive(Debug, Eq, PartialEq, Hash)]
struct SymbolKey {
name: OYarn,
Expand All @@ -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);
Expand All @@ -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| {
Expand Down
4 changes: 2 additions & 2 deletions server/src/features/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand All @@ -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
})
Expand Down