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) {
|
override fun editorActivated(vFile: VirtualFile) {
|
||||||
if (isCustomScriptingSupport(vFile)) {
|
if (isCustomScriptingSupport(vFile)) {
|
||||||
checkUpToDate(vFile)
|
buildRootsManager.updateNotifications(restartAnalyzer = false) { it == vFile.path }
|
||||||
} else {
|
} else {
|
||||||
legacy.editorActivated(vFile)
|
legacy.editorActivated(vFile)
|
||||||
}
|
}
|
||||||
@@ -42,14 +42,8 @@ class GradleScriptListener(project: Project) : ScriptChangeListener(project) {
|
|||||||
override fun documentChanged(vFile: VirtualFile) {
|
override fun documentChanged(vFile: VirtualFile) {
|
||||||
fileChanged(vFile.path, System.currentTimeMillis())
|
fileChanged(vFile.path, System.currentTimeMillis())
|
||||||
|
|
||||||
if (isCustomScriptingSupport(vFile)) {
|
if (!isCustomScriptingSupport(vFile)) {
|
||||||
checkUpToDate(vFile)
|
|
||||||
} else {
|
|
||||||
legacy.documentChanged(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
|
@Suppress("MemberVisibilityCanBePrivate") // used in GradleImportHelper.kt.201
|
||||||
fun isConfigurationOutOfDate(file: VirtualFile): Boolean {
|
fun isConfigurationOutOfDate(file: VirtualFile): Boolean {
|
||||||
val script = getScriptInfo(file) ?: return false
|
val script = getScriptInfo(file) ?: return false
|
||||||
@@ -171,6 +162,8 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
|||||||
if (lastModifiedFilesSaveScheduled.compareAndSet(false, true)) {
|
if (lastModifiedFilesSaveScheduled.compareAndSet(false, true)) {
|
||||||
BackgroundTaskUtil.executeOnPooledThread(project) {
|
BackgroundTaskUtil.executeOnPooledThread(project) {
|
||||||
if (lastModifiedFilesSaveScheduled.compareAndSet(true, false)) {
|
if (lastModifiedFilesSaveScheduled.compareAndSet(true, false)) {
|
||||||
|
updateNotifications(restartAnalyzer = false) { true }
|
||||||
|
|
||||||
roots.list.forEach {
|
roots.list.forEach {
|
||||||
it.saveLastModifiedFiles()
|
it.saveLastModifiedFiles()
|
||||||
}
|
}
|
||||||
@@ -330,19 +323,24 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
private fun updateNotifications(shouldUpdatePath: (String) -> Boolean) {
|
fun updateNotifications(
|
||||||
|
restartAnalyzer: Boolean = true,
|
||||||
|
shouldUpdatePath: (String) -> Boolean
|
||||||
|
) {
|
||||||
if (!project.isOpen) return
|
if (!project.isOpen) return
|
||||||
|
|
||||||
// import notification is a balloon, so should be shown only for selected editor
|
// import notification is a balloon, so should be shown only for selected editor
|
||||||
FileEditorManager.getInstance(project).selectedEditor?.file?.let {
|
FileEditorManager.getInstance(project).selectedEditor?.file?.let {
|
||||||
if (shouldUpdatePath(it.path) && maybeAffectedGradleProjectFile(it.path)) {
|
if (shouldUpdatePath(it.path) && maybeAffectedGradleProjectFile(it.path)) {
|
||||||
checkUpToDate(it)
|
updateFloatingAction(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val openedScripts = FileEditorManager.getInstance(project).openFiles.filter {
|
val openedScripts = FileEditorManager.getInstance(project).selectedEditors
|
||||||
shouldUpdatePath(it.path) && maybeAffectedGradleProjectFile(it.path)
|
.mapNotNull { it.file }
|
||||||
}
|
.filter {
|
||||||
|
shouldUpdatePath(it.path) && maybeAffectedGradleProjectFile(it.path)
|
||||||
|
}
|
||||||
|
|
||||||
if (openedScripts.isEmpty()) return
|
if (openedScripts.isEmpty()) return
|
||||||
|
|
||||||
@@ -350,13 +348,25 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
|
|||||||
if (project.isDisposed) return@launch
|
if (project.isDisposed) return@launch
|
||||||
|
|
||||||
openedScripts.forEach {
|
openedScripts.forEach {
|
||||||
val ktFile = PsiManager.getInstance(project).findFile(it)
|
if (restartAnalyzer) {
|
||||||
if (ktFile != null) DaemonCodeAnalyzer.getInstance(project).restart(ktFile)
|
// 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()
|
EditorNotifications.getInstance(project).updateAllNotifications()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateFloatingAction(file: VirtualFile) {
|
||||||
|
if (isConfigurationOutOfDate(file)) {
|
||||||
|
scriptConfigurationsNeedToBeUpdated(project)
|
||||||
|
} else {
|
||||||
|
scriptConfigurationsAreUpToDate(project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadStandaloneScriptConfigurations(files: MutableSet<String>) {
|
private fun loadStandaloneScriptConfigurations(files: MutableSet<String>) {
|
||||||
runReadAction {
|
runReadAction {
|
||||||
files.forEach {
|
files.forEach {
|
||||||
|
|||||||
Reference in New Issue
Block a user