summaryrefslogtreecommitdiff
path: root/layout-inspector/src
diff options
context:
space:
mode:
authorJens Ole Lauridsen <jlauridsen@google.com>2021-12-20 15:05:06 -0800
committerJens Ole Lauridsen <jlauridsen@google.com>2021-12-23 18:59:23 +0000
commit09debda8b850bed5da9decb97871df2bf50ff0ae (patch)
treea5eb7bf3d2456ed0c4030e9e587108102fa56585 /layout-inspector/src
parent89920e2ca20981485dac361343d469b18732e822 (diff)
downloadidea-09debda8b850bed5da9decb97871df2bf50ff0ae.tar.gz
Delay execution for GotoDeclarationAction
The GotoDeclarationAction needs to perform an index lookup which should not happen on the EDT. To avoid that: - execute the goto on a background thread - remove the update method which cannot contain index lookups Updated the tests to wait for the background thread to finish. Fixes: 210727054 Test: Existing tests updated Change-Id: I6c346cc34a97061e7bcb4a11610bc551b27150c4
Diffstat (limited to 'layout-inspector/src')
-rw-r--r--layout-inspector/src/com/android/tools/idea/layoutinspector/resource/ComposeResolver.kt3
-rw-r--r--layout-inspector/src/com/android/tools/idea/layoutinspector/resource/ResourceLookup.kt1
-rw-r--r--layout-inspector/src/com/android/tools/idea/layoutinspector/tree/GotoDeclarationAction.kt17
3 files changed, 15 insertions, 6 deletions
diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/resource/ComposeResolver.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/resource/ComposeResolver.kt
index a1cf70ad09e..caef66166c6 100644
--- a/layout-inspector/src/com/android/tools/idea/layoutinspector/resource/ComposeResolver.kt
+++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/resource/ComposeResolver.kt
@@ -15,6 +15,7 @@
*/
package com.android.tools.idea.layoutinspector.resource
+import com.android.annotations.concurrency.Slow
import com.android.tools.idea.layoutinspector.model.ComposeViewNode
import com.android.tools.idea.layoutinspector.model.packageNameHash
import com.intellij.ide.util.PsiNavigationSupport
@@ -30,6 +31,7 @@ import org.jetbrains.kotlin.psi.KtFile
*/
open class ComposeResolver(val project: Project) {
+ @Slow
fun findComposableNavigatable(node: ComposeViewNode): Navigatable? {
val ktFile = findKotlinFile(node.composeFilename) { packageNameHash(it) == node.composePackageHash } ?: return null
val vFile = ktFile.virtualFile ?: return null
@@ -41,6 +43,7 @@ open class ComposeResolver(val project: Project) {
*
* If there are multiple files with the same name use the package name matcher.
*/
+ @Slow
protected fun findKotlinFile(fileName: String, packageNameMatcher: (String) -> Boolean): KtFile? {
val files = FilenameIndex.getFilesByName(project, fileName, GlobalSearchScope.allScope(project))
if (files.size == 1) {
diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/resource/ResourceLookup.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/resource/ResourceLookup.kt
index 9ea045537d7..aa1a384f815 100644
--- a/layout-inspector/src/com/android/tools/idea/layoutinspector/resource/ResourceLookup.kt
+++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/resource/ResourceLookup.kt
@@ -140,6 +140,7 @@ class ResourceLookup(private val project: Project) {
/**
* Find the source navigatable of a composable function.
*/
+ @Slow
fun findComposableNavigatable(composable: ComposeViewNode): Navigatable? =
composeResolver.findComposableNavigatable(composable)
diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/GotoDeclarationAction.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/GotoDeclarationAction.kt
index 44eed70a16a..8db8125d5fb 100644
--- a/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/GotoDeclarationAction.kt
+++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/GotoDeclarationAction.kt
@@ -15,30 +15,35 @@
*/
package com.android.tools.idea.layoutinspector.tree
+import com.android.annotations.concurrency.Slow
+import com.android.tools.idea.concurrency.executeOnPooledThread
import com.android.tools.idea.layoutinspector.LayoutInspector
import com.android.tools.idea.layoutinspector.model.ComposeViewNode
import com.android.tools.idea.layoutinspector.model.InspectorModel
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.pom.Navigatable
+import org.jetbrains.kotlin.idea.debugger.readAction
/**
* Action for navigating to the currently selected node in the layout inspector.
*/
object GotoDeclarationAction : AnAction("Go To Declaration") {
+
override fun actionPerformed(event: AnActionEvent) {
val inspector = LayoutInspector.get(event) ?: return
- inspector.stats.gotoSourceFromTreeActionMenu(event)
- findNavigatable(event)?.navigate(true)
- }
-
- override fun update(event: AnActionEvent) {
- event.presentation.isEnabled = findNavigatable(event) != null
+ executeOnPooledThread {
+ readAction {
+ inspector.stats.gotoSourceFromTreeActionMenu(event)
+ findNavigatable(event)?.navigate(true)
+ }
+ }
}
private fun findNavigatable(event: AnActionEvent): Navigatable? =
LayoutInspector.get(event)?.layoutInspectorModel?.let { findNavigatable(it) }
+ @Slow
fun findNavigatable(model: InspectorModel): Navigatable? {
val resourceLookup = model.resourceLookup
val node = model.selection ?: return null