From e46024534ce50b995182050b5e29786e5b683504 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Sun, 15 Dec 2024 01:01:52 +0100 Subject: [PATCH] fix exception when searching for a reference [closes #89] --- .../intellij/reference/ReferenceSearcher.kt | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/main/kotlin/org/nextras/orm/intellij/reference/ReferenceSearcher.kt b/src/main/kotlin/org/nextras/orm/intellij/reference/ReferenceSearcher.kt index 68ab315..06f1ede 100644 --- a/src/main/kotlin/org/nextras/orm/intellij/reference/ReferenceSearcher.kt +++ b/src/main/kotlin/org/nextras/orm/intellij/reference/ReferenceSearcher.kt @@ -1,5 +1,6 @@ package org.nextras.orm.intellij.reference +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.QueryExecutorBase import com.intellij.psi.PsiReference import com.intellij.psi.search.PsiSearchHelper @@ -11,31 +12,36 @@ import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocProperty import com.jetbrains.php.lang.psi.elements.StringLiteralExpression class ReferenceSearcher : QueryExecutorBase() { - override fun processQuery(searchParameters: ReferencesSearch.SearchParameters, processor: Processor) { + override fun processQuery( + searchParameters: ReferencesSearch.SearchParameters, + processor: Processor + ) { val property = searchParameters.elementToSearch as? PhpDocProperty ?: return val providers = arrayOf(CollectionPropertyReferenceProvider(), EntityPropertyNameReferenceProvider()) - PsiSearchHelper.getInstance(property.project) - .processElementsWithWord( - { psiElement, _ -> - if (psiElement !is StringLiteralExpression) { - return@processElementsWithWord true - } + ApplicationManager.getApplication().runReadAction { + PsiSearchHelper.getInstance(property.project) + .processElementsWithWord( + { psiElement, _ -> + if (psiElement !is StringLiteralExpression) { + return@processElementsWithWord true + } - val processingContext = ProcessingContext() - processingContext.put("field", property.name) - for (provider in providers) { - provider.getReferencesByElement(psiElement, processingContext) - .filter { it.isReferenceTo(searchParameters.elementToSearch) } - .forEach { processor.process(it) } - } + val processingContext = ProcessingContext() + processingContext.put("field", property.name) + for (provider in providers) { + provider.getReferencesByElement(psiElement, processingContext) + .filter { it.isReferenceTo(searchParameters.elementToSearch) } + .forEach { processor.process(it) } + } + true + }, + searchParameters.scopeDeterminedByUser, + property.name, + UsageSearchContext.IN_STRINGS, true - }, - searchParameters.scopeDeterminedByUser, - property.name, - UsageSearchContext.IN_STRINGS, - true - ) + ) + } } }