Skip to content

Commit b1c44b3

Browse files
authored
Fix logged error due to ARN contributor taking too long (#3092)
1 parent 93f6c17 commit b1c44b3

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Fix logged error due to ARN contributor taking too long (#3085)"
4+
}

jetbrains-core/src/software/aws/toolkits/jetbrains/services/federation/psireferences/ArnPsiReferenceContributor.kt

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
package software.aws.toolkits.jetbrains.services.federation.psireferences
55

66
import com.intellij.patterns.PsiElementPattern
7-
import com.intellij.psi.ElementManipulators
87
import com.intellij.psi.PsiElement
8+
import com.intellij.psi.PsiLiteralValue
99
import com.intellij.psi.PsiReferenceContributor
1010
import com.intellij.psi.PsiReferenceRegistrar
1111
import com.intellij.util.ProcessingContext
12-
import software.aws.toolkits.core.utils.debug
13-
import software.aws.toolkits.core.utils.error
1412
import software.aws.toolkits.core.utils.getLogger
1513

1614
class ArnPsiReferenceContributor : PsiReferenceContributor() {
@@ -19,28 +17,9 @@ class ArnPsiReferenceContributor : PsiReferenceContributor() {
1917
object : PsiElementPattern.Capture<PsiElement>(
2018
PsiElement::class.java
2119
) {
22-
override fun accepts(o: Any?, context: ProcessingContext): Boolean {
23-
if (o == null || o !is PsiElement) return false
24-
val manipulator = ElementManipulators.getManipulator(o)
25-
if (manipulator == null) return false
26-
27-
try {
28-
val text = o.text
29-
val range = manipulator.getRangeInElement(o)
30-
if (range.length > text.length || range.endOffset > text.length) {
31-
LOG.debug { "Manipulator range: $range doesn't fit in PsiElement text: $text" }
32-
return false
33-
}
34-
if (range.substring(text).contains("arn:")) {
35-
return true
36-
}
37-
} catch (e: Exception) {
38-
LOG.error(e) { "Error while checking PsiElement" }
39-
return false
40-
}
41-
42-
return false
43-
}
20+
override fun accepts(o: Any?, context: ProcessingContext): Boolean =
21+
// this is lower fidelity than we'd like but avoids resolving the entire PSI tree
22+
o is PsiLiteralValue && o.value is String
4423
},
4524
ArnPsiReferenceProvider(),
4625
PsiReferenceRegistrar.LOWER_PRIORITY

jetbrains-core/tst/software/aws/toolkits/jetbrains/services/federation/psireferences/ArnPsiReferenceProviderTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class ArnPsiReferenceProviderTest {
133133
val contents = """
134134
Hello:
135135
Some:
136-
Nesting: arn:aws:lambda::123456789012:function
136+
Nesting: 1 # arn:aws:lambda::123456789012:function
137137
""".trimIndent()
138138

139139
val file = runInEdtAndGet {

0 commit comments

Comments
 (0)