GradleBuildRootsManager: update notifications in corner cases
- notification for all visible editors should be updates on each change, since it may depend on last modified ts. - notifications should be updated only for active editors, not all opened - we should recheck it on editor activation too - analyzer should be restarted on roots update only
This commit is contained in:
+2
-8
@@ -33,7 +33,7 @@ class GradleScriptListener(project: Project) : ScriptChangeListener(project) {
|
||||
|
||||
override fun editorActivated(vFile: VirtualFile) {
|
||||
if (isCustomScriptingSupport(vFile)) {
|
||||
checkUpToDate(vFile)
|
||||
buildRootsManager.updateNotifications(restartAnalyzer = false) { it == vFile.path }
|
||||
} else {
|
||||
legacy.editorActivated(vFile)
|
||||
}
|
||||
@@ -42,14 +42,8 @@ class GradleScriptListener(project: Project) : ScriptChangeListener(project) {
|
||||
override fun documentChanged(vFile: VirtualFile) {
|
||||
fileChanged(vFile.path, System.currentTimeMillis())
|
||||
|
||||
if (isCustomScriptingSupport(vFile)) {
|
||||
checkUpToDate(vFile)
|
||||
} else {
|
||||
if (!isCustomScriptingSupport(vFile)) {
|
||||
legacy.documentChanged(vFile)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkUpToDate(vFile: VirtualFile) {
|
||||
GradleBuildRootsManager.getInstance(project).checkUpToDate(vFile)
|
||||
}
|
||||
}
|
||||
+26
-16
@@ -82,15 +82,6 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate") // used in GradleImportHelper.kt.193
|
||||
fun checkUpToDate(file: VirtualFile) {
|
||||
if (isConfigurationOutOfDate(file)) {
|
||||
scriptConfigurationsNeedToBeUpdated(project)
|
||||
} else {
|
||||
scriptConfigurationsAreUpToDate(project)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate") // used in GradleImportHelper.kt.201
|
||||
fun isConfigurationOutOfDate(file: VirtualFile): Boolean {
|
||||
val script = getScriptInfo(file) ?: return false
|
||||
@@ -171,6 +162,8 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
||||
if (lastModifiedFilesSaveScheduled.compareAndSet(false, true)) {
|
||||
BackgroundTaskUtil.executeOnPooledThread(project) {
|
||||
if (lastModifiedFilesSaveScheduled.compareAndSet(true, false)) {
|
||||
updateNotifications(restartAnalyzer = false) { true }
|
||||
|
||||
roots.list.forEach {
|
||||
it.saveLastModifiedFiles()
|
||||
}
|
||||
@@ -330,19 +323,24 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
||||
}
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
private fun updateNotifications(shouldUpdatePath: (String) -> Boolean) {
|
||||
fun updateNotifications(
|
||||
restartAnalyzer: Boolean = true,
|
||||
shouldUpdatePath: (String) -> Boolean
|
||||
) {
|
||||
if (!project.isOpen) return
|
||||
|
||||
// import notification is a balloon, so should be shown only for selected editor
|
||||
FileEditorManager.getInstance(project).selectedEditor?.file?.let {
|
||||
if (shouldUpdatePath(it.path) && maybeAffectedGradleProjectFile(it.path)) {
|
||||
checkUpToDate(it)
|
||||
updateFloatingAction(it)
|
||||
}
|
||||
}
|
||||
|
||||
val openedScripts = FileEditorManager.getInstance(project).openFiles.filter {
|
||||
shouldUpdatePath(it.path) && maybeAffectedGradleProjectFile(it.path)
|
||||
}
|
||||
val openedScripts = FileEditorManager.getInstance(project).selectedEditors
|
||||
.mapNotNull { it.file }
|
||||
.filter {
|
||||
shouldUpdatePath(it.path) && maybeAffectedGradleProjectFile(it.path)
|
||||
}
|
||||
|
||||
if (openedScripts.isEmpty()) return
|
||||
|
||||
@@ -350,13 +348,25 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
||||
if (project.isDisposed) return@launch
|
||||
|
||||
openedScripts.forEach {
|
||||
val ktFile = PsiManager.getInstance(project).findFile(it)
|
||||
if (ktFile != null) DaemonCodeAnalyzer.getInstance(project).restart(ktFile)
|
||||
if (restartAnalyzer) {
|
||||
// this required only for "pause" state
|
||||
val ktFile = PsiManager.getInstance(project).findFile(it)
|
||||
if (ktFile != null) DaemonCodeAnalyzer.getInstance(project).restart(ktFile)
|
||||
}
|
||||
|
||||
EditorNotifications.getInstance(project).updateAllNotifications()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateFloatingAction(file: VirtualFile) {
|
||||
if (isConfigurationOutOfDate(file)) {
|
||||
scriptConfigurationsNeedToBeUpdated(project)
|
||||
} else {
|
||||
scriptConfigurationsAreUpToDate(project)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadStandaloneScriptConfigurations(files: MutableSet<String>) {
|
||||
runReadAction {
|
||||
files.forEach {
|
||||
|
||||
Reference in New Issue
Block a user