@@ -23,29 +23,42 @@ import com.intellij.util.Processor
2323
2424
2525class GtsReferenceSearcher : QueryExecutorBase <PsiReference ?, ReferencesSearch .SearchParameters >(true ) {
26- override fun processQuery (queryParameters : ReferencesSearch .SearchParameters , consumer : Processor <in PsiReference ?>) {
26+ override fun processQuery (
27+ queryParameters : ReferencesSearch .SearchParameters ,
28+ consumer : Processor <in PsiReference ?>
29+ ) {
2730 var element = queryParameters.elementToSearch
2831 if (element is JSPsiNamedElementBase ) {
2932 val name = element.name
3033 if (name != null ) {
31- if (element.containingFile is GtsFile ){
32- if (element is JSVariable ) {
33- val psi = element.containingFile.viewProvider.getPsi(JavaScriptSupportLoader .TYPESCRIPT ) ? : element.containingFile.viewProvider.getPsi(JavaScriptSupportLoader .ECMA_SCRIPT_6 )
34- element = psi.findElementAt(element.textOffset)?.parent ? : element
35- }
36- }
37- val effectiveScope = if (element is JSVariable && (queryParameters.effectiveSearchScope as ? LocalSearchScope )?.scope?.size == 1 ) {
38- LocalSearchScope (element.containingFile)
39- } else {
40- queryParameters.effectiveSearchScope
34+ if (element.containingFile is GtsFile ) {
35+ if (element is JSVariable ) {
36+ val psi = element.containingFile.viewProvider.getPsi(JavaScriptSupportLoader .TYPESCRIPT )
37+ ? : element.containingFile.viewProvider.getPsi(JavaScriptSupportLoader .ECMA_SCRIPT_6 )
38+ element = psi.findElementAt(element.textOffset)?.parent ? : element
39+ }
4140 }
41+ val effectiveScope =
42+ if (element is JSVariable && (queryParameters.effectiveSearchScope as ? LocalSearchScope )?.scope?.size == 1 ) {
43+ LocalSearchScope (element.containingFile)
44+ } else {
45+ queryParameters.effectiveSearchScope
46+ }
4247 val collector = queryParameters.optimizer
43- collector.searchWord(name, effectiveScope, 1 .toShort(), true , element, MyProcessor (queryParameters, element))
48+ collector.searchWord(
49+ name,
50+ effectiveScope,
51+ 1 .toShort(),
52+ true ,
53+ element,
54+ MyProcessor (queryParameters, element)
55+ )
4456 }
4557 }
4658 }
4759
48- private class MyProcessor (queryParameters : ReferencesSearch .SearchParameters , elementToSearch : PsiElement ) : RequestResultProcessor() {
60+ private class MyProcessor (queryParameters : ReferencesSearch .SearchParameters , elementToSearch : PsiElement ) :
61+ RequestResultProcessor () {
4962 private val myQueryParameters: ReferencesSearch .SearchParameters
5063 private val myOwnCollector: SearchRequestCollector
5164 private val myElementToSearch: PsiElement
@@ -56,16 +69,21 @@ class GtsReferenceSearcher : QueryExecutorBase<PsiReference?, ReferencesSearch.S
5669 myOwnCollector = SearchRequestCollector (queryParameters.optimizer.searchSession)
5770 }
5871
59- override fun processTextOccurrence (element : PsiElement , offsetInElement : Int , consumer : Processor <in PsiReference >): Boolean {
72+ override fun processTextOccurrence (
73+ element : PsiElement ,
74+ offsetInElement : Int ,
75+ consumer : Processor <in PsiReference >
76+ ): Boolean {
6077 if (myElementToSearch.containingFile is GtsFile ) {
6178 consumer.process(ResolvedReference (myElementToSearch, myElementToSearch))
6279 return false
6380 }
64- return if ((element is HbPsiElement && element.elementType == HbTokenTypes .ID ) || (element is XmlToken && element.parent is HtmlTag )) {
81+ return if ((element is HbPsiElement && element.elementType == HbTokenTypes .ID ) || (element is XmlToken && element.parent is HtmlTag ) || element is HtmlTag ) {
6582 val elem = (element is XmlToken && element.parent is HtmlTag ).ifTrue { element.parent } ? : element
66- var foundRef = (elem.reference?.isReferenceTo(myElementToSearch) == true ).ifTrue { elem.reference } ? : elem.references.find {
67- it.isReferenceTo(myElementToSearch)
68- }
83+ var foundRef = (elem.reference?.isReferenceTo(myElementToSearch) == true ).ifTrue { elem.reference }
84+ ? : elem.references.find {
85+ it.isReferenceTo(myElementToSearch)
86+ }
6987
7088 if (foundRef != null ) {
7189 consumer.process(foundRef)
@@ -83,13 +101,20 @@ class GtsReferenceSearcher : QueryExecutorBase<PsiReference?, ReferencesSearch.S
83101 }
84102 foundRef = (resolved as ? ES6ImportSpecifier )?.let {
85103 val results = it.multiResolve(false )
86- results.find { it.element == myElementToSearch }?.let { ResolvedReference (element, myElementToSearch) }
104+ results.find {
105+ it.element?.containingFile?.viewProvider == myElementToSearch.containingFile.viewProvider &&
106+ it.element?.textOffset == myElementToSearch.textOffset
107+ }?.let { ResolvedReference (element, myElementToSearch) }
108+ ? : results.find { it.element == myElementToSearch }
109+ ?.let { ResolvedReference (element, myElementToSearch) }
87110 }
111+
88112 if (foundRef != null ) {
89113 consumer.process(foundRef)
90114 return false
91115 }
92- val ref = elem.references.find { it.resolve() is ES6ImportSpecifier || it.resolve() is EmberNamedElement }
116+ val ref =
117+ elem.references.find { it.resolve() is ES6ImportSpecifier || it.resolve() is EmberNamedElement }
93118 resolved = ref?.resolve()
94119 if (resolved is EmberNamedElement ) {
95120 resolved = resolved.target
@@ -99,9 +124,9 @@ class GtsReferenceSearcher : QueryExecutorBase<PsiReference?, ReferencesSearch.S
99124 return false
100125 }
101126 val found = (resolved as ? ES6ImportSpecifier )?.let {
102- val results = it.multiResolve(false )
103- results.any { it.element == myElementToSearch }
104- } ? : false
127+ val results = it.multiResolve(false )
128+ results.any { it.element == myElementToSearch }
129+ } ? : false
105130 if (found) {
106131 consumer.process(ref)
107132 }
0 commit comments