Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unused import when referenced by import #115

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/main/kotlin/com/emberjs/gts/GtsReferenceSearcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ package com.emberjs.gts
import com.dmarcotte.handlebars.parsing.HbTokenTypes
import com.dmarcotte.handlebars.psi.HbPsiElement
import com.emberjs.psi.EmberNamedElement
import com.emberjs.utils.ifTrue
import com.intellij.lang.ecmascript6.psi.ES6ImportSpecifier
import com.intellij.lang.javascript.psi.JSPsiNamedElementBase
import com.intellij.lang.javascript.psi.JSVariable
import com.intellij.openapi.application.QueryExecutorBase
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiReference
import com.intellij.psi.html.HtmlTag
import com.intellij.psi.search.LocalSearchScope
import com.intellij.psi.search.RequestResultProcessor
import com.intellij.psi.search.SearchRequestCollector
import com.intellij.psi.search.searches.ReferencesSearch
import com.intellij.psi.util.elementType
import com.intellij.psi.xml.XmlToken
import com.intellij.util.Processor


Expand Down Expand Up @@ -44,12 +47,14 @@ class GtsReferenceSearcher : QueryExecutorBase<PsiReference?, ReferencesSearch.S
}

override fun processTextOccurrence(element: PsiElement, offsetInElement: Int, consumer: Processor<in PsiReference>): Boolean {
return if (element is HbPsiElement && element.elementType == HbTokenTypes.ID) {
var found = element.reference?.isReferenceTo(myQueryParameters.elementToSearch) == true || element.references.any {
it.isReferenceTo(myQueryParameters.elementToSearch)
return if ((element is HbPsiElement && element.elementType == HbTokenTypes.ID) || (element is XmlToken && element.parent is HtmlTag)) {
val elem = (element is XmlToken && element.parent is HtmlTag).ifTrue { element.parent } ?: element
var found = elem.reference?.isReferenceTo(myQueryParameters.elementToSearch) == true || elem.references.any {
it.isReferenceTo(myQueryParameters.elementToSearch)
}

if (!found) {
var resolved = element.reference?.resolve()
var resolved = elem.reference?.resolve()
if (resolved is EmberNamedElement) {
resolved = resolved.target
}
Expand All @@ -62,7 +67,7 @@ class GtsReferenceSearcher : QueryExecutorBase<PsiReference?, ReferencesSearch.S
} ?: false
}
if (!found) {
var resolved = element.references.find { it.resolve() is ES6ImportSpecifier || it.resolve() is EmberNamedElement }?.resolve()
var resolved = elem.references.find { it.resolve() is ES6ImportSpecifier || it.resolve() is EmberNamedElement }?.resolve()
if (resolved is EmberNamedElement) {
resolved = resolved.target
}
Expand Down
Loading