Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] server: eval odoo test common form import + diagnostic #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
29 changes: 28 additions & 1 deletion server/src/core/import_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use glob::glob;
use lsp_types::{Diagnostic, DiagnosticSeverity, DiagnosticTag, NumberOrString, Position, Range};
use tracing::error;
use std::rc::Rc;
use std::cell::RefCell;
Expand All @@ -21,7 +22,29 @@ pub struct ImportResult {
pub range: TextRange,
}

pub fn resolve_import_stmt(session: &mut SessionInfo, source_file_symbol: &Rc<RefCell<Symbol>>, from_stmt: Option<&Identifier>, name_aliases: &[Alias], level: Option<u32>, from_range: &TextRange) -> Vec<ImportResult> {
fn resolve_import_stmt_hook(alias: &Alias, from_symbol: &Option<Rc<RefCell<Symbol>>>, session: &mut SessionInfo, source_file_symbol: &Rc<RefCell<Symbol>>, from_stmt: Option<&Identifier>, level: Option<u32>, from_range: &TextRange, diagnostics: &mut Option<&mut Vec<Diagnostic>>) -> Option<ImportResult>{
if alias.name.as_str() == "Form" && (*(from_symbol.as_ref().unwrap())).borrow().get_tree().0 == vec!["odoo", "tests", "common"]{
let mut results = resolve_import_stmt(session, source_file_symbol, Some(&Identifier::new(S!("odoo.tests"), from_stmt.unwrap().range)), &[alias.clone()], level, from_range, &mut None);
if let Some(diagnostic) = diagnostics.as_mut() {
diagnostic.push(
Diagnostic::new(
Range::new(Position::new(alias.range.start().to_u32(), 0), Position::new(alias.range.end().to_u32(), 0)),
Some(DiagnosticSeverity::WARNING),
Some(NumberOrString::String(S!("OLS20006"))),
Some(EXTENSION_NAME.to_string()),
S!("Deprecation Warning: Since 17.0: odoo.tests.common.Form is deprecated, use odoo.tests.Form"),
None,
Some(vec![DiagnosticTag::DEPRECATED]),
)
);
}
results.pop()
} else {
None
}
}

pub fn resolve_import_stmt(session: &mut SessionInfo, source_file_symbol: &Rc<RefCell<Symbol>>, from_stmt: Option<&Identifier>, name_aliases: &[Alias], level: Option<u32>, from_range: &TextRange, diagnostics: &mut Option<&mut Vec<Diagnostic>>) -> Vec<ImportResult> {
//A: search base of different imports
let _source_file_symbol_lock = source_file_symbol.borrow_mut();
let file_tree = _resolve_packages(
Expand Down Expand Up @@ -55,6 +78,10 @@ pub fn resolve_import_stmt(session: &mut SessionInfo, source_file_symbol: &Rc<Re
for alias in name_aliases.iter() {
let name = alias.name.as_str().to_string();
name_index += 1;
if let Some(hook_result) = resolve_import_stmt_hook(alias, &from_symbol, session, source_file_symbol, from_stmt, level, from_range, diagnostics){
result[name_index as usize] = hook_result;
continue;
}
if name == "*" {
result[name_index as usize].found = true;
result[name_index as usize].symbol = from_symbol.as_ref().unwrap().clone();
Expand Down
2 changes: 1 addition & 1 deletion server/src/core/python_arch_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl PythonArchBuilder {
from_stmt,
name_aliases,
level,
range).remove(0); //we don't need the vector with this call as there will be 1 result.
range, &mut None).remove(0); //we don't need the vector with this call as there will be 1 result.
if !import_result.found {
session.sync_odoo.not_found_symbols.insert(self.sym_stack[0].clone());
let file_tree_flattened = vec![import_result.file_tree.0.clone(), import_result.file_tree.1.clone()].concat();
Expand Down
2 changes: 1 addition & 1 deletion server/src/core/python_arch_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl PythonArchEval {
from_stmt,
name_aliases,
level,
range);
range, &mut Some(&mut self.diagnostics));

for _import_result in import_results.iter() {
let variable = self.sym_stack.last().unwrap().borrow_mut().get_positioned_symbol(&_import_result.name, &_import_result.range);
Expand Down
4 changes: 2 additions & 2 deletions server/src/core/python_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl PythonValidator {
from_stmt,
name_aliases,
level,
range);
range, &mut None);
for import_result in import_results.iter() {
if import_result.found && self.current_module.is_some() {
let module = import_result.symbol.borrow().find_module();
Expand Down Expand Up @@ -414,4 +414,4 @@ impl PythonValidator {
//TODO do we want to raise something?
}
}
}
}