workaround for IDEA's issue that throws an exception when using union() on a LocalSearchScope with no elements (EA-82063 - AIOOBE: GlobalSearchScope.union)
This commit is contained in:
+2
-1
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||
import org.jetbrains.kotlin.idea.search.KOTLIN_NAMED_ARGUMENT_SEARCH_CONTEXT
|
||||
import org.jetbrains.kotlin.idea.search.allScope
|
||||
import org.jetbrains.kotlin.idea.search.effectiveSearchScope
|
||||
import org.jetbrains.kotlin.idea.search.unionSafe
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.dataClassComponentFunction
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.getClassNameForCompanionObject
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.getSpecialNamesToSearch
|
||||
@@ -80,7 +81,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
|
||||
|
||||
val effectiveSearchScope = runReadAction {
|
||||
val elements = if (unwrappedElement is KtDeclaration) unwrappedElement.toLightElements() else listOf(unwrappedElement)
|
||||
elements.fold(queryParameters.effectiveSearchScope) { scope, e -> scope.union(queryParameters.effectiveSearchScope(e)) }
|
||||
elements.fold(queryParameters.effectiveSearchScope) { scope, e -> scope.unionSafe(queryParameters.effectiveSearchScope(e)) }
|
||||
}
|
||||
|
||||
val refFilter: (PsiReference) -> Boolean = when {
|
||||
|
||||
@@ -32,6 +32,16 @@ infix fun SearchScope.or(otherScope: SearchScope): SearchScope = union(otherScop
|
||||
operator fun SearchScope.minus(otherScope: GlobalSearchScope): SearchScope = this and !otherScope
|
||||
operator fun GlobalSearchScope.not(): GlobalSearchScope = GlobalSearchScope.notScope(this)
|
||||
|
||||
fun SearchScope.unionSafe(other: SearchScope): SearchScope {
|
||||
if (this is LocalSearchScope && this.scope.isEmpty()) {
|
||||
return other
|
||||
}
|
||||
if (other is LocalSearchScope && other.scope.isEmpty()) {
|
||||
return this
|
||||
}
|
||||
return this.union(other)
|
||||
}
|
||||
|
||||
fun Project.allScope(): GlobalSearchScope = GlobalSearchScope.allScope(this)
|
||||
|
||||
fun Project.projectScope(): GlobalSearchScope = GlobalSearchScope.projectScope(this)
|
||||
|
||||
Reference in New Issue
Block a user