11package 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
57import com.intellij.framework.FrameworkType
68import com.intellij.framework.detection.DetectedFrameworkDescription
79import com.intellij.framework.detection.FileContentPattern
810import com.intellij.framework.detection.FrameworkDetectionContext
911import com.intellij.framework.detection.FrameworkDetector
1012import 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
1413import com.intellij.javascript.nodejs.packageJson.PackageJsonFileManager
15- import com.intellij.javascript.nodejs.reference.NodeModuleManager
1614import 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
1916import com.intellij.openapi.fileTypes.FileType
20- import com.intellij.openapi.fileTypes.PlainTextFileType
2117import com.intellij.openapi.module.ModuleUtilCore
2218import com.intellij.openapi.project.Project
2319import com.intellij.openapi.roots.ModifiableModelsProvider
@@ -30,9 +26,6 @@ import com.intellij.patterns.ElementPattern
3026import com.intellij.patterns.PatternCondition
3127import com.intellij.util.ProcessingContext
3228import com.intellij.util.indexing.FileContent
33- import com.intellij.xml.DefaultXmlExtension
34- import com.intellij.xml.XmlExtension
35- import com.intellij.xml.XmlTagNameProvider
3629
3730class 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)
0 commit comments