From dda3c7119dae8fed340f5a69545d9129ba069a33 Mon Sep 17 00:00:00 2001 From: Mitja Leino Date: Sat, 29 Jun 2024 11:26:30 +0300 Subject: [PATCH 1/4] Working implementation with coroutines --- src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt b/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt index 8564862b..7e127bc9 100644 --- a/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt +++ b/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt @@ -30,6 +30,7 @@ import com.intellij.openapi.editor.EditorFactory import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.fileEditor.impl.EditorHistoryManager import com.intellij.openapi.module.ModuleManager +import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.progress.ProgressManager import com.intellij.openapi.progress.Task @@ -48,9 +49,11 @@ import com.mituuz.fuzzier.components.FuzzyFinderComponent import com.mituuz.fuzzier.entities.FuzzyMatchContainer import com.mituuz.fuzzier.settings.FuzzierSettingsService import com.mituuz.fuzzier.settings.FuzzierSettingsService.RecentFilesMode.NONE +import kotlinx.coroutines.* import org.apache.commons.lang3.StringUtils import java.awt.event.* import javax.swing.* +import kotlin.coroutines.cancellation.CancellationException open class Fuzzier : FuzzyAction() { private var defaultDoc: Document? = null @@ -157,29 +160,38 @@ open class Fuzzier : FuzzyAction() { return } - currentTask?.takeIf { !it.isDone }?.cancel(true) - currentTask = ApplicationManager.getApplication().executeOnPooledThread { - component.fileList.setPaintBusy(true) - var listModel = DefaultListModel() + if (currentTask != null) { + println("Task is running, try to cancel") + currentTask!!.cancel() + } + currentTask = CoroutineScope(Dispatchers.IO).launch { + try { + component.fileList.setPaintBusy(true) + var listModel = DefaultListModel() - val stringEvaluator = StringEvaluator( - fuzzierSettingsService.state.exclusionSet, - fuzzierSettingsService.state.modules, - changeListManager - ) + val stringEvaluator = StringEvaluator( + fuzzierSettingsService.state.exclusionSet, + fuzzierSettingsService.state.modules, + changeListManager + ) + yield() - val moduleManager = ModuleManager.getInstance(project) - processModules(moduleManager, stringEvaluator, searchString, listModel) + val moduleManager = ModuleManager.getInstance(project) + processModules(moduleManager, stringEvaluator, searchString, listModel) - listModel = fuzzierUtil.sortAndLimit(listModel) + yield() + listModel = fuzzierUtil.sortAndLimit(listModel) - ApplicationManager.getApplication().invokeLater { - component.fileList.model = listModel - component.fileList.cellRenderer = getCellRenderer() - component.fileList.setPaintBusy(false) - if (!component.fileList.isEmpty) { - component.fileList.setSelectedValue(listModel[0], true) + ApplicationManager.getApplication().invokeLater { + component.fileList.model = listModel + component.fileList.cellRenderer = getCellRenderer() + component.fileList.setPaintBusy(false) + if (!component.fileList.isEmpty) { + component.fileList.setSelectedValue(listModel[0], true) + } } + } catch (e: CancellationException) { + // Do nothing } } } From fa82f83e6ab7d68e720cc5f5b916960de33fc542 Mon Sep 17 00:00:00 2001 From: Mitja Leino Date: Sat, 29 Jun 2024 11:47:15 +0300 Subject: [PATCH 2/4] Fix task cancellation and update minor version --- build.gradle.kts | 2 +- changelog.md | 3 ++ src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt | 20 ++++----- .../kotlin/com/mituuz/fuzzier/FuzzyMover.kt | 44 ++++++++++++------- src/main/resources/META-INF/plugin.xml | 2 + 5 files changed, 44 insertions(+), 27 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index aa7fea05..77f68a8b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "com.mituuz" -version = "0.25.0" +version = "0.25.1" repositories { mavenCentral() diff --git a/changelog.md b/changelog.md index bc28b130..afb5f2cb 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,7 @@ # Changelog +## Version 0.25.1 +- Fix task cancellation, making lower debounce time feel much better + ## Version 0.25.0 - Clear up settings grouping - Add option to highlight filename matches in the file list diff --git a/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt b/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt index 7e127bc9..d395f38c 100644 --- a/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt +++ b/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt @@ -30,7 +30,6 @@ import com.intellij.openapi.editor.EditorFactory import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.fileEditor.impl.EditorHistoryManager import com.intellij.openapi.module.ModuleManager -import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.progress.ProgressManager import com.intellij.openapi.progress.Task @@ -47,9 +46,7 @@ import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.openapi.wm.WindowManager import com.mituuz.fuzzier.components.FuzzyFinderComponent import com.mituuz.fuzzier.entities.FuzzyMatchContainer -import com.mituuz.fuzzier.settings.FuzzierSettingsService import com.mituuz.fuzzier.settings.FuzzierSettingsService.RecentFilesMode.NONE -import kotlinx.coroutines.* import org.apache.commons.lang3.StringUtils import java.awt.event.* import javax.swing.* @@ -160,12 +157,11 @@ open class Fuzzier : FuzzyAction() { return } - if (currentTask != null) { - println("Task is running, try to cancel") - currentTask!!.cancel() - } - currentTask = CoroutineScope(Dispatchers.IO).launch { + currentTask?.takeIf { !it.isDone }?.cancel(true) + currentTask = ApplicationManager.getApplication().executeOnPooledThread { try { + // Create a reference to the current task to check if it has been cancelled + val task = currentTask component.fileList.setPaintBusy(true) var listModel = DefaultListModel() @@ -174,14 +170,18 @@ open class Fuzzier : FuzzyAction() { fuzzierSettingsService.state.modules, changeListManager ) - yield() + + if (task?.isCancelled == true) throw CancellationException() val moduleManager = ModuleManager.getInstance(project) processModules(moduleManager, stringEvaluator, searchString, listModel) - yield() + if (task?.isCancelled == true) throw CancellationException() + listModel = fuzzierUtil.sortAndLimit(listModel) + if (task?.isCancelled == true) throw CancellationException() + ApplicationManager.getApplication().invokeLater { component.fileList.model = listModel component.fileList.cellRenderer = getCellRenderer() diff --git a/src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt b/src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt index a9573d82..af72029b 100644 --- a/src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt +++ b/src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt @@ -51,6 +51,7 @@ import org.apache.commons.lang3.StringUtils import java.awt.event.* import java.util.concurrent.CompletableFuture import javax.swing.* +import kotlin.coroutines.cancellation.CancellationException class FuzzyMover : FuzzyAction() { private val dimensionKey: String = "FuzzyMoverPopup" @@ -194,28 +195,39 @@ class FuzzyMover : FuzzyAction() { } currentTask?.takeIf { !it.isDone }?.cancel(true) - currentTask = ApplicationManager.getApplication().executeOnPooledThread { - component.fileList.setPaintBusy(true) - var listModel = DefaultListModel() + try { + // Create a reference to the current task to check if it has been cancelled + val task = currentTask + component.fileList.setPaintBusy(true) + var listModel = DefaultListModel() - val stringEvaluator = StringEvaluator( - fuzzierSettingsService.state.exclusionSet, - fuzzierSettingsService.state.modules - ) + val stringEvaluator = StringEvaluator( + fuzzierSettingsService.state.exclusionSet, + fuzzierSettingsService.state.modules + ) - val moduleManager = ModuleManager.getInstance(project) - processModules(moduleManager, stringEvaluator, searchString, listModel) + if (task?.isCancelled == true) throw CancellationException() - listModel = fuzzierUtil.sortAndLimit(listModel, true) + val moduleManager = ModuleManager.getInstance(project) + processModules(moduleManager, stringEvaluator, searchString, listModel) - ApplicationManager.getApplication().invokeLater { - component.fileList.model = listModel - component.fileList.cellRenderer = getCellRenderer() - component.fileList.setPaintBusy(false) - if (!component.fileList.isEmpty) { - component.fileList.setSelectedValue(listModel[0], true) + if (task?.isCancelled == true) throw CancellationException() + + listModel = fuzzierUtil.sortAndLimit(listModel, true) + + if (task?.isCancelled == true) throw CancellationException() + + ApplicationManager.getApplication().invokeLater { + component.fileList.model = listModel + component.fileList.cellRenderer = getCellRenderer() + component.fileList.setPaintBusy(false) + if (!component.fileList.isEmpty) { + component.fileList.setSelectedValue(listModel[0], true) + } } + } catch (e: CancellationException) { + // Do nothing } } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index d27e0704..58a54585 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -29,6 +29,8 @@ Version 0.25.1 + - Fix task cancellation, making lower debounce time feel much better

Version 0.25.0

- Clear up settings grouping
- Add option to highlight filename matches in the file list
From 1d5c702afbbd11270c0f6cf5617988518b5010c3 Mon Sep 17 00:00:00 2001 From: Mitja Leino Date: Sat, 29 Jun 2024 11:54:29 +0300 Subject: [PATCH 3/4] Lower the default debounce period --- changelog.md | 1 + .../com/mituuz/fuzzier/settings/FuzzierSettingsService.kt | 2 +- src/main/resources/META-INF/plugin.xml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index afb5f2cb..3d3085df 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,7 @@ # Changelog ## Version 0.25.1 - Fix task cancellation, making lower debounce time feel much better +- Lower default debounce time ## Version 0.25.0 - Clear up settings grouping diff --git a/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt b/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt index 66a3264c..2567f62b 100644 --- a/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt +++ b/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt @@ -43,7 +43,7 @@ class FuzzierSettingsService : PersistentStateComponent = setOf("/.idea/*", "/.git/*", "/target/*", "/build/*", "/.gradle/*", "/.run/*") var newTab: Boolean = false var prioritizeShorterDirPaths = true - var debouncePeriod: Int = 150 + var debouncePeriod: Int = 50 var resetWindow = false var fileListLimit: Int = 50 diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 58a54585..e9c1f422 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -31,6 +31,7 @@ Version 0.25.1 - Fix task cancellation, making lower debounce time feel much better
+ - Lower default debounce time

Version 0.25.0

- Clear up settings grouping
- Add option to highlight filename matches in the file list
From e53ec28008ffe22528079a81f09c12d7c516dc7a Mon Sep 17 00:00:00 2001 From: Mitja Leino Date: Sat, 29 Jun 2024 11:57:00 +0300 Subject: [PATCH 4/4] Halve the default debounce time --- .../com/mituuz/fuzzier/settings/FuzzierSettingsService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt b/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt index 2567f62b..f08ab224 100644 --- a/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt +++ b/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt @@ -43,7 +43,7 @@ class FuzzierSettingsService : PersistentStateComponent = setOf("/.idea/*", "/.git/*", "/target/*", "/build/*", "/.gradle/*", "/.run/*") var newTab: Boolean = false var prioritizeShorterDirPaths = true - var debouncePeriod: Int = 50 + var debouncePeriod: Int = 80 var resetWindow = false var fileListLimit: Int = 50