Skip to content

Commit

Permalink
fix exception when searching for a reference [closes #89]
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Dec 15, 2024
1 parent c685a6a commit e460245
Showing 1 changed file with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,31 +12,36 @@ import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocProperty
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression

class ReferenceSearcher : QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters>() {
override fun processQuery(searchParameters: ReferencesSearch.SearchParameters, processor: Processor<in PsiReference>) {
override fun processQuery(
searchParameters: ReferencesSearch.SearchParameters,
processor: Processor<in PsiReference>
) {
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
)
)
}
}
}

0 comments on commit e460245

Please sign in to comment.