Skip to content

Commit f7ea246

Browse files
committed
[IMP] Address cargo compiler warnings
1 parent fd64618 commit f7ea246

File tree

7 files changed

+38
-34
lines changed

7 files changed

+38
-34
lines changed

server/src/core/evaluation.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,19 @@ pub type Context = HashMap<String, ContextValue>;
198198
* diagnostics: a vec the hook can fill to add diagnostics
199199
* file_symbol: if provided, can be used to add dependencies
200200
*/
201-
type GetSymbolHook = fn (session: &mut SessionInfo, eval: &EvaluationSymbol, context: &mut Option<Context>, diagnostics: &mut Vec<Diagnostic>, scope: Option<Rc<RefCell<Symbol>>>) -> Option<EvaluationSymbolPtr>;
201+
type GetSymbolHookCallable = fn (session: &mut SessionInfo, eval: &EvaluationSymbol, context: &mut Option<Context>, diagnostics: &mut Vec<Diagnostic>, scope: Option<Rc<RefCell<Symbol>>>) -> Option<EvaluationSymbolPtr>;
202+
203+
#[derive(Debug, Clone)]
204+
pub struct GetSymbolHook {
205+
pub callable: GetSymbolHookCallable,
206+
pub name: String
207+
}
208+
209+
impl PartialEq for GetSymbolHook {
210+
fn eq(&self, other: &Self) -> bool {
211+
self.name == other.name
212+
}
213+
}
202214

203215

