fun update()

in src/main/kotlin/org/arend/toolWindow/errors/ArendMessagesView.kt [348:402]


    fun update() {
        val filterSet = project.service<ArendProjectSettings>().messagesFilterSet
        val errorsMap = project.service<ErrorService>().errors

        ApplicationManager.getApplication().run {
            executeOnPooledThread {
                val arendFilesWithErrors = getArendFilesWithErrors(filterSet, errorsMap).onEach {
                    runReadAction { it.arendLibrary }
                    it.moduleLocation
                }
                runInEdt {
                    val expandedPaths = TreeUtil.collectExpandedPaths(tree)
                    val selectedPath = tree.selectionPath

                    val map = HashMap<PsiConcreteReferable, HashMap<PsiElement?, ArendErrorTreeElement>>()
                    tree.update(root) { node ->
                        if (node == root) {
                            arendFilesWithErrors
                        }
                        else when (val obj = node.userObject) {
                            is ArendFile -> {
                                val arendErrors = errorsMap[obj]
                                val children = LinkedHashSet<Any>()
                                for (arendError in arendErrors ?: emptyList()) {
                                    if (!arendError.error.satisfies(filterSet)) {
                                        continue
                                    }

                                    var def: PsiConcreteReferable? = null
                                    executeOnPooledThread {
                                        runReadAction {
                                            def = arendError.definition
                                        }
                                    }.get()
                                    if (def == null) {
                                        children.add(ArendErrorTreeElement(arendError))
                                    } else {
                                        children.add(def!!)
                                        map.computeIfAbsent(def!!) { LinkedHashMap() }
                                            .computeIfAbsent(arendError.cause) { ArendErrorTreeElement() }.add(arendError)
                                    }
                                }
                                children
                            }
                            is PsiConcreteReferable -> map[obj]?.values ?: emptySet()
                            else -> emptySet()
                        }
                    }
                    treeModel.reload()
                    TreeUtil.restoreExpandedPaths(tree, expandedPaths)
                    tree.selectionPath = tree.getExistingPrefix(selectedPath)
                }
            }
        }
    }