Skip to content

Commit

Permalink
only shows option for clj files & works for cljc/cljs
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ajensen committed Apr 25, 2024
1 parent f874afa commit 5e413ae
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .idea/artifacts/spec_mate.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion src/main/kotlin/io/sajensen/specmate/GoToTestAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile

class GoToTestAction : AnAction("Test") {

Expand All @@ -13,7 +14,7 @@ class GoToTestAction : AnAction("Test") {
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 testFilePath = getSpecPath(currentFile)
val testFile = LocalFileSystem.getInstance().findFileByPath(testFilePath)

if (testFile != null) {
Expand All @@ -28,4 +29,20 @@ class GoToTestAction : AnAction("Test") {
}
}
}

private fun getSpecPath(file: VirtualFile): String {
val basePath = file.path.replaceFirst("src", "spec").substringBeforeLast(".")
val extension = file.extension
return basePath.plus("_spec.").plus(extension)
}

override fun update(e: AnActionEvent) {
super.update(e)

val project = e.project
val file = e.getData(com.intellij.openapi.actionSystem.CommonDataKeys.VIRTUAL_FILE)
val isClojureFile = file?.extension in listOf("clj", "cljc", "cljs")

e.presentation.isEnabledAndVisible = project != null && isClojureFile
}
}

0 comments on commit 5e413ae

Please sign in to comment.