From 45568f8c6045ed91847d033bedc05780bc24d510 Mon Sep 17 00:00:00 2001 From: Oliver Nybroe Date: Thu, 12 Aug 2021 07:26:27 +0200 Subject: [PATCH] Change the file listener to use a invokeLater action --- CHANGELOG.md | 4 ++ gradle.properties | 2 +- .../fileListeners/ExtendAsyncFileListener.kt | 47 +++++++------------ .../pest/services/ExpectationFileService.kt | 7 ++- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 794c5146..2c621e8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ # PEST IntelliJ Changelog ## [Unreleased] +### Fixed +- Invoke the FileListener PSI part later (should fix indexing issues) + +## [1.0.5] ### Changed - Bumped min IntelliJ version to 2021.1 diff --git a/gradle.properties b/gradle.properties index 86403741..e3018345 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ pluginGroup = com.pestphp pluginName = PEST PHP -pluginVersion = 1.0.5 +pluginVersion = 1.0.6 # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. diff --git a/src/main/kotlin/com/pestphp/pest/fileListeners/ExtendAsyncFileListener.kt b/src/main/kotlin/com/pestphp/pest/fileListeners/ExtendAsyncFileListener.kt index 856d366f..a404b6b6 100644 --- a/src/main/kotlin/com/pestphp/pest/fileListeners/ExtendAsyncFileListener.kt +++ b/src/main/kotlin/com/pestphp/pest/fileListeners/ExtendAsyncFileListener.kt @@ -1,5 +1,6 @@ package com.pestphp.pest.fileListeners +import com.intellij.openapi.application.invokeLater import com.intellij.openapi.components.service import com.intellij.openapi.externalSystem.autoimport.AsyncFileChangeListenerBase import com.intellij.openapi.project.NoAccessDuringPsiEvents @@ -26,25 +27,24 @@ class ExtendAsyncFileListener : AsyncFileChangeListenerBase() { } override fun updateFile(file: VirtualFile, event: VFileEvent) { - try { - ProjectManager.getInstance() - .openProjects - // Only look at projects where the file is inside. - .filter { ProjectFileIndex.getInstance(it).isInContent(file) } - // Get the PSI file inside each of the projects. - .mapNotNull { PsiManager.getInstance(it).findFile(file) } - // Only look at PHP files - .filterIsInstance() - .filter { it.expectExtends.isNotEmpty() } - .forEach { - val expectationFileService = it.project.service() + ProjectManager.getInstance() + .openProjects + // Only look at projects where the file is inside. + .filter { ProjectFileIndex.getInstance(it).isInContent(file) } + // Get the PSI file inside each of the projects. + .mapNotNull { PsiManager.getInstance(it).findFile(file) } + // Only look at PHP files + .filterIsInstance() + .forEach { + val expectationFileService = it.project.service() - // In case file is deleted. - if (event is VFileDeleteEvent) { - expectationFileService.removeExtends(it.virtualFile) - return@forEach - } + // In case file is deleted. + if (event is VFileDeleteEvent) { + expectationFileService.removeExtends(it.virtualFile) + return@forEach + } + invokeLater { // Add all the extends val hasChanges = expectationFileService.updateExtends(it) @@ -53,20 +53,7 @@ class ExtendAsyncFileListener : AsyncFileChangeListenerBase() { expectationFileService.generateFile() } } - } catch (exception: Exception) { - // Ignore up to date stub mismatch exceptions - if (exception.javaClass.simpleName.equals("UpToDateStubIndexMismatch")) { - return - } - if (exception.stackTrace.any { it.methodName.equals("stubTreeAndIndexDoNotMatch") }) { - return } - if (exception.stackTrace.any { it.className.equals(NoAccessDuringPsiEvents::class.java.name)}) { - return - } - - throw exception - } } override fun isRelevant(file: VirtualFile, event: VFileEvent): Boolean { diff --git a/src/main/kotlin/com/pestphp/pest/services/ExpectationFileService.kt b/src/main/kotlin/com/pestphp/pest/services/ExpectationFileService.kt index ebe847a2..755573ac 100644 --- a/src/main/kotlin/com/pestphp/pest/services/ExpectationFileService.kt +++ b/src/main/kotlin/com/pestphp/pest/services/ExpectationFileService.kt @@ -1,6 +1,9 @@ package com.pestphp.pest.services import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.application.invokeLater +import com.intellij.openapi.application.runWriteAction +import com.intellij.openapi.progress.runSuspendingAction import com.intellij.openapi.project.DumbService import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile @@ -73,8 +76,8 @@ class ExpectationFileService(val project: Project) { val file = generator.generateToFile(project) // Save the file in vendor folder - ApplicationManager.getApplication().invokeLater { - ApplicationManager.getApplication().runWriteAction { + invokeLater { + runWriteAction { DumbService.getInstance(project).suspendIndexingAndRun( "Indexing Pest expect extends" ) {