Skip to content

Commit

Permalink
fix: Don't run on each file save (#10)
Browse files Browse the repository at this point in the history
Only run infracost when the file that is update is a terraform file
  • Loading branch information
owenrumney authored Jul 2, 2024
1 parent deb133e commit 96d5eaa
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.intellij.openapi.vfs.newvfs.BulkFileListener
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
import io.infracost.plugins.infracost.actions.RunInfracostAction

val INFRACOST_FILE_EXTENSIONS = setOf("tf", "hcl", "tfvars")
val INFRACOST_FILES = setOf("infracost.yml", "infracost.yml.tmpl", "infracost-usage.yml")

class InfracostFileListener : BulkFileListener {

// This method is called after the files are processed
Expand All @@ -13,8 +16,11 @@ class InfracostFileListener : BulkFileListener {
override fun after(events: MutableList<out VFileEvent>) {
for (event in events) {
if (event.isFromSave) {
val project = ProjectLocator.getInstance().guessProjectForFile(event.file!!) ?: return
RunInfracostAction.runInfracost(project)
if (event.file?.extension?.lowercase() in INFRACOST_FILE_EXTENSIONS ||
INFRACOST_FILES.contains(event.file?.name?.lowercase())){
val project = ProjectLocator.getInstance().guessProjectForFile(event.file!!) ?: return
RunInfracostAction.runInfracost(project)
}
}
}
}
Expand Down

0 comments on commit 96d5eaa

Please sign in to comment.