@@ -26,14 +26,10 @@ package com.mituuz.fuzzier.actions.filesystem
2626
2727import com.intellij.openapi.actionSystem.AnActionEvent
2828import com.intellij.openapi.application.EDT
29- import com.intellij.openapi.module.ModuleManager
3029import com.intellij.openapi.project.Project
31- import com.intellij.openapi.project.rootManager
32- import com.intellij.openapi.roots.ProjectFileIndex
3330import com.intellij.openapi.vfs.VirtualFile
3431import com.mituuz.fuzzier.actions.FuzzyAction
3532import com.mituuz.fuzzier.entities.*
36- import com.mituuz.fuzzier.intellij.iteration.IntelliJIterationFileCollector
3733import com.mituuz.fuzzier.intellij.iteration.IterationFileCollector
3834import com.mituuz.fuzzier.util.FuzzierUtil
3935import kotlinx.coroutines.*
@@ -43,11 +39,10 @@ import java.util.concurrent.ConcurrentHashMap
4339import javax.swing.DefaultListModel
4440
4541abstract class FilesystemAction : FuzzyAction () {
46- private var collector : IterationFileCollector = IntelliJIterationFileCollector ()
42+ abstract fun createCollector () : IterationFileCollector
4743
4844 abstract override fun runAction (
49- project : Project ,
50- actionEvent : AnActionEvent
45+ project : Project , actionEvent : AnActionEvent
5146 )
5247
5348 abstract fun buildFileFilter (project : Project ): (VirtualFile ) -> Boolean
@@ -58,17 +53,9 @@ abstract class FilesystemAction : FuzzyAction() {
5853 val ctx = currentCoroutineContext()
5954 val job = ctx.job
6055
61- val indexTargets = if (projectState.isProject) {
62- listOf (ProjectFileIndex .getInstance(project) to project.name)
63- } else {
64- val moduleManager = ModuleManager .getInstance(project)
65- moduleManager.modules.map { it.rootManager.fileIndex to it.name }
66- }
67-
68- return collector.collectFiles(
69- targets = indexTargets,
70- shouldContinue = { job.isActive },
71- fileFilter = buildFileFilter(project)
56+ val c: IterationFileCollector = createCollector()
57+ return c.collectFiles(
58+ project = project, shouldContinue = { job.isActive }, fileFilter = buildFileFilter(project)
7259 )
7360 }
7461
@@ -99,9 +86,7 @@ abstract class FilesystemAction : FuzzyAction() {
9986 val processedFiles = ConcurrentHashMap .newKeySet<String >()
10087 val listLimit = fileListLimit
10188 val priorityQueue = PriorityQueue (
102- listLimit + 1 ,
103- compareBy<FuzzyMatchContainer > { it.getScore(prioritizeShorterDirPaths) }
104- )
89+ listLimit + 1 , compareBy<FuzzyMatchContainer > { it.getScore(prioritizeShorterDirPaths) })
10590
10691 val queueLock = Any ()
10792 var minimumScore: Int? = null
@@ -139,9 +124,7 @@ abstract class FilesystemAction : FuzzyAction() {
139124 }
140125 }
141126
142- fileEntries
143- .filter { processedFiles.add(it.path) }
144- .forEach { ch.send(it) }
127+ fileEntries.filter { processedFiles.add(it.path) }.forEach { ch.send(it) }
145128 ch.close()
146129 }
147130
0 commit comments