Skip to content

Commit 001a808

Browse files
committed
## 2023.1.51
- feature: support gjs files
1 parent 34b173d commit 001a808

File tree

8 files changed

+124
-20
lines changed

8 files changed

+124
-20
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
Changelog
44
===============================================================================
5+
## 2023.1.51
6+
- feature: support gjs files
7+
58
## 2023.1.50
69
- feature: warn if gts file is not included in tsconfig
710
- feature: add back typescript actions

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212

1313

1414
group = "com.emberjs"
15-
version = "2023.1.50"
15+
version = "2023.1.51"
1616

1717
// Configure project's dependencies
1818
repositories {

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

Lines changed: 98 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,28 @@ import java.util.function.Predicate
8383
import javax.swing.Icon
8484

8585
val TS: JSLanguageDialect = JavaScriptSupportLoader.TYPESCRIPT
86+
val JS: Language = JavaScriptSupportLoader.JAVASCRIPT.language
8687

87-
class GtsLanguage : Language(TS, "Gts") {
88+
89+
90+
open class GtsLanguage(val lang: JSLanguageDialect = TS, id: String ="Gts") : Language(lang, id) {
8891

8992
companion object {
9093
val INSTANCE = GtsLanguage()
9194
}
9295
}
9396

94-
class GtsFile(viewProvider: FileViewProvider?) : JSFileImpl(viewProvider!!, GtsLanguage.INSTANCE) {
97+
class GjsLanguage(): GtsLanguage(JavascriptLanguage.INSTANCE, "Gjs") {
98+
companion object {
99+
val INSTANCE = GjsLanguage()
100+
}
101+
}
102+
103+
104+
class GtsFile(viewProvider: FileViewProvider?, val isJS: Boolean =false)
105+
: JSFileImpl(viewProvider!!, isJS.ifTrue { GjsLanguage.INSTANCE } ?: GtsLanguage.INSTANCE) {
95106
override fun getFileType(): FileType {
96-
return GtsFileType.INSTANCE
107+
return isJS.ifTrue { GjsFileType.INSTANCE } ?: GtsFileType.INSTANCE
97108
}
98109

99110
override fun toString(): String {
@@ -200,12 +211,36 @@ class GtsElementTypes {
200211
return node.firstChildNode ?: PsiWhiteSpaceImpl("")
201212
}
202213
}
214+
val GJS_FILE_NODE_TYPE = object : IFileElementType("GJS", GjsLanguage.INSTANCE) {
215+
override fun equals(other: Any?): Boolean {
216+
if (other == JavaScriptFileType.INSTANCE) {
217+
return true
218+
}
219+
return super.equals(other)
220+
}
221+
222+
override fun hashCode(): Int {
223+
return JavaScriptFileType.INSTANCE.hashCode()
224+
}
225+
226+
override fun doParseContents(chameleon: ASTNode, psi: PsiElement): ASTNode {
227+
val project = psi.project
228+
val languageForParser = getLanguageForParser(psi)
229+
val builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, null, languageForParser, chameleon.chars)
230+
val parser = GjsParserDefinition().createParser(project)
231+
val node = parser.parse(this, builder)
232+
return node.firstChildNode ?: PsiWhiteSpaceImpl("")
233+
}
234+
}
203235
}
204236
}
205237

206-
class GtsParserDefinition : TypeScriptParserDefinition() {
238+
open class GtsParserDefinition(val isJS: Boolean = false) : TypeScriptParserDefinition() {
207239

208240
override fun getFileNodeType(): IFileElementType {
241+
if (isJS) {
242+
return GtsElementTypes.GJS_FILE_NODE_TYPE
243+
}
209244
return GtsElementTypes.GTS_FILE_NODE_TYPE
210245
}
211246

@@ -228,11 +263,15 @@ class GtsParserDefinition : TypeScriptParserDefinition() {
228263
}
229264

230265
override fun createFile(viewProvider: FileViewProvider): JSFile {
231-
return GtsFile(viewProvider)
266+
if (viewProvider.baseLanguage.id == GjsLanguage.INSTANCE.id) {
267+
return GtsFile(viewProvider, true)
268+
}
269+
return GtsFile(viewProvider, isJS)
232270
}
233-
234271
}
235272

273+
class GjsParserDefinition: GtsParserDefinition(true)
274+
236275

237276
internal object GtsIcons {
238277
val icon: Icon = IconLoader.getIcon("/com/emberjs/icons/glimmer.svg", GtsIcons::class.java)
@@ -336,14 +375,50 @@ class GtsFileType : LanguageFileType(GtsLanguage.INSTANCE) {
336375
}
337376
}
338377

378+
class GjsFileType : LanguageFileType(GjsLanguage.INSTANCE) {
379+
380+
override fun equals(other: Any?): Boolean {
381+
if (other == JavaScriptFileType.INSTANCE) {
382+
return true
383+
}
384+
return super.equals(other)
385+
}
386+
387+
companion object {
388+
val INSTANCE = GjsFileType()
389+
}
390+
391+
override fun getName(): String {
392+
return "Gjs File"
393+
}
394+
395+
override fun getDescription(): String {
396+
return "Gjs file type"
397+
}
398+
399+
override fun getDefaultExtension(): String {
400+
return "gjs"
401+
}
402+
403+
override fun getIcon(): Icon {
404+
return GtsIcons.icon
405+
}
406+
407+
override fun hashCode(): Int {
408+
return javaClass.hashCode()
409+
}
410+
}
411+
339412
class GtsFileViewProviderFactory: FileViewProviderFactory {
340413
override fun createFileViewProvider(file: VirtualFile, language: Language?, manager: PsiManager, eventSystemEnabled: Boolean): FileViewProvider {
341-
return GtsFileViewProvider(manager, file, eventSystemEnabled)
414+
return (language as? GtsLanguage)
415+
?.let { GtsFileViewProvider(manager, file, eventSystemEnabled, it) }
416+
?: GtsFileViewProvider(manager, file, eventSystemEnabled)
342417
}
343418

344419
}
345420

346-
class GtsFileViewProvider(manager: PsiManager, virtualFile: VirtualFile, eventSystemEnabled: Boolean) : MultiplePsiFilesPerDocumentFileViewProvider(manager, virtualFile, eventSystemEnabled), TemplateLanguageFileViewProvider {
421+
class GtsFileViewProvider(manager: PsiManager, virtualFile: VirtualFile, eventSystemEnabled: Boolean, private val baseLang: GtsLanguage = GtsLanguage.INSTANCE) : MultiplePsiFilesPerDocumentFileViewProvider(manager, virtualFile, eventSystemEnabled), TemplateLanguageFileViewProvider {
347422

348423

349424
override fun findElementAt(offset: Int): PsiElement? {
@@ -355,10 +430,13 @@ class GtsFileViewProvider(manager: PsiManager, virtualFile: VirtualFile, eventSy
355430
}
356431

357432
override fun getBaseLanguage(): Language {
358-
return GtsLanguage.INSTANCE
433+
return baseLang
359434
}
360435

361436
override fun getLanguages(): MutableSet<Language> {
437+
if (baseLang == GjsLanguage.INSTANCE) {
438+
return mutableSetOf(HTMLLanguage.INSTANCE, HbLanguage.INSTANCE, JavascriptLanguage.INSTANCE, GjsLanguage.INSTANCE)
439+
}
362440
return mutableSetOf(HTMLLanguage.INSTANCE, HbLanguage.INSTANCE, TS, GtsLanguage.INSTANCE)
363441
}
364442

@@ -367,18 +445,26 @@ class GtsFileViewProvider(manager: PsiManager, virtualFile: VirtualFile, eventSy
367445
}
368446

369447
override fun cloneInner(virtualFile: VirtualFile): MultiplePsiFilesPerDocumentFileViewProvider {
370-
return GtsFileViewProvider(this.manager, virtualFile, false)
448+
return GtsFileViewProvider(this.manager, virtualFile, false, baseLang)
371449
}
372450

373451
override fun createFile(lang: Language): PsiFile? {
374452
if (lang.id == GtsLanguage.INSTANCE.id) {
375453
return GtsParserDefinition().createFile(this)
376454
}
455+
if (lang.id == GjsLanguage.INSTANCE.id) {
456+
return GjsParserDefinition().createFile(this)
457+
}
377458
if (lang.id == TS.id) {
378459
val f = TypeScriptParserDefinition().createFile(this)
379460
(f as PsiFileImpl).contentElementType = GtsFileElementType.INSTANCE
380461
return f
381462
}
463+
if (lang.id == JavascriptLanguage.INSTANCE.id) {
464+
val f = JavascriptParserDefinition().createFile(this)
465+
(f as PsiFileImpl).contentElementType = GtsFileElementType.INSTANCE
466+
return f
467+
}
382468
if (lang.id == HTMLLanguage.INSTANCE.id) {
383469
val f = HTMLParserDefinition().createFile(this)
384470
(f as PsiFileImpl).contentElementType = GtsElementTypes.HTML_CONTENT_ELEMENT_TYPE
@@ -839,9 +925,9 @@ class GtsFormattingModelBuilder : AbstractXmlTemplateFormattingModelBuilder() {
839925

840926
var element = formattingContext.psiElement.containingFile.findElementAt(formattingContext.formattingRange.startOffset) ?: formattingContext.psiElement
841927
if (formattingContext.psiElement is PsiFile && formattingContext.formattingRange.startOffset == 0) {
842-
element = formattingContext.containingFile.viewProvider.getPsi(TS)
928+
element = formattingContext.containingFile.viewProvider.getPsi(TS) ?: formattingContext.containingFile.viewProvider.getPsi(JS)
843929
}
844-
val tsFile = formattingContext.containingFile.viewProvider.getPsi(TS)
930+
val tsFile = formattingContext.containingFile.viewProvider.getPsi(TS) ?: formattingContext.containingFile.viewProvider.getPsi(JS)
845931
val m = jsModelBuilder.createModel(formattingContext.withPsiElement(tsFile))
846932
val jsModel = JavascriptFormattingModelBuilder.createJSFormattingModel(tsFile, formattingContext.codeStyleSettings, JSAstBlockWrapper(m.rootBlock as ASTBlock, null, null))
847933
if (element.language is JSLanguageDialect) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class FakeJsElement(val element: PsiElement): PsiElement by element {
6363
}
6464

6565
override fun getContainingFile(): PsiFile {
66-
return element.containingFile.viewProvider.getPsi(JavaScriptSupportLoader.TYPESCRIPT)
66+
return element.containingFile.viewProvider.getPsi(JavaScriptSupportLoader.TYPESCRIPT) ?: element.containingFile.viewProvider.getPsi(JavaScriptSupportLoader.JAVASCRIPT.language)
6767
}
6868

6969
override fun getReference(): PsiReference {
@@ -170,7 +170,7 @@ class HbLintAnnotator() : Annotator {
170170
fun getCandidates(file: PsiFile, name: String): MutableList<JSImportCandidate> {
171171
val candidates = mutableListOf<JSImportCandidate>()
172172
ApplicationManager.getApplication().runReadAction {
173-
val tsFile = file.viewProvider.getPsi(JavaScriptSupportLoader.TYPESCRIPT) ?: return@runReadAction
173+
val tsFile = file.viewProvider.getPsi(JavaScriptSupportLoader.TYPESCRIPT) ?: file.viewProvider.getPsi(JavaScriptSupportLoader.JAVASCRIPT.language) ?: return@runReadAction
174174
val keyFilter = Predicate { n: String? -> n?.startsWith(name) == true }
175175
val info = JSImportPlaceInfo(tsFile)
176176
val providers = JSImportCandidatesProvider.getProviders(info)
@@ -188,7 +188,7 @@ class HbLintAnnotator() : Annotator {
188188
return
189189
}
190190

191-
val tsFile = file.viewProvider.getPsi(JavaScriptSupportLoader.TYPESCRIPT)
191+
val tsFile = file.viewProvider.getPsi(JavaScriptSupportLoader.TYPESCRIPT) ?: file.viewProvider.getPsi(JavaScriptSupportLoader.JAVASCRIPT.language)
192192
if (element is XmlTag && element.reference?.resolve() == null) {
193193
val candidates = tsFile?.let { getCandidates(file, element.name) }
194194
val nameElement = element.children.find { it.elementType == XmlTokenType.XML_NAME } ?: return

src/main/kotlin/com/emberjs/lookup/HbsInsertHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class HbsInsertHandler : InsertHandler<LookupElement> {
3838
}
3939

4040
if (context.file.viewProvider is GtsFileViewProvider) {
41-
val tsFile = context.file.viewProvider.getPsi(JavaScriptSupportLoader.TYPESCRIPT)
41+
val tsFile = context.file.viewProvider.getPsi(JavaScriptSupportLoader.TYPESCRIPT) ?: context.file.viewProvider.getPsi(JavaScriptSupportLoader.JAVASCRIPT.language)
4242
if (candidate != null) {
4343
context.commitDocument()
4444
JSImportCandidateWithExecutor(candidate, ES6AddImportExecutor(tsFile)).execute()

src/main/kotlin/com/emberjs/utils/EmberUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class EmberUtils {
218218
fun findDefaultExportClass(f: PsiFile): JSClass? {
219219
var file = f
220220
if (file is GtsFile) {
221-
file = file.viewProvider.getPsi(JavaScriptSupportLoader.TYPESCRIPT)
221+
file = file.viewProvider.getPsi(JavaScriptSupportLoader.TYPESCRIPT) ?: file.viewProvider.getPsi(JavaScriptSupportLoader.JAVASCRIPT.language)
222222
}
223223
val exp = ES6PsiUtil.findDefaultExport(file)
224224
var cls: Any? = exp?.children?.find { it is JSClass }

src/main/kotlin/com/emberjs/xml/EmberTagNameProvider.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ class EmberTagNameProvider : XmlTagNameProvider {
262262
}
263263

264264
fun forGtsFiles(tag: XmlTag, lookupElements: MutableList<LookupElement>) {
265-
val info = JSImportPlaceInfo(tag.originalElement.containingFile.viewProvider.getPsi(JavaScriptSupportLoader.TYPESCRIPT))
265+
val info = JSImportPlaceInfo(
266+
tag.originalElement.containingFile.viewProvider.getPsi(JavaScriptSupportLoader.TYPESCRIPT)
267+
?: tag.originalElement.containingFile.viewProvider.getPsi(JavaScriptSupportLoader.JAVASCRIPT.language)
268+
)
266269
val tagName = tag.name.replace("IntellijIdeaRulezzz", "")
267270
val keyFilter = Predicate { name: String? -> name?.first()?.isUpperCase() == true && name.contains(tagName) }
268271
val providers = JSImportCandidatesProvider.getProviders(info)
@@ -276,6 +279,7 @@ class EmberTagNameProvider : XmlTagNameProvider {
276279
.withInsertHandler(object : InsertHandler<LookupElement> {
277280
override fun handleInsert(context: InsertionContext, item: LookupElement) {
278281
val tsFile = context.file.viewProvider.getPsi(JavaScriptSupportLoader.TYPESCRIPT)
282+
?: context.file.viewProvider.getPsi(JavaScriptSupportLoader.JAVASCRIPT.language)
279283
val action = JSImportAction(context.editor, tag, name!!)
280284
val candidateWithExecutors = JSImportCandidateWithExecutor.sortWithExecutors(candidate, tsFile)
281285
if (candidateWithExecutors.size == 1) {

src/main/resources/META-INF/plugin.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<li>Handlebars parameter hints for helpers/modifiers and components</li>
2424
<li>Handlebars renaming for mustache ids and html tags</li>
2525
<li>Glint Support</li>
26-
<li>Gts Support</li>
26+
<li>Gts/Gjs Support</li>
2727
<li>Find Usage between Js/Ts and Hbs</li>
2828
</ul>
2929
]]></description>
@@ -52,16 +52,27 @@
5252

5353
<extensions defaultExtensionNs="com.intellij">
5454
<lang.fileViewProviderFactory language="Gts" implementationClass="com.emberjs.gts.GtsFileViewProviderFactory"/>
55+
<lang.fileViewProviderFactory language="Gjs" implementationClass="com.emberjs.gts.GtsFileViewProviderFactory"/>
5556
<editorHighlighterProvider filetype="Gts File" implementationClass="com.emberjs.gts.GtsHighlighterProvider"/>
57+
<editorHighlighterProvider filetype="Gjs File" implementationClass="com.emberjs.gts.GtsHighlighterProvider"/>
5658
<lang.parserDefinition
5759
language="Gts"
5860
implementationClass="com.emberjs.gts.GtsParserDefinition"/>
61+
<lang.parserDefinition
62+
language="Gjs"
63+
implementationClass="com.emberjs.gts.GjsParserDefinition"/>
5964
<fileType
6065
name="Gts File"
6166
implementationClass="com.emberjs.gts.GtsFileType"
6267
fieldName="INSTANCE"
6368
language="Gts"
6469
extensions="gts"/>
70+
<fileType
71+
name="Gjs File"
72+
implementationClass="com.emberjs.gts.GjsFileType"
73+
fieldName="INSTANCE"
74+
language="Gjs"
75+
extensions="gjs"/>
6576
<lang.syntaxHighlighterFactory
6677
language="Gts"
6778
implementationClass="com.emberjs.gts.GtsSyntaxHighlighterFactory"/>

0 commit comments

Comments
 (0)