Skip to content

Commit 364620c

Browse files
committed
fix unused imports
1 parent f1ab56b commit 364620c

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.emberjs.utils.originalVirtualFile
2323
import com.intellij.injected.editor.VirtualFileWindow
2424
import com.intellij.lang.Language
2525
import com.intellij.lang.ecmascript6.psi.ES6ImportDeclaration
26+
import com.intellij.lang.ecmascript6.psi.ES6ImportSpecifier
2627
import com.intellij.lang.injection.InjectedLanguageManager
2728
import com.intellij.lang.javascript.JavaScriptSupportLoader
2829
import com.intellij.lang.javascript.psi.JSObjectLiteralExpression
@@ -226,6 +227,26 @@ class TagReference(val element: XmlTag, val fullName: String, val rangeInElem: T
226227
var res = resolve()
227228
if (res is EmberNamedElement) {
228229
res = res.target
230+
if (element.manager.areElementsEquivalent(res, other) || super.isReferenceTo(other)) {
231+
return true
232+
}
233+
}
234+
if (res is ES6ImportSpecifier) {
235+
if (element.manager.areElementsEquivalent(res.reference?.resolve(), other)) {
236+
return true
237+
}
238+
if (res.references.any {
239+
element.manager.areElementsEquivalent(it.element, other) || super.isReferenceTo(other)
240+
}) {
241+
return true
242+
}
243+
val results = res.multiResolve(false)
244+
val r = results.any {
245+
element.manager.areElementsEquivalent(it.element, other) || super.isReferenceTo(other)
246+
}
247+
if (r) {
248+
return true
249+
}
229250
}
230251
return element.manager.areElementsEquivalent(res, other) || super.isReferenceTo(other)
231252
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ class GtsFileTest : BasePlatformTestCase() {
7171

7272
@Test
7373
fun testGtsImportUsed() {
74+
val otherGts = """
75+
export const OtherComponent = 2;
76+
export const other = 2;
77+
""".trimIndent()
7478
val gts = """
79+
import { OtherComponent, other } from './other-component';
7580
import x from "a";
7681
import { y, quux } from "a";
7782
import qux from "a";
@@ -85,24 +90,28 @@ class GtsFileTest : BasePlatformTestCase() {
8590
export const Grault = {};
8691
8792
export default <template>
93+
<OtherComponent />
8894
<Foo />
8995
<Baz />
9096
<Grault />
9197
{{x}}
9298
{{y}}
9399
{{bar}}
94100
{{grault}}
101+
{{other}}
95102
</template>
96103
""".trimIndent()
97-
myFixture.configureByText(GtsFileType.INSTANCE, gts)
104+
myFixture.addFileToProject("other-component.ts", otherGts)
105+
myFixture.addFileToProject("main.gts", gts)
106+
myFixture.configureByFile("main.gts")
98107
myFixture.enableInspections(ES6UnusedImportsInspection(), JSUnusedLocalSymbolsInspection(), JSUnusedGlobalSymbolsInspection())
99108
CodeInsightTestFixtureImpl.ensureIndexesUpToDate(project)
100109
val highlighting = myFixture.doHighlighting()
101110
System.out.println(highlighting)
102111
val unusedConstants = highlighting.filter { it.description?.startsWith("Unused constant") == true }
103112
TestCase.assertEquals(unusedConstants.toString(), 0, unusedConstants.size)
104113
val highlightInfos: List<HighlightInfo> = highlighting.filter { it.inspectionToolId == "ES6UnusedImports" }
105-
TestCase.assertEquals(highlightInfos.size, 2)
114+
TestCase.assertEquals(2, highlightInfos.size)
106115
TestCase.assertTrue(highlightInfos.first().description.contains("quux"))
107116
TestCase.assertTrue(highlightInfos.last().description.contains("qux"))
108117
}

0 commit comments

Comments
 (0)