Skip to content

Commit

Permalink
Merge pull request #85 from cashapp/juho/fix-redundant-installs
Browse files Browse the repository at this point in the history
fix: do not run "hermit install" multiple times on a change if multiple windows are open
  • Loading branch information
jvmakine authored Mar 12, 2024
2 parents e64c761 + ccc2303 commit cd81e89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ kotlin.code.style=official

# The latest supported versions. Note, these are updated automatically from update-major-versions.sh
IIC.release.version=233.14015.106
IIC.eap.version=241.8102.112
IIC.eap.version=241.14494.17

IIC.release.go_plugin.version=233.14015.106
IIC.eap.go_plugin.version=241.8102.112
IIC.eap.go_plugin.version=241.14494.17
GO.release.version=233.13135.104
GO.eap.version=241.8102.131
# The oldest supported versions.
Expand Down
28 changes: 13 additions & 15 deletions src/main/kotlin/com/squareup/cash/hermit/HermitVFSChangeListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,34 @@ import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.newvfs.BulkFileListener
import com.intellij.openapi.vfs.newvfs.events.VFileEvent

class HermitVFSChangeListener : BulkFileListener {
class HermitVFSChangeListener(val project: Project) : BulkFileListener {
private val log: Logger = Logger.getInstance(this.javaClass)

override fun after(events: MutableList<out VFileEvent>) {
val needsUpdating = HashMap<String, Project>()
var needsUpdating = false
events.forEach {
it.file?.let { file ->
log.debug("Checking if file [${file.path}] is in projects " +
"${Hermit.allProjects().map { state -> state.project.name }}")
Hermit.allProjects().forEach { state ->
val project = state.project
// The project might have been disposed since looking up Hermit.allProjects.
log.debug("Project [${project.name}] is disposed: [${project.isDisposed}]")
if (!project.isDisposed && isHermitChange(project, file)) {
log.debug("Project [${project.name}] needs updating")
needsUpdating[project.name] = project
}
"${Hermit.allProjects().map { state -> state.project.name }}")
// The project might have been disposed since looking up Hermit.allProjects.
log.debug("Project [${project.name}] is disposed: [${project.isDisposed}]")
if (!project.isDisposed && isHermitChange(project, file)) {
log.debug("Project [${project.name}] needs updating")
needsUpdating = true
}
}
}

needsUpdating.forEach {
log.info("hermit configuration change detected at " + it.value.name)
Hermit(it.value).open()
Hermit(it.value).installAndUpdate()
if (needsUpdating) {
log.info("hermit configuration change detected at " + project.name)
Hermit(project).open()
Hermit(project).installAndUpdate()
}
}

private fun isHermitChange(project: Project, file: VirtualFile): Boolean {
val root = project.guessProjectDir()

// Check if we are in a bin/ directory
if (root == null || file.parent == null || (file.parent.name != "bin" && file.name != "bin")) {
return false
Expand Down

0 comments on commit cd81e89

Please sign in to comment.