Skip to content

Commit b2000f4

Browse files
committed
[IMP] server: improve inherit diagnostics
1 parent fa8ec4a commit b2000f4

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

server/error_code.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ You should check the dependencies in the \_\_manifest\_\_.py file of your module
8888
The declared model is specifying an inheritance to a model that is not declared in the visible modules by the current one.
8989
Consider updating the manifest of your module to include the relevant module.
9090

91+
### OLS30105
92+
93+
"This model is inherited, but never declared."
94+
95+
The extension found some classes inheriting this model, but didn't find any class that declare it first, with only a _name.
96+
9197
### OLS30201
9298

9399
"A manifest shoul only contains one dictionnary".

server/src/core/python_arch_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl PythonArchEval {
419419
}
420420
let eval_base = &eval_base[0];
421421
let eval_symbol = eval_base.symbol.get_symbol(session, &mut None, &mut vec![], None);
422-
let ref_sym = Symbol::follow_ref(&eval_symbol, session, &mut None, true, false, None, &mut vec![]);
422+
let ref_sym = Symbol::follow_ref(&eval_symbol, session, &mut None, false, false, None, &mut vec![]);
423423
if ref_sym.len() > 1 {
424424
self.diagnostics.push(Diagnostic::new(
425425
Range::new(Position::new(base.range().start().to_u32(), 0), Position::new(base.range().end().to_u32(), 0)),

server/src/core/python_arch_eval_hooks.rs

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -435,36 +435,57 @@ impl PythonArchEvalHooks {
435435
let mut f = file_symbol.borrow_mut();
436436
f.add_model_dependencies(model);
437437
}
438-
let symbols = model.clone().borrow().get_main_symbols(session, from_module.clone(), &mut None);
438+
let model = model.clone();
439+
let model = model.borrow();
440+
let symbols = model.get_main_symbols(session, from_module.clone(), &mut None);
439441
if !symbols.is_empty() {
440442
for s in symbols.iter() {
441443
if from_module.is_none() || ModuleSymbol::is_in_deps(session, &from_module.as_ref().unwrap(),&s.borrow().find_module().unwrap().borrow().as_module_package().dir_name, &mut None) {
442444
return EvaluationSymbolWeak::new(Rc::downgrade(s), Some(true), false);
443445
}
444446
}
445-
//still here? If from module is set, dependencies are not met
447+
} else {
446448
if from_module.is_some() {
449+
//retry without from_module to see if model exists elsewhere
450+
let symbols = model.get_main_symbols(session, None, &mut None);
451+
if symbols.is_empty() {
452+
let range = FileMgr::textRange_to_temporary_Range(&context.get(&S!("range")).unwrap().as_text_range());
453+
diagnostics.push(Diagnostic::new(range,
454+
Some(DiagnosticSeverity::ERROR),
455+
Some(NumberOrString::String(S!("OLS30105"))),
456+
Some(EXTENSION_NAME.to_string()),
457+
S!("This model is inherited, but never declared."),
458+
None,
459+
None
460+
)
461+
);
462+
} else {
463+
let range = FileMgr::textRange_to_temporary_Range(&context.get(&S!("range")).unwrap().as_text_range());
464+
let valid_modules: Vec<String> = symbols.iter().map(|s| match s.borrow().find_module() {
465+
Some(sym) => sym.borrow().name().clone(),
466+
None => S!("Unknown").clone()
467+
}).collect();
468+
diagnostics.push(Diagnostic::new(range,
469+
Some(DiagnosticSeverity::ERROR),
470+
Some(NumberOrString::String(S!("OLS30101"))),
471+
Some(EXTENSION_NAME.to_string()),
472+
format!("This model is not declared in the dependencies of your module. You should consider adding one of the following dependency: {:?}", valid_modules),
473+
None,
474+
None
475+
)
476+
);
477+
}
478+
} else {
447479
let range = FileMgr::textRange_to_temporary_Range(&context.get(&S!("range")).unwrap().as_text_range());
448480
diagnostics.push(Diagnostic::new(range,
449481
Some(DiagnosticSeverity::ERROR),
450-
Some(NumberOrString::String(S!("OLS30101"))),
482+
Some(NumberOrString::String(S!("OLS30102"))),
451483
Some(EXTENSION_NAME.to_string()),
452-
S!("This model is not in the dependencies of your module."),
484+
S!("Unknown model. Check your addons path"),
453485
None,
454486
None
455-
)
456-
);
487+
));
457488
}
458-
} else {
459-
let range = FileMgr::textRange_to_temporary_Range(&context.get(&S!("range")).unwrap().as_text_range());
460-
diagnostics.push(Diagnostic::new(range,
461-
Some(DiagnosticSeverity::ERROR),
462-
Some(NumberOrString::String(S!("OLS30102"))),
463-
Some(EXTENSION_NAME.to_string()),
464-
S!("Unknown model. Check your addons path"),
465-
None,
466-
None
467-
));
468489
}
469490
} else {
470491
let range = FileMgr::textRange_to_temporary_Range(&context.get(&S!("range")).unwrap().as_text_range());

0 commit comments

Comments
 (0)