Skip to content

Commit bac5218

Browse files
committed
fix unused imports
1 parent bcd2396 commit bac5218

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/main/kotlin/com/emberjs/hbs/HbReference.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package com.emberjs.hbs
33
import com.dmarcotte.handlebars.psi.HbSimpleMustache
44
import com.dmarcotte.handlebars.psi.HbStringLiteral
55
import com.dmarcotte.handlebars.psi.impl.HbStatementsImpl
6+
import com.emberjs.gts.GjsLanguage
7+
import com.emberjs.gts.GtsLanguage
68
import com.emberjs.index.EmberNameIndex
79
import com.emberjs.psi.EmberNamedAttribute
810
import com.emberjs.psi.EmberNamedElement
@@ -11,6 +13,7 @@ import com.emberjs.resolver.EmberName
1113
import com.emberjs.utils.originalVirtualFile
1214
import com.emberjs.xml.EmberAttrDec
1315
import com.intellij.lang.Language
16+
import com.intellij.lang.ecmascript6.psi.ES6ImportSpecifier
1417
import com.intellij.openapi.util.TextRange
1518
import com.intellij.psi.PsiDirectory
1619
import com.intellij.psi.PsiElement
@@ -34,6 +37,28 @@ abstract class HbReference(element: PsiElement): PsiReferenceBase<PsiElement>(el
3437
if (res is EmberNamedElement) {
3538
res = res.target
3639
}
40+
if (res is ES6ImportSpecifier) {
41+
var resolved = res.containingFile.viewProvider.findReferenceAt(res.textOffset, GtsLanguage.INSTANCE)?.resolve()
42+
resolved = resolved ?: res.containingFile.viewProvider.findReferenceAt(res.textOffset, GjsLanguage.INSTANCE)?.resolve()
43+
if (element.manager.areElementsEquivalent(resolved, other)) {
44+
return true
45+
}
46+
if (element.manager.areElementsEquivalent(res.reference?.resolve(), other)) {
47+
return true
48+
}
49+
if (res.references.any {
50+
element.manager.areElementsEquivalent(it.element, other) || super.isReferenceTo(other)
51+
}) {
52+
return true
53+
}
54+
val results = res.multiResolve(false)
55+
val r = results.any {
56+
element.manager.areElementsEquivalent(it.element, other) || super.isReferenceTo(other)
57+
}
58+
if (r) {
59+
return true
60+
}
61+
}
3762
return element.manager.areElementsEquivalent(res, other) || super.isReferenceTo(other)
3863
}
3964
}

src/main/kotlin/com/emberjs/hbs/TagReferencesProvider.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import com.dmarcotte.handlebars.psi.impl.HbStatementsImpl
1212
import com.emberjs.xml.EmberAttrDec
1313
import com.emberjs.xml.EmberXmlElementDescriptor
1414
import com.emberjs.glint.GlintLanguageServiceProvider
15+
import com.emberjs.gts.GjsLanguage
1516
import com.emberjs.gts.GtsFileViewProvider
17+
import com.emberjs.gts.GtsLanguage
1618
import com.emberjs.index.EmberNameIndex
1719
import com.emberjs.psi.EmberNamedAttribute
1820
import com.emberjs.psi.EmberNamedElement
@@ -232,6 +234,11 @@ class TagReference(val element: XmlTag, val fullName: String, val rangeInElem: T
232234
}
233235
}
234236
if (res is ES6ImportSpecifier) {
237+
var resolved = res.containingFile.viewProvider.findReferenceAt(res.textOffset, GtsLanguage.INSTANCE)?.resolve()
238+
resolved = resolved ?: res.containingFile.viewProvider.findReferenceAt(res.textOffset, GjsLanguage.INSTANCE)?.resolve()
239+
if (element.manager.areElementsEquivalent(resolved, other)) {
240+
return true
241+
}
235242
if (element.manager.areElementsEquivalent(res.reference?.resolve(), other)) {
236243
return true
237244
}

src/test/kotlin/com/emberjs/gts/GtsFileTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ class GtsFileTest : BasePlatformTestCase() {
7676
export const other = 2;
7777
""".trimIndent()
7878
val gts = """
79-
import { OtherComponent, other } from './other-component';
79+
import { OtherComponent } from './other-component';
80+
import { other } from './other-component';
8081
import x from "a";
8182
import { y, quux } from "a";
8283
import qux from "a";
@@ -111,7 +112,7 @@ class GtsFileTest : BasePlatformTestCase() {
111112
val unusedConstants = highlighting.filter { it.description?.startsWith("Unused constant") == true }
112113
TestCase.assertEquals(unusedConstants.toString(), 0, unusedConstants.size)
113114
val highlightInfos: List<HighlightInfo> = highlighting.filter { it.inspectionToolId == "ES6UnusedImports" }
114-
TestCase.assertEquals(2, highlightInfos.size)
115+
TestCase.assertEquals(highlightInfos.toString(), 2, highlightInfos.size)
115116
TestCase.assertTrue(highlightInfos.first().description.contains("quux"))
116117
TestCase.assertTrue(highlightInfos.last().description.contains("qux"))
117118
}

0 commit comments

Comments
 (0)