Skip to content

Commit

Permalink
Fix doing slow operation on EDT issues.
Browse files Browse the repository at this point in the history
Version 1.24.9.
  • Loading branch information
BlueBoxWare committed Dec 20, 2023
1 parent 6cabf0a commit 3127131
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 1.24.9
* Fix doing slow operation on EDT issues.

### 1.24.8
* Fix [#38](https://github.com/BlueBoxWare/LibGDXPlugin/issues/38): IndexNotReadyException when loading non-libgdx project.

Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ plugins {
id("java")
id("maven-publish")
id("org.jetbrains.kotlin.jvm") version "1.8.10"
id("org.jetbrains.intellij") version "1.13.0"
id("com.github.blueboxware.tocme") version "1.7"
id("org.jetbrains.intellij") version "1.16.1"
id("com.github.blueboxware.tocme") version "1.8"
}

group = properties("pluginGroup")
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
pluginGroup = com.gmail.blueboxware
pluginName = LibGDX Plugin
pluginVersion = 1.24.8
pluginVersion = 1.24.9

pluginSinceBuild = 232.6095.10
pluginSinceBuild = 233.11799.300
pluginUntilBuild =

# https://www.jetbrains.com/intellij-repository/snapshots/
# https://www.jetbrains.com/intellij-repository/releases/
# gradle printProductsReleases
pluginVerifierIdeVersions = 232.9921.47
pluginVerifierIdeVersions = 233.11799.300

platformType = IC
platformVersion = 232.9921.47
platformVersion = 233.11799.300
platformDownloadSources = true

platformPlugins = java, Kotlin, Groovy, properties
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.intellij.openapi.components.State
import com.intellij.openapi.fileTypes.FileType
import com.intellij.openapi.fileTypes.impl.FileTypeOverrider
import com.intellij.openapi.project.ProjectLocator
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile

/*
Expand Down Expand Up @@ -52,13 +53,15 @@ internal class LibGDXFileTypeOverrider : FileTypeOverrider {
} catch (e: UnsupportedOperationException) {
null
} ?: return null

val url = VfsUtilCore.pathToUrl(file.path)
project.getService(LibGDXProjectSkinFiles::class.java)?.let {
if (it.contains(file)) {
if (it.contains(url)) {
return LibGDXSkinFileType
}
}
project.getService(LibGDXProjectGdxJsonFiles::class.java)?.let {
if (it.contains(file)) {
if (it.contains(url)) {
return LibGDXJsonFileType
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.psi.LanguageSubstitutors
import com.intellij.ui.EditorNotifications
import com.intellij.util.FileContentUtilCore
Expand Down Expand Up @@ -155,7 +156,7 @@ private fun resetAssociations(

if (result == Messages.OK) {

val filesChanged = mutableSetOf<VirtualFile>()
val filesChanged = mutableSetOf<String>()

@Suppress("RetrievingService")
project.getService(set1.java)?.let {
Expand All @@ -173,8 +174,11 @@ private fun resetAssociations(
it.removeAll()
}

filesChanged.forEach {
project.reset(it)
val vfManager = VirtualFileManager.getInstance()
filesChanged.forEach { url ->
vfManager.findFileByUrl(url)?.let { file ->
project.reset(file)
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package com.gmail.blueboxware.libgdxplugin.utils
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.openapi.vfs.VirtualFileWithId
import org.jdom.Attribute
import org.jdom.Element
import java.util.*

/**
*
Expand All @@ -16,47 +14,36 @@ import java.util.*
*/
open class PersistentFileSetManager : PersistentStateComponent<Element> {

val files = HashSet<VirtualFile>()
val files = HashSet<String>()

fun add(file: VirtualFile): Boolean {
if (file !is VirtualFileWithId || file.isDirectory) {
return false
}
files.add(file)
files.add(VfsUtilCore.pathToUrl(file.path))
return true
}

fun remove(file: VirtualFile): Boolean {
if (!files.contains(file)) {
val url = VfsUtilCore.pathToUrl(file.path)
if (!files.contains(url)) {
return false
}
files.remove(file)
files.remove(url)
return true
}

fun removeAll() = files.clear()

fun contains(file: VirtualFile) = files.contains(file)
fun contains(file: VirtualFile) = files.contains(VfsUtilCore.pathToUrl(file.path))

private fun getSortedFiles(): Collection<VirtualFile> {
val sortedFiles = mutableListOf<VirtualFile>()
sortedFiles.addAll(files)
sortedFiles.sortWith { o1, o2 ->
o1.path.lowercase(Locale.getDefault()).compareTo(o2.path.lowercase(Locale.getDefault()))
}
return sortedFiles
}
fun contains(url: String) = files.contains(url)

override fun loadState(state: Element) {
val vfManager = VirtualFileManager.getInstance()
for (child in state.getChildren("file") ?: listOf()) {
if (child is Element) {
child.getAttribute("url")?.let { filePathAttr ->
val filePath = filePathAttr.value
val virtualFile = vfManager.findFileByUrl(filePath)
if (virtualFile != null) {
files.add(virtualFile)
}
filePathAttr.value?.let { files.add(it) }
}
}
}
Expand All @@ -65,9 +52,9 @@ open class PersistentFileSetManager : PersistentStateComponent<Element> {
override fun getState(): Element {
val root = Element("root")

for (virtualFile in getSortedFiles()) {
for (file in files.sorted()) {
val element = Element("file")
val filePathAttr = Attribute("url", VfsUtilCore.pathToUrl(virtualFile.path))
val filePathAttr = Attribute("url", file)
element.setAttribute(filePathAttr)
root.addContent(element)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.gmail.blueboxware.libgdxplugin.filetypes.skin.LibGDXSkinFileType
import com.gmail.blueboxware.libgdxplugin.settings.LibGDXProjectSkinFiles
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.psi.search.FileTypeIndex
import org.jetbrains.kotlin.idea.base.util.allScope

Expand Down Expand Up @@ -35,8 +36,16 @@ val SKIN_SIGNATURE = Regex("""(?:com\.badlogic\.gdx\.$FQ_CLASS_NAME|\b$COMMON_CL
fun getSkinFiles(project: Project): List<VirtualFile> {
val result = mutableListOf<VirtualFile>()
result.addAll(FileTypeIndex.getFiles(LibGDXSkinFileType, project.allScope()))
project.getService(LibGDXProjectSkinFiles::class.java)?.let { result.addAll(it.files) }
return result.filter { it.isValid }.toList()
val vfManager = VirtualFileManager.getInstance()
project.getService(LibGDXProjectSkinFiles::class.java)?.let {
for (url in it.files) {
val file = vfManager.findFileByUrl(url)
if (file != null && file.isValid) {
result.add(file)
}
}
}
return result
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.gmail.blueboxware.libgdxplugin.utils.findClasses
import com.gmail.blueboxware.libgdxplugin.utils.getLibraryInfoFromIdeaLibrary
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.DumbService
Expand All @@ -14,7 +15,9 @@ import com.intellij.openapi.roots.libraries.LibraryTable
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar
import com.intellij.psi.PsiLiteralExpression
import com.intellij.util.Alarm
import com.intellij.util.concurrency.AppExecutorUtil
import com.intellij.util.text.DateFormatUtil
import com.jetbrains.rd.util.Callable
import org.jetbrains.kotlin.config.MavenComparableVersion

/*
Expand Down Expand Up @@ -112,7 +115,10 @@ class VersionService(val project: Project) : Disposable {
if (ApplicationManager.getApplication().isUnitTestMode) {
DumbService.getInstance(project).runReadActionInSmartMode(runnable)
} else {
DumbService.getInstance(project).smartInvokeLater(runnable)
DumbService.getInstance(project).smartInvokeLater {
ReadAction.nonBlocking(Callable(runnable)).inSmartMode(project)
.submit(AppExecutorUtil.getAppExecutorService())
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<change-notes><![CDATA[
<ul>
<li>Fix 38: IndexNotReadyException</li>
<li>Fix doing slow operation on EDT issues.</li>
</ul>
]]>
</change-notes>
Expand Down

0 comments on commit 3127131

Please sign in to comment.