Skip to content

Commit 5bd9e53

Browse files
authored
fix bad inspections like trailing comma (#265)
add test for trailing comma
1 parent 4aa6e92 commit 5bd9e53

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

src/main/kotlin/com/emberjs/glint/GlintLanguageServiceFileEditorListener.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package com.emberjs.glint
22

3+
import com.emberjs.gts.GjsLanguage
4+
import com.emberjs.gts.GtsFileViewProvider
5+
import com.emberjs.gts.GtsLanguage
6+
import com.intellij.codeInsight.daemon.impl.analysis.FileHighlightingSetting
7+
import com.intellij.codeInsight.daemon.impl.analysis.HighlightingSettingsPerFile
38
import com.intellij.openapi.fileEditor.FileEditorManager
49
import com.intellij.openapi.fileEditor.FileEditorManagerListener
510
import com.intellij.openapi.vfs.VirtualFile
11+
import com.intellij.psi.PsiManager
612

713
class GlintLanguageServiceFileEditorListener : FileEditorManagerListener {
814
override fun fileOpened(source: FileEditorManager, file: VirtualFile) {

src/main/kotlin/com/emberjs/gts/GtsSupport.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ import com.intellij.lang.xml.XmlFormattingModel
4747
import com.intellij.lexer.HtmlLexer
4848
import com.intellij.lexer.Lexer
4949
import com.intellij.lexer.LookAheadLexer
50-
import com.intellij.openapi.editor.Document
5150
import com.intellij.openapi.editor.Editor
52-
import com.intellij.openapi.editor.actions.lists.TrailingComma
5351
import com.intellij.openapi.editor.colors.EditorColorsScheme
5452
import com.intellij.openapi.editor.ex.util.LayerDescriptor
5553
import com.intellij.openapi.editor.ex.util.LayeredLexerEditorHighlighter
@@ -99,6 +97,7 @@ val JS: JSLanguageDialect = JavaScriptSupportLoader.ECMA_SCRIPT_6
9997

10098
open class GtsLanguage(val lang: JSLanguageDialect = TS, id: String ="Gts") : Language(lang, id) {
10199
public var fileElementType: JSFileElementType? = null
100+
102101
override fun <T : Any?> getUserData(key: Key<T>): T? {
103102
if (key.toString() == "js.file.element.type") {
104103
return fileElementType as T?
@@ -114,7 +113,7 @@ open class GtsLanguage(val lang: JSLanguageDialect = TS, id: String ="Gts") : La
114113
}
115114

116115
companion object {
117-
val INSTANCE = GtsLanguage()
116+
val INSTANCE = GtsLanguage(TS)
118117
}
119118
}
120119

@@ -135,8 +134,6 @@ class GtsFile(viewProvider: FileViewProvider?, val isJS: Boolean =false)
135134
override fun toString(): String {
136135
return "GTS File"
137136
}
138-
139-
140137
}
141138

142139

@@ -397,6 +394,9 @@ class GtsFileType : LanguageFileType(GtsLanguage.INSTANCE) {
397394
if (other == TypeScriptFileType) {
398395
return true
399396
}
397+
if (other == JavaScriptFileType) {
398+
return true
399+
}
400400
return super.equals(other)
401401
}
402402

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package com.emberjs.hbs
33
import com.emberjs.gts.GjsFileType
44
import com.emberjs.gts.GtsFileType
55
import com.intellij.codeInsight.daemon.impl.HighlightInfo
6+
import com.intellij.lang.javascript.BasicDialectDetector
7+
import com.intellij.lang.javascript.JavaScriptSupportLoader
68
import com.intellij.lang.javascript.inspections.ES6UnusedImportsInspection
9+
import com.intellij.lang.javascript.inspections.JSLastCommaInObjectLiteralInspection
710
import com.intellij.lang.javascript.inspections.JSUnusedGlobalSymbolsInspection
811
import com.intellij.lang.javascript.inspections.JSUnusedLocalSymbolsInspection
912
import com.intellij.lang.javascript.psi.impl.JSFileImpl
@@ -121,4 +124,27 @@ class GtsFileTest : BasePlatformTestCase() {
121124
TestCase.assertTrue(highlightInfos.first().description.contains("quux"))
122125
TestCase.assertTrue(highlightInfos.last().description.contains("qux"))
123126
}
127+
128+
@Test
129+
fun testGtsTrailingCommaAllowed() {
130+
val gts = """
131+
const a = {
132+
a: 1,
133+
b: 2,
134+
}
135+
""".trimIndent()
136+
myFixture.addFileToProject("main.gts", gts)
137+
myFixture.configureByFile("main.gts")
138+
myFixture.enableInspections(JSLastCommaInObjectLiteralInspection())
139+
try {
140+
CodeInsightTestFixtureImpl.ensureIndexesUpToDate(project)
141+
} catch (exception: Exception) {
142+
143+
}
144+
145+
val highlighting = myFixture.doHighlighting()
146+
System.out.println(highlighting)
147+
val noCommaAllowed = highlighting.filter { it.description?.contains("comma") == true }
148+
TestCase.assertEquals(noCommaAllowed.toString(), 0, noCommaAllowed.size)
149+
}
124150
}

0 commit comments

Comments
 (0)