Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 5 additions & 69 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

// Use the same version and group for the jar and the plugin
val currentVersion = "2.0.1"
val currentVersion = "2.1.0"
val myGroup = "com.mituuz"
version = currentVersion
group = myGroup
Expand All @@ -40,78 +40,14 @@ intellijPlatform {
changeNotes = """
<h2>Version $currentVersion</h2>
<ul>
<li>Fix incorrect <code>grep</code> command</li>
<li>Partially fix <code>findstr</code> command</li>
<li>Re-add the backend name to the popup title</li>
</ul>
<h3>Known issues</h3>
<ul>
<li><code>findstr</code> does not work with currently open tabs
<ul>
<li>To reduce the maintenance burden, I may remove support later</li>
<li>Performance is poor enough that I thought that the command wasn't returning any results</li>
</ul>
</li>
</ul>
<h2>Version 2.0.0</h2>
<p>This version contains larger refactors and multiple new actions enabled by them.</p>
<p>I&#39;m updating the existing package structure to keep things nicer and not supporting the old actions to avoid possible problems in the future.</p>

<h3>Breaking changes</h3>
<p><strong>Rename existing actions</strong></p>
<ul>
<li><code>com.mituuz.fuzzier.FuzzyGrepCaseInsensitive</code> to <code>com.mituuz.fuzzier.grep.FuzzyGrepCI</code></li>
<li><code>com.mituuz.fuzzier.FuzzyGrep</code> to <code>com.mituuz.fuzzier.grep.FuzzyGrep</code></li>
<li><code>com.mituuz.fuzzier.Fuzzier</code> to <code>com.mituuz.fuzzier.search.Fuzzier</code></li>
<li><code>com.mituuz.fuzzier.FuzzierVCS</code> to <code>com.mituuz.fuzzier.search.FuzzierVCS</code></li>
<li><code>com.mituuz.fuzzier.FuzzyMover</code> to <code>com.mituuz.fuzzier.operation.FuzzyMover</code></li>
</ul>
<p><strong>Update default list movement keys</strong></p>
<ul>
<li>From <code>CTRL + j</code> and <code>CTRL + k</code> to <code>CTRL + n</code> and <code>CTRL + p</code></li>
</ul>

<h3>New actions</h3>
<p>Added some new grep variations</p>
<pre><code>com.mituuz.fuzzier.grep.FuzzyGrepOpenTabsCI
com.mituuz.fuzzier.grep.FuzzyGrepOpenTabs
com.mituuz.fuzzier.grep.FuzzyGrepCurrentBufferCI
com.mituuz.fuzzier.grep.FuzzyGrepCurrentBuffer</code></pre>

<h3>Example mappings</h3>
<pre><code>&quot; File search
nmap &lt;Leader&gt;sf &lt;action&gt;(com.mituuz.fuzzier.search.Fuzzier)
nmap &lt;Leader&gt;sg &lt;action&gt;(com.mituuz.fuzzier.search.FuzzierVCS)

&quot; Mover
nmap &lt;Leader&gt;fm &lt;action&gt;(com.mituuz.fuzzier.operation.FuzzyMover)

&quot; Grepping
nmap &lt;Leader&gt;ss &lt;action&gt;(com.mituuz.fuzzier.grep.FuzzyGrepCI)
nmap &lt;Leader&gt;sS &lt;action&gt;(com.mituuz.fuzzier.grep.FuzzyGrep)
nmap &lt;Leader&gt;st &lt;action&gt;(com.mituuz.fuzzier.grep.FuzzyGrepOpenTabsCI)
nmap &lt;Leader&gt;sT &lt;action&gt;(com.mituuz.fuzzier.grep.FuzzyGrepOpenTabs)
nmap &lt;Leader&gt;sb &lt;action&gt;(com.mituuz.fuzzier.grep.FuzzyGrepCurrentBufferCI)
nmap &lt;Leader&gt;sB &lt;action&gt;(com.mituuz.fuzzier.grep.FuzzyGrepCurrentBuffer)</code></pre>

<h3>New features</h3>
<ul>
<li>Popup now defaults to auto-sized, which scales with the current window</li>
<li>You can revert this from the settings</li>
</ul>

<h3>Other changes</h3>
<ul>
<li>Refactor file search to use coroutines
<li>Add built-in Fuzzier grep backend
<ul>
<li>Handle list size limiting during processing instead of doing them separately</li>
<li>Replaces <code>grep</code> and <code>findstr</code> fallback implementations</li>
<li>Add setting to choose between Dynamic (uses <code>rg</code> if available, otherwise Fuzzier) and Fuzzier backends</li>
</ul>
</li>
<li>Add debouncing for file preview using <code>SingleAlarm</code></li>
<li>Refactor everything</li>
<li>Remove manual handling of the divider location (use JBSplitter instead) and unify styling</li>
<li>Migrate from <code>Timer</code> to coroutines for debouncing</li>
</ul>

""".trimIndent()

ideaVersion {
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Version 2.1.0

- Add a built-in Fuzzier grep backend
- Replaces `grep` and `findstr` fallback implementations
- Add setting to choose between Dynamic (uses `rg` if available, otherwise Fuzzier) and Fuzzier backends
- Migrate from `Timer` to coroutines for debouncing

## Version 2.0.1

- Fix incorrect `grep` command
Expand Down
25 changes: 15 additions & 10 deletions src/main/kotlin/com/mituuz/fuzzier/actions/FuzzyAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,15 @@ import kotlinx.coroutines.*
import java.awt.Component
import java.awt.Font
import java.awt.event.ActionEvent
import java.util.*
import java.util.Timer
import java.util.concurrent.ConcurrentHashMap
import javax.swing.*
import kotlin.concurrent.schedule

abstract class FuzzyAction : AnAction() {
lateinit var component: FuzzyComponent
lateinit var popup: JBPopup
private lateinit var originalDownHandler: EditorActionHandler
private lateinit var originalUpHandler: EditorActionHandler
private var debounceTimer: TimerTask? = null
private var originalDownHandler: EditorActionHandler? = null
private var originalUpHandler: EditorActionHandler? = null
private var debounceJob: Job? = null
protected lateinit var projectState: FuzzierSettingsService.State
protected val globalState = service<FuzzierGlobalSettingsService>().state
protected var defaultDoc: Document? = null
Expand Down Expand Up @@ -138,9 +135,10 @@ abstract class FuzzyAction : AnAction() {
val document = component.searchField.document
val listener: DocumentListener = object : DocumentListener {
override fun documentChanged(event: DocumentEvent) {
debounceTimer?.cancel()
debounceJob?.cancel()
val debouncePeriod = globalState.debouncePeriod
debounceTimer = Timer().schedule(debouncePeriod.toLong()) {
debounceJob = actionScope?.launch {
delay(debouncePeriod.toLong())
updateListContents(project, component.searchField.text)
}
}
Expand All @@ -161,6 +159,9 @@ abstract class FuzzyAction : AnAction() {
fun cleanupPopup() {
resetOriginalHandlers()

debounceJob?.cancel()
debounceJob = null

currentUpdateListContentJob?.cancel()
currentUpdateListContentJob = null

Expand All @@ -180,8 +181,12 @@ abstract class FuzzyAction : AnAction() {

fun resetOriginalHandlers() {
val actionManager = EditorActionManager.getInstance()
actionManager.setActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN, originalDownHandler)
actionManager.setActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP, originalUpHandler)
originalDownHandler?.let {
actionManager.setActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN, it)
}
originalUpHandler?.let {
actionManager.setActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP, it)
}
}

class FuzzyListActionHandler(private val fuzzyAction: FuzzyAction, private val isUp: Boolean) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,26 @@ class FuzzierGlobalSettingsComponent(
JBCheckBox(), "Fuzzy Grep: Preview entire file",
"""
Toggles showing the full file in the preview.<br><br>

If set, preview will use full syntax highlighting.<br>
Otherwise, preview will only use limited syntax highlighting and show a slice around the match.<br><br>
Disabling this option may improve performance on very large files,

Disabling this option may improve performance on very large files,
for small-to-medium files the performance impact is negligible.
""".trimIndent(),
false
)

val grepBackendSelector = SettingsComponent(
ComboBox<GrepBackend>(), "Grep backend",
"""
Select which backend to use for Fuzzy Grep.<br><br>
<strong>Dynamic</strong>: Uses ripgrep (rg) if available, otherwise falls back to Fuzzier.<br>
<strong>Fuzzier</strong>: Uses the built-in Fuzzier backend.
""".trimIndent(),
false
)

val globalExclusionTextArea: JBTextArea = JBTextArea().apply {
rows = 5
lineWrap = true
Expand Down Expand Up @@ -328,6 +338,7 @@ class FuzzierGlobalSettingsComponent(
.addComponent(debounceTimerValue)
.addComponent(fileListLimit)
.addComponent(fuzzyGrepShowFullFile)
.addComponent(grepBackendSelector)
.addComponent(globalExclusionSet)

.addSeparator()
Expand Down Expand Up @@ -430,6 +441,25 @@ class FuzzierGlobalSettingsComponent(
popupSizingSelector.getPopupSizingComboBox().addItem(s)
}

grepBackendSelector.getGrepBackendComboBox().renderer = object : DefaultListCellRenderer() {
override fun getListCellRendererComponent(
list: JList<*>?,
value: Any?,
index: Int,
isSelected: Boolean,
cellHasFocus: Boolean
): Component {
val renderer =
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) as JLabel
val backend = value as GrepBackend
renderer.text = backend.text
return renderer
}
}
for (backend in GrepBackend.entries) {
grepBackendSelector.getGrepBackendComboBox().addItem(backend)
}

filenameTypeSelector.getFilenameTypeComboBox().renderer = object : DefaultListCellRenderer() {
override fun getListCellRendererComponent(
list: JList<*>?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ class SettingsComponent {
return component as ComboBox<PopupSizing>
}

fun getGrepBackendComboBox(): ComboBox<FuzzierGlobalSettingsService.GrepBackend> {
@Suppress("UNCHECKED_CAST")
return component as ComboBox<FuzzierGlobalSettingsService.GrepBackend>
}

fun getIntSpinner(index: Int): JBIntSpinner {
return (component as JPanel).getComponent(index) as JBIntSpinner
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ import java.util.concurrent.Future
import javax.swing.DefaultListModel
import javax.swing.JPanel
import javax.swing.table.DefaultTableModel
import kotlin.concurrent.schedule

class TestBenchComponent : JPanel(), Disposable {
private val columnNames =
arrayOf("Filename", "Filepath", "Streak", "MultiMatch", "PartialPath", "Filename", "Total")
private val table = JBTable()
private var searchField = EditorTextField()
private var debounceTimer: TimerTask? = null
private var debounceJob: Job? = null

@Volatile
var currentTask: Future<*>? = null
Expand Down Expand Up @@ -122,9 +121,10 @@ class TestBenchComponent : JPanel(), Disposable {
val document = searchField.document
val listener: DocumentListener = object : DocumentListener {
override fun documentChanged(event: DocumentEvent) {
debounceTimer?.cancel()
debounceJob?.cancel()
val debouncePeriod = liveSettingsComponent.debounceTimerValue.getIntSpinner().value as Int
debounceTimer = Timer().schedule(debouncePeriod.toLong()) {
debounceJob = actionScope.launch {
delay(debouncePeriod.toLong())
updateListContents(project, searchField.text)
}
}
Expand Down Expand Up @@ -199,14 +199,16 @@ class TestBenchComponent : JPanel(), Disposable {
}

override fun dispose() {
debounceTimer?.cancel()
debounceTimer = null
debounceJob?.cancel()
debounceJob = null

currentTask?.let { task ->
if (!task.isDone) task.cancel(true)
}
currentTask = null

actionScope.cancel()

ApplicationManager.getApplication().invokeLater {
try {
table.setPaintBusy(false)
Expand Down
54 changes: 30 additions & 24 deletions src/main/kotlin/com/mituuz/fuzzier/entities/FuzzyContainer.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
/*
MIT License

Copyright (c) 2025 Mitja Leino

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
* MIT License
*
* Copyright (c) 2025 Mitja Leino
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.mituuz.fuzzier.entities

import com.intellij.openapi.vfs.VirtualFile
import com.mituuz.fuzzier.settings.FuzzierGlobalSettingsService

abstract class FuzzyContainer(val filePath: String, val basePath: String, val filename: String) {
abstract class FuzzyContainer(
val filePath: String,
val basePath: String,
val filename: String,
val virtualFile: VirtualFile? = null,
) {
/**
* Get display string for the popup
*/
Expand All @@ -34,7 +40,7 @@ abstract class FuzzyContainer(val filePath: String, val basePath: String, val fi
/**
* Get the complete URI for the file
*/
fun getFileUri() : String {
fun getFileUri(): String {
return "$basePath$filePath"
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/com/mituuz/fuzzier/entities/GrepConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@

package com.mituuz.fuzzier.entities

import com.intellij.openapi.vfs.VirtualFile

enum class CaseMode {
SENSITIVE,
INSENSITIVE,
}

class GrepConfig(
val targets: List<String>,
val targets: Set<VirtualFile>?,
val caseMode: CaseMode,
val title: String = "",
val supportsSecondaryField: Boolean = true,
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/com/mituuz/fuzzier/entities/RowContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.mituuz.fuzzier.entities

import com.intellij.openapi.vfs.VirtualFile
import com.mituuz.fuzzier.settings.FuzzierGlobalSettingsService
import java.io.File

Expand All @@ -32,8 +33,9 @@ class RowContainer(
filename: String,
val rowNumber: Int,
val trimmedRow: String,
val columnNumber: Int = 0
) : FuzzyContainer(filePath, basePath, filename) {
val columnNumber: Int = 0,
virtualFile: VirtualFile? = null
) : FuzzyContainer(filePath, basePath, filename, virtualFile) {
companion object {
private val FILE_SEPARATOR: String = File.separator
private val RG_PATTERN: Regex = Regex("""^.+:\d+:\d+:\s*.+$""")
Expand Down
Loading