@@ -2,12 +2,13 @@ use std::cmp::Ordering;
2
2
use std:: collections:: HashSet ;
3
3
use std:: rc:: Rc ;
4
4
use std:: cell:: RefCell ;
5
- use lsp_types:: notification:: ShowMessage ;
6
- use lsp_types:: MessageType ;
7
5
use ruff_python_ast:: Expr ;
8
- use lsp_types:: { Diagnostic , ShowMessageParams , notification:: Notification } ;
6
+ use lsp_types:: Diagnostic ;
7
+ use ruff_text_size:: TextRange ;
9
8
use tracing:: error;
10
9
use weak_table:: PtrWeakHashSet ;
10
+ use crate :: core:: diagnostics:: { create_diagnostic, DiagnosticCode } ;
11
+ use crate :: core:: file_mgr:: { FileMgr } ;
11
12
12
13
use crate :: constants:: { OYarn , SymType } ;
13
14
use crate :: core:: model:: { Model , ModelData } ;
@@ -49,7 +50,34 @@ impl PythonOdooBuilder {
49
50
self . _add_magic_fields ( session) ;
50
51
let model_name = sym. borrow ( ) . as_class_sym ( ) . _model . as_ref ( ) . unwrap ( ) . name . clone ( ) ;
51
52
match session. sync_odoo . models . get ( & model_name) . cloned ( ) {
52
- Some ( model) => model. borrow_mut ( ) . add_symbol ( session, sym. clone ( ) ) ,
53
+ Some ( model) => {
54
+ let inherited_model_names = sym. borrow ( ) . as_class_sym ( ) . _model . as_ref ( ) . unwrap ( ) . inherit . clone ( ) ;
55
+ if !inherited_model_names. contains ( & model_name)
56
+ && !model. borrow ( ) . get_main_symbols ( session, sym. borrow ( ) . find_module ( ) ) . is_empty ( ) {
57
+ // This a model with a name that already exists in models and in dependencies,
58
+ // and it is not inherited, so it is basically shadowing the existing model.
59
+ let _name = sym. borrow ( ) . get_symbol ( & ( vec ! [ ] , vec ! [ Sy !( "_name" ) ] ) , u32:: MAX ) ;
60
+ if let Some ( _name) = _name. last ( ) {
61
+ let mut range = _name. borrow ( ) . range ( ) . clone ( ) ;
62
+ // Try to get the string value range, otherwise stick to _name var range.
63
+ if let Some ( eval_range) = _name. borrow ( ) . evaluations ( ) . unwrap ( ) . iter ( ) . find_map ( |e|
64
+ match e. follow_ref_and_get_value ( session, & mut None , & mut diagnostics) {
65
+ Some ( EvaluationValue :: CONSTANT ( Expr :: StringLiteral ( _) ) ) => e. range ,
66
+ _ => None ,
67
+ }
68
+ ) {
69
+ range = TextRange :: new ( range. start ( ) , eval_range. end ( ) ) ;
70
+ }
71
+ if let Some ( diagnostic) = create_diagnostic ( & session, DiagnosticCode :: OLS03020 , & [ & model_name] ) {
72
+ diagnostics. push ( Diagnostic {
73
+ range : FileMgr :: textRange_to_temporary_Range ( & range) ,
74
+ ..diagnostic
75
+ } ) ;
76
+ }
77
+ }
78
+ }
79
+ model. borrow_mut ( ) . add_symbol ( session, sym. clone ( ) )
80
+ } ,
53
81
None => {
54
82
let model = Model :: new ( model_name. clone ( ) , sym. clone ( ) ) ;
55
83
session. sync_odoo . modules . get ( "base" ) . map ( |module| {
0 commit comments