Skip to content

Commit 12e6e77

Browse files
authored
support glint (#13)
1 parent 009e821 commit 12e6e77

26 files changed

+809
-116
lines changed

build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ plugins {
55
// Java support
66
id("java")
77
// Kotlin support
8-
id("org.jetbrains.kotlin.jvm") version "1.6.20"
8+
id("org.jetbrains.kotlin.jvm") version "1.6.21"
99
// gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
10-
id("org.jetbrains.intellij") version "1.7.0"
10+
id("org.jetbrains.intellij") version "1.9.0"
1111
}
1212

1313

1414

1515
group = "com.emberjs"
16-
version = "2022.2.10"
16+
version = "2022.2.11"
1717

1818
// Configure project's dependencies
1919
repositories {
@@ -69,4 +69,4 @@ tasks.test {
6969

7070
tasks.buildSearchableOptions {
7171
enabled = false
72-
}
72+
}

src/main/kotlin/com/emberjs/EmberAttrDec.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class EmberAttrDec(private val descriptor: EmberAttributeDescriptor, ref: PsiRef
102102
}
103103

104104
override fun getTextOffset(): Int {
105-
return descriptor.context.attributes.find { it.descriptor == descriptor }!!.textOffset
105+
return descriptor.context.attributes.find { it.descriptor == descriptor }?.textOffset ?: -1
106106
}
107107

108108
override fun getText(): String {

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,18 @@ import com.emberjs.psi.EmberNamedElement
1515
import com.emberjs.resolver.EmberName
1616
import com.emberjs.utils.EmberUtils
1717
import com.emberjs.utils.originalVirtualFile
18-
import com.emberjs.utils.parentModule
1918
import com.intellij.codeInsight.completion.PrioritizedLookupElement
2019
import com.intellij.codeInsight.lookup.LookupElement
2120
import com.intellij.codeInsight.lookup.LookupElementBuilder
2221
import com.intellij.injected.editor.VirtualFileWindow
2322
import com.intellij.javascript.nodejs.reference.NodeModuleManager
2423
import com.intellij.lang.Language
2524
import com.intellij.lang.ecmascript6.resolve.ES6PsiUtil
26-
import com.intellij.lang.javascript.completion.JSCompletionContributor
27-
import com.intellij.lang.javascript.completion.JSCompletionUtil
28-
import com.intellij.lang.javascript.psi.util.JSUtils
2925
import com.intellij.openapi.util.Key
3026
import com.intellij.psi.PsiElement
3127
import com.intellij.psi.PsiManager
3228
import com.intellij.psi.PsiNameIdentifierOwner
33-
import com.intellij.psi.impl.source.html.HtmlFileImpl
3429
import com.intellij.psi.impl.source.tree.LeafPsiElement
35-
import com.intellij.psi.search.LocalSearchScope
3630
import com.intellij.psi.search.ProjectScope
3731
import com.intellij.psi.util.PsiTreeUtil
3832
import com.intellij.psi.util.elementType
@@ -107,7 +101,7 @@ class EmberTagNameProvider : XmlTagNameProvider {
107101
return
108102
}
109103

110-
val dereferenceYield = EmberUtils.findTagYield(anything)
104+
val dereferenceYield = EmberUtils.findTagYieldAttribute(anything)
111105
if (dereferenceYield != null) {
112106
val name = (anything as EmberAttrDec).name.replace("|", "")
113107
val angleBracketBlock = anything.context

src/main/kotlin/com/emberjs/EmberXmlElementDescriptor.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import com.intellij.lang.injection.InjectedLanguageManager
88
import com.intellij.lang.javascript.psi.JSFile
99
import com.intellij.lang.javascript.psi.JSNamedElement
1010
import com.intellij.lang.javascript.psi.ecma6.JSStringTemplateExpression
11+
import com.intellij.lang.javascript.psi.ecma6.JSTypedEntity
1112
import com.intellij.psi.*
1213
import com.intellij.psi.impl.source.html.dtd.HtmlNSDescriptorImpl
1314
import com.intellij.psi.impl.source.xml.XmlDescriptorUtil
15+
import com.intellij.psi.search.ProjectScope
1416
import com.intellij.psi.util.PsiTreeUtil
1517
import com.intellij.psi.xml.XmlAttribute
1618
import com.intellij.psi.xml.XmlTag
@@ -21,7 +23,7 @@ import com.intellij.xml.XmlNSDescriptor
2123

2224

2325

24-
class EmberXmlElementDescriptor(private val tag: XmlTag, private val declaration: PsiElement) : XmlElementDescriptor {
26+
class EmberXmlElementDescriptor(private val tag: XmlTag, private val declaration: PsiElement?) : XmlElementDescriptor {
2527
val project = tag.project
2628
val version = "v2022.1.11"
2729

@@ -79,17 +81,23 @@ class EmberXmlElementDescriptor(private val tag: XmlTag, private val declaration
7981
fun getReferenceData(): ComponentReferenceData {
8082
var f: PsiFile? = null
8183
// if it references a block param
82-
val target: PsiElement
84+
val target: PsiElement?
8385
if (this.declaration is EmberNamedElement) {
8486
target = this.declaration.target
8587
} else {
8688
target = this.declaration
8789
}
90+
if (target == null) {
91+
return ComponentReferenceData()
92+
}
8893
val followed = EmberUtils.followReferences(target)
8994
if (followed is JSNamedElement || followed is JSFile) {
9095
return EmberUtils.getComponentReferenceData(followed)
9196
}
9297
val file = f ?: target.containingFile.originalFile
98+
if (this.tag.containingFile.virtualFile.path == file.virtualFile.path) {
99+
return ComponentReferenceData()
100+
}
93101

94102
if (file.name == "intellij-emberjs/internal/components-stub") {
95103
return EmberUtils.getComponentReferenceData(target)
@@ -107,7 +115,7 @@ class EmberXmlElementDescriptor(private val tag: XmlTag, private val declaration
107115
val data = getReferenceData()
108116
val attributes = data.args.map { EmberAttributeDescriptor(context, it.value, false, it.description, it.reference, null) }
109117
result.addAll(attributes)
110-
if (data.hasSplattributes) {
118+
if (data.hasSplattributes || this.declaration == null) {
111119
result.addAll(commonHtmlAttributes)
112120
}
113121
return result.toTypedArray()

src/main/kotlin/com/emberjs/cli/EmberCliFrameworkDetector.kt

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
package com.emberjs.cli
22

3-
import com.emberjs.EmberTagNameProvider
4-
import com.emberjs.utils.*
3+
4+
import com.emberjs.glint.getGlintDescriptor
5+
import com.emberjs.utils.emberRoot
6+
import com.emberjs.utils.isEmber
57
import com.intellij.framework.FrameworkType
68
import com.intellij.framework.detection.DetectedFrameworkDescription
79
import com.intellij.framework.detection.FileContentPattern
810
import com.intellij.framework.detection.FrameworkDetectionContext
911
import com.intellij.framework.detection.FrameworkDetector
1012
import com.intellij.ide.projectView.actions.MarkRootActionBase
11-
import com.intellij.javascript.nodejs.PackageJsonData
12-
import com.intellij.javascript.nodejs.library.NodeModulesDirectoryChecker
13-
import com.intellij.javascript.nodejs.library.NodeModulesDirectoryManager
1413
import com.intellij.javascript.nodejs.packageJson.PackageJsonFileManager
15-
import com.intellij.javascript.nodejs.reference.NodeModuleManager
1614
import com.intellij.json.JsonFileType
17-
import com.intellij.lang.javascript.JavaScriptFileType
18-
import com.intellij.lang.javascript.frameworks.react.ReactXmlExtension
15+
import com.intellij.openapi.application.ApplicationManager
1916
import com.intellij.openapi.fileTypes.FileType
20-
import com.intellij.openapi.fileTypes.PlainTextFileType
2117
import com.intellij.openapi.module.ModuleUtilCore
2218
import com.intellij.openapi.project.Project
2319
import com.intellij.openapi.roots.ModifiableModelsProvider
@@ -30,9 +26,6 @@ import com.intellij.patterns.ElementPattern
3026
import com.intellij.patterns.PatternCondition
3127
import com.intellij.util.ProcessingContext
3228
import com.intellij.util.indexing.FileContent
33-
import com.intellij.xml.DefaultXmlExtension
34-
import com.intellij.xml.XmlExtension
35-
import com.intellij.xml.XmlTagNameProvider
3629

3730
class EmberCliFrameworkDetector : FrameworkDetector("Ember", 2) {
3831
/** Use package json keys to detect ember */
@@ -62,33 +55,36 @@ class EmberCliFrameworkDetector : FrameworkDetector("Ember", 2) {
6255
.forEach { module ->
6356
val p = modifiableModelsProvider.getModuleModifiableModel(module).project
6457
p.messageBus.connect().subscribe(PackageJsonFileManager.TOPIC, PackageJsonFileManager.PackageJsonChangeListener {
65-
val model = modifiableModelsProvider.getModuleModifiableModel(module)
66-
val entry = MarkRootActionBase.findContentEntry(model, rootDir)
67-
if (entry != null) {
68-
val e = MarkRootActionBase.findContentEntry(model, rootDir)!!
69-
rootDir.findChild("node_modules")?.children?.forEach {
70-
if (it.name.contains("ember")) {
71-
(e.rootModel as ModifiableRootModel).addContentEntry(it.url)
72-
}
73-
if (it.name.contains("@types")) {
74-
(e.rootModel as ModifiableRootModel).addContentEntry(it.url)
75-
}
76-
if (it.name.contains("glimmer")) {
77-
(e.rootModel as ModifiableRootModel).addContentEntry(it.url)
58+
ApplicationManager.getApplication().invokeLater {
59+
ApplicationManager.getApplication().runWriteAction()
60+
{
61+
val model = modifiableModelsProvider.getModuleModifiableModel(module)
62+
val entry = MarkRootActionBase.findContentEntry(model, rootDir)
63+
if (entry != null) {
64+
val e = MarkRootActionBase.findContentEntry(model, rootDir)!!
65+
rootDir.findChild("node_modules")!!.children.forEach {
66+
if (it.name.contains("ember")) {
67+
(e.rootModel as ModifiableRootModel).addContentEntry(it.url)
68+
}
69+
if (it.name.contains("@types")) {
70+
(e.rootModel as ModifiableRootModel).addContentEntry(it.url)
71+
}
72+
if (it.name.contains("glimmer")) {
73+
(e.rootModel as ModifiableRootModel).addContentEntry(it.url)
74+
}
75+
}
76+
modifiableModelsProvider.commitModuleModifiableModel(model)
77+
} else {
78+
modifiableModelsProvider.disposeModuleModifiableModel(model)
7879
}
7980
}
80-
modifiableModelsProvider.commitModuleModifiableModel(model)
81-
} else {
82-
modifiableModelsProvider.disposeModuleModifiableModel(model)
8381
}
8482
})
8583
}
8684
}
8785

8886
override fun detect(newFiles: MutableCollection<out VirtualFile>, context: FrameworkDetectionContext): MutableList<out DetectedFrameworkDescription> {
89-
XmlExtension.EP_NAME.point.unregisterExtensions({it !is DefaultXmlExtension })
90-
XmlTagNameProvider.EP_NAME.point.unregisterExtensions({ it !is ReactXmlExtension && it !is EmberTagNameProvider })
91-
newFiles.removeIf { createSuitableFilePattern().accepts(it) }
87+
newFiles.removeIf { !it.path.endsWith("package.json") || it.parent != it.emberRoot || !it.parent.isEmber }
9288
val rootDir = newFiles.firstOrNull()?.parent
9389

9490
if (rootDir != null && !isConfigured(newFiles, context.project)) {
@@ -97,6 +93,7 @@ class EmberCliFrameworkDetector : FrameworkDetector("Ember", 2) {
9793
// setup reconfigure on package.json change.
9894
val modulesProvider = DefaultModulesProvider.createForProject(context.project)
9995
listenNodeModules(rootDir, modulesProvider)
96+
getGlintDescriptor(context.project!!).server.start()
10097
}
10198
return mutableListOf()
10299
}
@@ -128,6 +125,7 @@ class EmberCliFrameworkDetector : FrameworkDetector("Ember", 2) {
128125
val entry = MarkRootActionBase.findContentEntry(model, root)
129126
if (entry != null) {
130127
EmberCliProjectConfigurator.setupEmber(model.project, entry, root)
128+
getGlintDescriptor(model.project).server.start()
131129
modifiableModelsProvider.commitModuleModifiableModel(model)
132130
} else {
133131
modifiableModelsProvider.disposeModuleModifiableModel(model)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.emberjs.glint
2+
3+
import com.intellij.lsp.methods.DidChangeMethod
4+
import com.intellij.openapi.editor.event.DocumentEvent
5+
import com.intellij.openapi.editor.event.DocumentListener
6+
import com.intellij.openapi.fileEditor.FileDocumentManager
7+
import com.intellij.openapi.project.ProjectManager
8+
9+
class GlintDocumentListener: DocumentListener {
10+
override fun documentChanged(event: DocumentEvent) {
11+
val projects = ProjectManager.getInstance().getOpenProjects();
12+
val file = FileDocumentManager.getInstance().getFile(event.document) ?: return
13+
projects.forEach {project ->
14+
GlintLanguageServiceProvider(project).allServices.forEach {
15+
val lspServer = it.getDescriptor()?.server
16+
if (lspServer != null && it.isAcceptable(file)&& lspServer.isFileOpened(file)) {
17+
val didChangeMethod = DidChangeMethod.createFull(lspServer, event, file)
18+
lspServer.invoke(didChangeMethod)
19+
}
20+
}
21+
22+
}
23+
24+
}
25+
}

0 commit comments

Comments
 (0)