Skip to content

Commit f1ff942

Browse files
committed
fix(java): wrap PSI operations in runReadAction
Wrap all PSI cache and file manager operations with runReadAction to ensure thread-safe access to the IntelliJ platform's read-write lock system.
1 parent 1d90492 commit f1ff942

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

java/src/main/kotlin/cc/unitmesh/idea/provider/JavaCustomDevInsSymbolProvider.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,19 @@ class JavaCustomDevInsSymbolProvider : DevInsSymbolProvider {
119119

120120
// className only, like `String` not Dot
121121
if (symbol.contains(".").not()) {
122-
val psiClasses = PsiShortNamesCache.getInstance(project).getClassesByName(symbol, scope)
122+
val psiClasses = runReadAction { PsiShortNamesCache.getInstance(project).getClassesByName(symbol, scope) }
123123
if (psiClasses.isNotEmpty()) {
124124
return psiClasses.toList()
125125
}
126126
}
127127

128128
// for package name only, like `cc.unitmesh`
129-
JavaFileManagerImpl(project).findPackage(symbol)?.let { pkg ->
129+
runReadAction { JavaFileManagerImpl(project).findPackage(symbol) }?.let { pkg ->
130130
return runReadAction { pkg.classes.toList() }
131131
}
132132

133133
// for single class, with function name, like `cc.unitmesh.idea.provider.JavaCustomDevInsSymbolProvider`
134-
val clazz = JavaFileManagerImpl(project).findClass(symbol, scope)
134+
val clazz = runReadAction { JavaFileManagerImpl(project).findClass(symbol, scope) }
135135
if (clazz != null) {
136136
return listOf(clazz)
137137
}
@@ -162,9 +162,11 @@ class JavaCustomDevInsSymbolProvider : DevInsSymbolProvider {
162162
scope: GlobalSearchScope,
163163
methodName: String
164164
): List<String> {
165-
val psiClass = JavaFileManagerImpl(project).findClass(clazzName, scope)
165+
val psiClass = runReadAction { JavaFileManagerImpl(project).findClass(clazzName, scope) }
166166
if (psiClass != null) {
167-
val psiMethod = psiClass.findMethodsByName(methodName, true).firstOrNull()
167+
val psiMethod = runReadAction {
168+
psiClass.findMethodsByName(methodName, true).firstOrNull()
169+
}
168170
if (psiMethod != null) {
169171
return listOf(psiMethod.text)
170172
}
@@ -179,9 +181,11 @@ class JavaCustomDevInsSymbolProvider : DevInsSymbolProvider {
179181
scope: GlobalSearchScope,
180182
methodName: String
181183
): List<PsiElement> {
182-
val psiClass = JavaFileManagerImpl(project).findClass(clazzName, scope)
184+
val psiClass = runReadAction { JavaFileManagerImpl(project).findClass(clazzName, scope) }
183185
if (psiClass != null) {
184-
val psiMethod = psiClass.findMethodsByName(methodName, true).firstOrNull()
186+
val psiMethod = runReadAction {
187+
psiClass.findMethodsByName(methodName, true).firstOrNull()
188+
}
185189
if (psiMethod != null) {
186190
return listOf(psiMethod)
187191
}

0 commit comments

Comments
 (0)