Skip to content

Commit 02c421f

Browse files
committed
fix bad inspections like trailing comma
add test for trailing comma
1 parent 4aa6e92 commit 02c421f

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
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: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.emberjs.index.EmberNameIndex
1313
import com.emberjs.resolver.EmberName
1414
import com.emberjs.utils.EmberUtils
1515
import com.emberjs.utils.ifTrue
16+
import com.intellij.extapi.psi.PsiFileBase
1617
import com.intellij.formatting.*
1718
import com.intellij.formatting.templateLanguages.DataLanguageBlockWrapper
1819
import com.intellij.lang.*
@@ -25,9 +26,11 @@ import com.intellij.lang.javascript.*
2526
import com.intellij.lang.javascript.config.JSImportResolveContext
2627
import com.intellij.lang.javascript.dialects.ECMA6ParserDefinition
2728
import com.intellij.lang.javascript.dialects.TypeScriptParserDefinition
29+
import com.intellij.lang.javascript.ecmascript6.TypeScriptAnnotatingVisitor
2830
import com.intellij.lang.javascript.editing.JavascriptCommenter
2931
import com.intellij.lang.javascript.formatter.JavascriptFormattingModelBuilder
3032
import com.intellij.lang.javascript.highlighting.JSHighlighter
33+
import com.intellij.lang.javascript.highlighting.JSSemanticHighlightingVisitor
3134
import com.intellij.lang.javascript.index.IndexedFileTypeProvider
3235
import com.intellij.lang.javascript.modules.JSImportCandidateDescriptor
3336
import com.intellij.lang.javascript.modules.JSImportPlaceInfo
@@ -41,6 +44,9 @@ import com.intellij.lang.javascript.psi.*
4144
import com.intellij.lang.javascript.psi.ecmal4.JSClass
4245
import com.intellij.lang.javascript.psi.impl.JSFileImpl
4346
import com.intellij.lang.javascript.types.JSFileElementType
47+
import com.intellij.lang.javascript.validation.JSAnnotatingVisitor
48+
import com.intellij.lang.javascript.validation.JSAnnotator
49+
import com.intellij.lang.javascript.validation.TypeScriptKeywordHighlighterVisitor
4450
import com.intellij.lang.typescript.tsconfig.*
4551
import com.intellij.lang.xml.XMLLanguage
4652
import com.intellij.lang.xml.XmlFormattingModel
@@ -49,7 +55,6 @@ import com.intellij.lexer.Lexer
4955
import com.intellij.lexer.LookAheadLexer
5056
import com.intellij.openapi.editor.Document
5157
import com.intellij.openapi.editor.Editor
52-
import com.intellij.openapi.editor.actions.lists.TrailingComma
5358
import com.intellij.openapi.editor.colors.EditorColorsScheme
5459
import com.intellij.openapi.editor.ex.util.LayerDescriptor
5560
import com.intellij.openapi.editor.ex.util.LayeredLexerEditorHighlighter
@@ -58,6 +63,7 @@ import com.intellij.openapi.fileTypes.*
5863
import com.intellij.openapi.project.Project
5964
import com.intellij.openapi.util.IconLoader
6065
import com.intellij.openapi.util.Key
66+
import com.intellij.openapi.util.Pair
6167
import com.intellij.openapi.util.TextRange
6268
import com.intellij.openapi.util.text.StringUtil
6369
import com.intellij.openapi.vfs.VirtualFile
@@ -72,14 +78,19 @@ import com.intellij.psi.formatter.xml.XmlFormattingPolicy
7278
import com.intellij.psi.formatter.xml.XmlTagBlock
7379
import com.intellij.psi.html.HtmlTag
7480
import com.intellij.psi.impl.source.PsiFileImpl
81+
import com.intellij.psi.impl.source.StubbedSpine
7582
import com.intellij.psi.impl.source.html.HtmlDocumentImpl
7683
import com.intellij.psi.impl.source.html.HtmlFileImpl
7784
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference
85+
import com.intellij.psi.impl.source.tree.FileElement
7886
import com.intellij.psi.impl.source.tree.LeafElement
7987
import com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
8088
import com.intellij.psi.search.FilenameIndex
8189
import com.intellij.psi.search.GlobalSearchScope
8290
import com.intellij.psi.search.ProjectScope
91+
import com.intellij.psi.stubs.LanguageStubDescriptor
92+
import com.intellij.psi.stubs.StubElement
93+
import com.intellij.psi.stubs.StubTree
8394
import com.intellij.psi.templateLanguages.*
8495
import com.intellij.psi.tree.IElementType
8596
import com.intellij.psi.tree.IFileElementType
@@ -89,6 +100,7 @@ import com.intellij.refactoring.suggested.endOffset
89100
import com.intellij.refactoring.suggested.startOffset
90101
import com.intellij.util.Processor
91102
import com.intellij.xml.template.formatter.AbstractXmlTemplateFormattingModelBuilder
103+
import org.jetbrains.annotations.Unmodifiable
92104
import java.util.function.Predicate
93105
import javax.swing.Icon
94106

@@ -99,6 +111,7 @@ val JS: JSLanguageDialect = JavaScriptSupportLoader.ECMA_SCRIPT_6
99111

100112
open class GtsLanguage(val lang: JSLanguageDialect = TS, id: String ="Gts") : Language(lang, id) {
101113
public var fileElementType: JSFileElementType? = null
114+
102115
override fun <T : Any?> getUserData(key: Key<T>): T? {
103116
if (key.toString() == "js.file.element.type") {
104117
return fileElementType as T?
@@ -114,7 +127,7 @@ open class GtsLanguage(val lang: JSLanguageDialect = TS, id: String ="Gts") : La
114127
}
115128

116129
companion object {
117-
val INSTANCE = GtsLanguage()
130+
val INSTANCE = GtsLanguage(TS)
118131
}
119132
}
120133

@@ -135,8 +148,6 @@ class GtsFile(viewProvider: FileViewProvider?, val isJS: Boolean =false)
135148
override fun toString(): String {
136149
return "GTS File"
137150
}
138-
139-
140151
}
141152

142153

@@ -397,6 +408,9 @@ class GtsFileType : LanguageFileType(GtsLanguage.INSTANCE) {
397408
if (other == TypeScriptFileType) {
398409
return true
399410
}
411+
if (other == JavaScriptFileType) {
412+
return true
413+
}
400414
return super.equals(other)
401415
}
402416

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)