diff --git a/src/main/kotlin/io/infracost/plugins/infracost/listeners/InfracostFileListener.kt b/src/main/kotlin/io/infracost/plugins/infracost/listeners/InfracostFileListener.kt index 83fdb5f..93b7c61 100644 --- a/src/main/kotlin/io/infracost/plugins/infracost/listeners/InfracostFileListener.kt +++ b/src/main/kotlin/io/infracost/plugins/infracost/listeners/InfracostFileListener.kt @@ -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 @@ -13,8 +16,11 @@ class InfracostFileListener : BulkFileListener { override fun after(events: MutableList) { 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) + } } } }