From e2403d2aba144c3ee8ebadf245d5db100f976e3d Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Fri, 5 Apr 2024 02:03:48 -0700 Subject: [PATCH] diagnostic descriptor: slow_functions Summary: As title Reviewed By: robertoaloi Differential Revision: D55737827 fbshipit-source-id: 226b29e11a0efbca4c4cc576d20929d58229a4b6 --- crates/ide/src/diagnostics.rs | 2 +- crates/ide/src/diagnostics/slow_functions.rs | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 11c393d330..556abba850 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs @@ -569,6 +569,7 @@ pub fn diagnostics_descriptors<'a>() -> Vec<&'a DiagnosticDescriptor<'a>> { &missing_separator::DESCRIPTOR, &deprecated_function::DESCRIPTOR, &dependent_header::DESCRIPTOR, + &slow_functions::DESCRIPTOR, ] } @@ -666,7 +667,6 @@ pub fn semantic_diagnostics( expression_can_be_simplified::diagnostic(res, sema, file_id); application_env::application_env(res, sema, file_id); missing_compile_warn_missing_spec::missing_compile_warn_missing_spec(res, sema, file_id); - slow_functions::slow_functions(res, sema, file_id); } } diff --git a/crates/ide/src/diagnostics/slow_functions.rs b/crates/ide/src/diagnostics/slow_functions.rs index eb3f3447a8..3eb61d9c2b 100644 --- a/crates/ide/src/diagnostics/slow_functions.rs +++ b/crates/ide/src/diagnostics/slow_functions.rs @@ -18,16 +18,25 @@ use lazy_static::lazy_static; use super::helpers::check_used_functions; use super::helpers::DiagnosticTemplate; use super::Diagnostic; +use super::DiagnosticConditions; +use super::DiagnosticDescriptor; use crate::codemod_helpers::FunctionMatch; use crate::diagnostics::helpers::FunctionCallDiagnostic; use crate::diagnostics::DiagnosticCode; use crate::diagnostics::Severity; -pub(crate) fn slow_functions(diags: &mut Vec, sema: &Semantic, file_id: FileId) { - if sema.db.is_generated(file_id) || Some(true) == sema.db.is_test_suite_or_test_helper(file_id) - { - return; - } +pub(crate) static DESCRIPTOR: DiagnosticDescriptor = DiagnosticDescriptor { + conditions: DiagnosticConditions { + experimental: false, + include_generated: false, + include_tests: false, + }, + checker: &|diags, sema, file_id, _ext| { + slow_functions(diags, sema, file_id); + }, +}; + +fn slow_functions(diags: &mut Vec, sema: &Semantic, file_id: FileId) { check_used_functions(sema, file_id, &USED_FUNCTIONS, diags); }