Skip to content

Commit

Permalink
goes to corresponding speclj test
Browse files Browse the repository at this point in the history
s-ajensen committed Apr 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e950714 commit f874afa
Showing 2 changed files with 37 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/main/kotlin/io/sajensen/specmate/GoToTestAction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.sajensen.specmate

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.vfs.LocalFileSystem

class GoToTestAction : AnAction("Test") {

override fun actionPerformed(e: AnActionEvent) {
val project = e.project
val currentFile = e.getData(com.intellij.openapi.actionSystem.CommonDataKeys.VIRTUAL_FILE)

if (project != null && currentFile != null) {
val testFilePath = currentFile.path.replaceFirst("src", "spec").replace(".clj", "_spec.clj")
val testFile = LocalFileSystem.getInstance().findFileByPath(testFilePath)

if (testFile != null) {
FileEditorManager.getInstance(project).openFile(testFile, true)
} else {
Messages.showMessageDialog(
project,
"Test file not found: $testFilePath",
"File Not Found",
Messages.getInformationIcon()
)
}
}
}
}
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -24,4 +24,10 @@
<extensions defaultExtensionNs="com.intellij">

</extensions>
<actions>
<action id="io.sajensen.specmate.GoToTestAction" class="io.sajensen.specmate.GoToTestAction" text="Test"
description="Opens the corresponding speclj test file for file">
<add-to-group group-id="EditorPopupMenu.GoTo" anchor="last"/>
</action>
</actions>
</idea-plugin>

0 comments on commit f874afa

Please sign in to comment.