|
| 1 | +use itertools::Itertools; |
| 2 | +use itertools::FoldWhile::{Continue, Done}; |
1 | 3 | use ruff_python_ast::{Arguments, Expr, ExprCall, Identifier, Number, Operator, Parameter, UnaryOp}; |
2 | 4 | use ruff_text_size::{Ranged, TextRange, TextSize}; |
3 | 5 | use lsp_types::{Diagnostic, Position, Range}; |
@@ -784,6 +786,7 @@ impl Evaluation { |
784 | 786 |
|
785 | 787 | let mut call_argument_diagnostics = Vec::new(); |
786 | 788 | for base_eval_ptr in base_eval_ptrs.iter() { |
| 789 | + call_argument_diagnostics.push(Vec::new()); //one list per evaluation |
787 | 790 | let EvaluationSymbolPtr::WEAK(base_sym_weak_eval) = base_eval_ptr else {continue}; |
788 | 791 | let Some(base_sym) = base_sym_weak_eval.weak.upgrade() else {continue}; |
789 | 792 | if base_sym.borrow().typ() == SymType::CLASS { |
@@ -994,7 +997,7 @@ impl Evaluation { |
994 | 997 | }; |
995 | 998 | if is_in_validation { |
996 | 999 | let on_instance = base_sym_weak_eval.context.get(&S!("is_attr_of_instance")).map(|v| v.as_bool()); |
997 | | - call_argument_diagnostics.extend(Evaluation::validate_call_arguments(session, |
| 1000 | + call_argument_diagnostics.last_mut().unwrap().extend(Evaluation::validate_call_arguments(session, |
998 | 1001 | &base_sym.borrow().as_func(), |
999 | 1002 | expr, |
1000 | 1003 | call_parent.clone(), |
@@ -1458,33 +1461,52 @@ impl Evaluation { |
1458 | 1461 | diagnostics |
1459 | 1462 | } |
1460 | 1463 |
|
1461 | | - fn process_argument_diagnostics(session: &SessionInfo, expr_call: &ExprCall, diagnostics: Vec<Diagnostic>, eval_count: usize) -> Vec<Diagnostic> { |
| 1464 | + fn process_argument_diagnostics(session: &SessionInfo, expr_call: &ExprCall, diagnostics: Vec<Vec<Diagnostic>>, eval_count: usize) -> Vec<Diagnostic> { |
1462 | 1465 | let mut filtered_diagnostics = vec![]; |
1463 | | - let mut arg_diagnostic = diagnostics.iter().filter(|d| |
1464 | | - d.code == Some(lsp_types::NumberOrString::String(DiagnosticCode::OLS01007.to_string())) || |
1465 | | - d.code == Some(lsp_types::NumberOrString::String(DiagnosticCode::OLS01008.to_string())) |
1466 | | - ); |
1467 | | - let arg_diagnostic_count = arg_diagnostic.clone().count(); |
1468 | | - if arg_diagnostic_count > 0 { |
1469 | | - if arg_diagnostic_count == eval_count { |
1470 | | - // if all evaluations have some argument error, we keep the first one |
1471 | | - filtered_diagnostics.push(arg_diagnostic.next().unwrap().clone()); |
1472 | | - } else { |
1473 | | - // if not all evaluations have it, it means at least one is valid. |
1474 | | - // We use a different code warning |
| 1466 | + //iter through diagnostics and check that each evaluation has the same amount of diagnostics with code OLS01007 or OLS01008 or OLS01010 |
| 1467 | + let all_same_issues = diagnostics.iter().fold_while(None, |acc, diags| { |
| 1468 | + let new_count = diags.iter().filter(|d| |
| 1469 | + d.code == Some(lsp_types::NumberOrString::String(DiagnosticCode::OLS01007.to_string())) || |
| 1470 | + d.code == Some(lsp_types::NumberOrString::String(DiagnosticCode::OLS01008.to_string())) || |
| 1471 | + d.code == Some(lsp_types::NumberOrString::String(DiagnosticCode::OLS01010.to_string())) |
| 1472 | + ).count() as i32; |
| 1473 | + match acc { |
| 1474 | + None => Continue(Some(new_count)), |
| 1475 | + Some(count) => { |
| 1476 | + if count == new_count { |
| 1477 | + Continue(Some(count)) |
| 1478 | + } else { |
| 1479 | + Done(Some(-1)) |
| 1480 | + } |
| 1481 | + } |
| 1482 | + } |
| 1483 | + }).into_inner(); |
| 1484 | + match all_same_issues { |
| 1485 | + Some(-1) => { |
1475 | 1486 | if let Some(diagnostic) = create_diagnostic(session, DiagnosticCode::OLS01009, &[]) { |
1476 | 1487 | filtered_diagnostics.push(Diagnostic { |
1477 | 1488 | range: Range::new(Position::new(expr_call.range().start().to_u32(), 0), Position::new(expr_call.range().end().to_u32(), 0)), |
1478 | 1489 | ..diagnostic |
1479 | 1490 | }); |
1480 | 1491 | } |
1481 | | - } |
| 1492 | + }, |
| 1493 | + Some(_count) => { |
| 1494 | + filtered_diagnostics.extend(diagnostics[0].iter().filter(|d| |
| 1495 | + d.code == Some(lsp_types::NumberOrString::String(DiagnosticCode::OLS01007.to_string())) || |
| 1496 | + d.code == Some(lsp_types::NumberOrString::String(DiagnosticCode::OLS01008.to_string())) || |
| 1497 | + d.code == Some(lsp_types::NumberOrString::String(DiagnosticCode::OLS01010.to_string())) |
| 1498 | + ).cloned().collect::<Vec<Diagnostic>>()); |
| 1499 | + }, |
| 1500 | + None => {} |
| 1501 | + } |
| 1502 | + // // we add the rest of the diagnostics as is |
| 1503 | + for eval_diag in diagnostics { |
| 1504 | + filtered_diagnostics.extend(eval_diag.into_iter().filter(|d| { |
| 1505 | + d.code != Some(lsp_types::NumberOrString::String(DiagnosticCode::OLS01007.to_string())) && |
| 1506 | + d.code != Some(lsp_types::NumberOrString::String(DiagnosticCode::OLS01008.to_string())) && |
| 1507 | + d.code != Some(lsp_types::NumberOrString::String(DiagnosticCode::OLS01010.to_string())) |
| 1508 | + })); |
1482 | 1509 | } |
1483 | | - // we add the rest of the diagnostics as is |
1484 | | - filtered_diagnostics.extend(diagnostics.into_iter().filter(|d| { |
1485 | | - d.code != Some(lsp_types::NumberOrString::String(DiagnosticCode::OLS01007.to_string())) && |
1486 | | - d.code != Some(lsp_types::NumberOrString::String(DiagnosticCode::OLS01008.to_string())) |
1487 | | - })); |
1488 | 1510 | filtered_diagnostics |
1489 | 1511 | } |
1490 | 1512 |
|
|
0 commit comments