Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't run on each file save #10

Merged
merged 1 commit into from
Jul 2, 2024
Merged
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
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