204216
#[derive(Debug, Clone)]
@@ -1194,7 +1206,7 @@ impl Evaluation {
11941206
let get_item = get_item.borrow();
11951207
if get_item.evaluations().is_some() && get_item.evaluations().unwrap().len() == 1 {
11961208
let get_item_eval = &get_item.evaluations().unwrap()[0];
1197-
if let Some(hook) = get_item_eval.symbol.get_symbol_hook {
1209+
if let Some(hook) = get_item_eval.symbol.get_symbol_hook.as_ref() {
11981210
let parent_file_or_func = parent.clone().borrow().parent_file_or_function().as_ref().unwrap().upgrade().unwrap();
11991211
let is_in_validation = match parent_file_or_func.borrow().typ().clone() {
12001212
SymType::FILE | SymType::PACKAGE(_) | SymType::FUNCTION => {
@@ -1206,7 +1218,7 @@ impl Evaluation {
12061218
let old_range = context.as_mut().unwrap().remove(&S!("range"));
12071219
context.as_mut().unwrap().insert(S!("range"), ContextValue::RANGE(sub.slice.range()));
12081220
context.as_mut().unwrap().insert(S!("is_in_validation"), ContextValue::BOOLEAN(is_in_validation));
1209-
let hook_result = hook(session, &get_item_eval.symbol, context, &mut diagnostics, Some(parent.clone()));
1221+
let hook_result = (hook.callable)(session, &get_item_eval.symbol, context, &mut diagnostics, Some(parent.clone()));
12101222
if let Some(hook_result) = hook_result {
12111223
match hook_result {
12121224
EvaluationSymbolPtr::WEAK(ref weak) => {
@@ -1347,8 +1359,7 @@ impl Evaluation {
13471359
},
13481360
ArgumentType::KWARG => {
13491361
kwarg_index = index as i32;
1350-
},
1351-
_ => {}
1362+
}
13521363
}
13531364
}
13541365
if !function.is_static {
@@ -1456,7 +1467,7 @@ impl Evaluation {
14561467
diagnostics
14571468
}
14581469

1459-
fn process_argument_diagnostics(session: &SessionInfo, expr_call: &ExprCall, diagnostics: Vec<Vec<Diagnostic>>, eval_count: usize) -> Vec<Diagnostic> {
1470+
fn process_argument_diagnostics(session: &SessionInfo, expr_call: &ExprCall, diagnostics: Vec<Vec<Diagnostic>>, _eval_count: usize) -> Vec<Diagnostic> {
14601471
let mut filtered_diagnostics = vec![];
14611472
//iter through diagnostics and check that each evaluation has the same amount of diagnostics with code OLS01007 or OLS01008 or OLS01010
14621473
let all_same_issues = diagnostics.iter().fold_while(None, |acc, diags| {
@@ -1789,8 +1800,8 @@ impl EvaluationSymbol {
17891800
/* Execute Hook, then return the effective EvaluationSymbolPtr */
17901801
pub fn get_symbol(&self, session: &mut SessionInfo, context: &mut Option<Context>, diagnostics: &mut Vec<Diagnostic>, file_symbol: Option<Rc<RefCell<Symbol>>>) -> EvaluationSymbolPtr {
17911802
let mut custom_eval = None;
1792-
if let Some(hook) = self.get_symbol_hook {
1793-
custom_eval = hook(session, self, context, diagnostics, file_symbol);
1803+
if let Some(hook) = self.get_symbol_hook.as_ref() {
1804+
custom_eval = (hook.callable)(session, self, context, diagnostics, file_symbol);
17941805
}
17951806
custom_eval.as_ref().unwrap_or(&self.sym).clone()
17961807
}

server/src/core/odoo.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::features::definition::DefinitionFeature;
1212
use crate::features::hover::HoverFeature;
1313
use std::collections::HashMap;
1414
use std::cell::RefCell;
15-
use std::ffi::OsStr;
1615
use std::rc::{Rc, Weak};
1716
use std::sync::atomic::{AtomicBool, Ordering};
1817
use std::sync::{Arc, Mutex};

server/src/core/python_arch_eval_hooks.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use ruff_text_size::TextRange;
1313
use tracing::warn;
1414
use weak_table::traits::WeakElement;
1515
use crate::core::diagnostics::{create_diagnostic, DiagnosticCode};
16+
use crate::core::evaluation::GetSymbolHook;
1617
use crate::core::odoo::SyncOdoo;
1718
use crate::core::evaluation::Context;
1819
use crate::core::symbols::symbol::Symbol;
@@ -442,8 +443,8 @@ static arch_eval_function_hooks: Lazy<Vec<PythonArchEvalFunctionHook>> = Lazy::n
442443
symbol.borrow_mut().set_evaluations(vec![Evaluation {
443444
symbol: EvaluationSymbol::new_with_symbol(Weak::new(),
444445
Some(true),
445-
HashMap::from([(S!("hook_name"), ContextValue::STRING(S!("eval_env_get_item")))]),
446-
Some(PythonArchEvalHooks::eval_env_get_item)
446+
HashMap::new(),
447+
Some(GetSymbolHook{callable: PythonArchEvalHooks::eval_env_get_item, name: S!("eval_env_get_item")})
447448
),
448449
value: None,
449450
range: None
@@ -458,7 +459,7 @@ static arch_eval_function_hooks: Lazy<Vec<PythonArchEvalFunctionHook>> = Lazy::n
458459
symbol: EvaluationSymbol::new_with_symbol(Weak::new(),
459460
Some(true),
460461
HashMap::new(),
461-
Some(PythonArchEvalHooks::eval_registry_get_item)
462+
Some(GetSymbolHook{callable: PythonArchEvalHooks::eval_registry_get_item, name: S!("eval_registry_get_item")})
462463
),
463464
value: None,
464465
range: None
@@ -600,7 +601,7 @@ static arch_eval_function_hooks: Lazy<Vec<PythonArchEvalFunctionHook>> = Lazy::n
600601
Rc::downgrade(&fields_class_sym),
601602
Some(true),
602603
HashMap::new(),
603-
Some(PythonArchEvalHooks::eval_init)
604+
Some(GetSymbolHook{callable: PythonArchEvalHooks::eval_init, name: S!("eval_init")})
604605
),
605606
value: None,
606607
range: None,
@@ -874,7 +875,7 @@ impl PythonArchEvalHooks {
874875
Rc::downgrade(return_sym.last().unwrap()),
875876
Some(true),
876877
HashMap::new(),
877-
Some(PythonArchEvalHooks::eval_get)
878+
Some(GetSymbolHook{callable: PythonArchEvalHooks::eval_get, name: S!("eval_get")})
878879
),
879880
value: None,
880881
range: None
@@ -898,7 +899,7 @@ impl PythonArchEvalHooks {
898899
Rc::downgrade(return_sym),
899900
Some(true),
900901
HashMap::new(),
901-
Some(PythonArchEvalHooks::eval_get)
902+
Some(GetSymbolHook{callable: PythonArchEvalHooks::eval_get, name: S!("eval_get")})
902903
),
903904
value: None,
904905
range: None
@@ -978,7 +979,7 @@ impl PythonArchEvalHooks {
978979
Weak::new(),
979980
Some(true),
980981
HashMap::new(),
981-
Some(PythonArchEvalHooks::eval_relational)
982+
Some(GetSymbolHook{callable: PythonArchEvalHooks::eval_relational, name: S!("eval_relational")})
982983
),
983984
value: None,
984985
range: None,
@@ -991,7 +992,7 @@ impl PythonArchEvalHooks {
991992
Weak::new(),
992993
Some(true),
993994
HashMap::new(),
994-
Some(PythonArchEvalHooks::eval_relational)
995+
Some(GetSymbolHook{callable: PythonArchEvalHooks::eval_relational, name: S!("eval_relational")})
995996
),
996997
value: None,
997998
range: None,
@@ -1108,9 +1109,9 @@ impl PythonArchEvalHooks {
11081109
Some(true),
11091110
HashMap::new(),
11101111
Some(match relational {
1111-
Some(oyarn) if oyarn == oyarn!("One2many") => PythonArchEvalHooks::eval_init_relational_one2many,
1112-
Some(_) => PythonArchEvalHooks::eval_init_relational,
1113-
None => PythonArchEvalHooks::eval_init,
1112+
Some(oyarn) if oyarn == oyarn!("One2many") => GetSymbolHook{callable: PythonArchEvalHooks::eval_init_relational_one2many, name: S!("eval_init_relational_one2many")},
1113+
Some(_) => GetSymbolHook{callable: PythonArchEvalHooks::eval_init_relational, name: S!("eval_init_relational")},
1114+
None => GetSymbolHook{callable: PythonArchEvalHooks::eval_init, name: S!("eval_init")},
11141115
})
11151116
),
11161117
value: None,
@@ -1293,7 +1294,7 @@ impl PythonArchEvalHooks {
12931294
Rc::downgrade(&func_sym),
12941295
Some(true),
12951296
HashMap::new(),
1296-
Some(PythonArchEvalHooks::eval_env_ref)
1297+
Some(GetSymbolHook{callable: PythonArchEvalHooks::eval_env_ref, name: S!("eval_env_ref")})
12971298
),
12981299
value: None,
12991300
range: None

server/src/core/xml_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{cell::RefCell, cmp::Ordering, collections::{HashMap, HashSet}, rc::Rc}
33
use lsp_types::{Diagnostic, Position, Range};
44
use tracing::{info, trace};
55

6-
use crate::{Sy, constants::{BuildSteps, DEBUG_STEPS, OYarn}, core::{diagnostics::{DiagnosticCode, create_diagnostic}, entry_point::{EntryPoint, EntryPointType}, evaluation::ContextValue, file_mgr::{FileInfo, FileMgr}, model::Model, odoo::SyncOdoo, symbols::{module_symbol::ModuleSymbol, symbol::Symbol}, xml_data::{OdooData, OdooDataRecord, XmlDataDelete, XmlDataMenuItem, XmlDataTemplate}}, oyarn, threads::SessionInfo, utils::compare_semver};
6+
use crate::{Sy, constants::{BuildSteps, DEBUG_STEPS, OYarn}, core::{diagnostics::{DiagnosticCode, create_diagnostic}, entry_point::{EntryPoint, EntryPointType}, evaluation::ContextValue, file_mgr::FileInfo, model::Model, odoo::SyncOdoo, symbols::symbol::Symbol, xml_data::{OdooData, OdooDataRecord, XmlDataDelete, XmlDataMenuItem, XmlDataTemplate}}, oyarn, threads::SessionInfo, utils::compare_semver};
77

88

99

server/src/features/completion.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -851,10 +851,8 @@ fn complete_subscript(session: &mut SessionInfo, file: &Rc<RefCell<Symbol>>, exp
851851
if get_item.borrow().evaluations().as_ref().unwrap().len() == 1 {
852852
let get_item_bw = get_item.borrow();
853853
let get_item_eval = get_item_bw.evaluations().as_ref().unwrap().first().unwrap();
854-
if let EvaluationSymbolPtr::WEAK(w) = get_item_eval.symbol.get_symbol_ptr() {
855-
if matches!(w.context.get(&S!("hook_name")), Some(hook_name) if hook_name.as_string() == "eval_env_get_item") {
856-
return complete_expr(&expr_subscript.slice, session, file, offset, is_param, &vec![ExpectedType::MODEL_NAME]);
857-
}
854+
if get_item_eval.symbol.get_symbol_hook.as_ref().map(|hook| &hook.name == "eval_env_get_item").unwrap_or_default(){
855+
return complete_expr(&expr_subscript.slice, session, file, offset, is_param, &vec![ExpectedType::MODEL_NAME]);
858856
}
859857
}
860858
}
@@ -1186,4 +1184,4 @@ fn get_completion_item_kind(typ: &SymType) -> CompletionItemKind {
11861184
SymType::XML_FILE => CompletionItemKind::FILE,
11871185
SymType::CSV_FILE => CompletionItemKind::FILE,
11881186
}
1189-
}
1187+
}

server/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub trait PathSanitizer {
158158
impl PathSanitizer for PathBuf {
159159

160160
fn sanitize(&self) -> String {
161-
let mut path = self.to_slash_lossy().to_string();
161+
let path = self.to_slash_lossy().to_string();
162162

163163
#[cfg(windows)]
164164
{
@@ -204,7 +204,7 @@ impl PathSanitizer for PathBuf {
204204
impl PathSanitizer for Path {
205205

206206
fn sanitize(&self) -> String {
207-
let mut path = self.to_slash_lossy().to_string();
207+
let path = self.to_slash_lossy().to_string();
208208

209209
#[cfg(windows)]
210210
{

server/tests/test_utils.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ pub fn verify_diagnostics_against_doc(
7777
let mut diags: HashMap<u32, Vec<&Diagnostic>> = HashMap::new();
7878
for diag in &diagnostics {
7979
let line = diag.range.start.line;
80-
let code_str = match &diag.code {
81-
Some(NumberOrString::String(c)) => c.clone(),
82-
Some(NumberOrString::Number(n)) => n.to_string(),
83-
None => continue,
84-
};
8580
diags.entry(line).or_default().push(diag);
8681
}
8782

0 commit comments

Comments
 (0)