From baae18ecd03ee7a81f8b76e5cc0bebdd496b8194 Mon Sep 17 00:00:00 2001 From: thelooter Date: Fri, 20 Dec 2024 23:21:46 +0100 Subject: [PATCH] Simplify package.json filtering logic. Removed redundant filtering of hidden parent directories in ISPPanelPopulator and moved it to the FileManager helper. This centralizes the logic, reduces duplication, and ensures consistent file filtering throughout the codebase. --- .../intellijshadcnplugin/backend/helpers/FileManager.kt | 4 +++- .../intellijshadcnplugin/ui/ISPPanelPopulator.kt | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/helpers/FileManager.kt b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/helpers/FileManager.kt index 7adec6d..1c58f63 100644 --- a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/helpers/FileManager.kt +++ b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/backend/helpers/FileManager.kt @@ -83,7 +83,9 @@ class FileManager(private val project: Project) { ) } }).filter { file -> - !file.path.contains("/node_modules/") && !file.path.contains("/.git/") + !file.path.contains("/node_modules/") + && !file.path.contains("/.git/") + && !file.parent.name.startsWith('.') }.sortedBy { file -> name.toRegex().find(file.path)?.range?.first ?: Int.MAX_VALUE }.also { diff --git a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/ui/ISPPanelPopulator.kt b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/ui/ISPPanelPopulator.kt index 461bf7e..ca4d55e 100644 --- a/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/ui/ISPPanelPopulator.kt +++ b/src/main/kotlin/com/github/warningimhack3r/intellijshadcnplugin/ui/ISPPanelPopulator.kt @@ -23,8 +23,7 @@ class ISPPanelPopulator(private val project: Project) { CoroutineScope(SupervisorJob() + Dispatchers.Default).async { return@async Pair( SourceScanner.findShadcnImplementation(project), - FileManager.getInstance(project).getVirtualFilesByName("package.json") - .filter { !it.parent.name.startsWith('.') }.size + FileManager.getInstance(project).getVirtualFilesByName("package.json").size ) }.asCompletableFuture().thenApplyAsync { (source, packageJsonCount) -> log.info("Shadcn implementation detected: $source, package.json count: $packageJsonCount")