@@ -46,6 +46,8 @@ import com.intellij.util.KeyedLazyInstance
4646import com.intellij.util.xmlb.annotations.Attribute
4747import java.util.ResourceBundle
4848import javax.swing.JComponent
49+ import kotlinx.coroutines.Dispatchers
50+ import kotlinx.coroutines.runBlocking
4951
5052/* *
5153 * Extensions responsible for creating a [TemplateDescriptor] based on whatever data it is provided in its configuration
@@ -73,31 +75,34 @@ interface TemplateProvider {
7375
7476 fun getAllKeys () = EP_NAME .extensionList.mapNotNull { it.key }
7577
76- fun findTemplates (
78+ suspend fun findTemplates (
7779 modalityState : ModalityState ,
7880 repoRoot : VirtualFile ,
7981 templates : MutableList <VfsLoadedTemplate > = mutableListOf(),
80- bundle : ResourceBundle ? = loadMessagesBundle(modalityState, repoRoot)
82+ bundle : ResourceBundle ? = null
8183 ): List <VfsLoadedTemplate > {
84+ val bundle = bundle ? : loadMessagesBundle(modalityState, repoRoot)
8285 val visitor = object : VirtualFileVisitor <Unit >() {
8386 override fun visitFile (file : VirtualFile ): Boolean {
8487 if (! file.isFile || ! file.name.endsWith(" .mcdev.template.json" )) {
8588 return true
8689 }
8790
88- try {
89- createVfsLoadedTemplate(modalityState, file.parent, file, bundle = bundle)
90- ?.let (templates::add)
91- } catch (t: Throwable ) {
92- if (t is ControlFlowException ) {
93- throw t
94- }
95-
96- val attachment = runCatching { Attachment (file.name, file.readText()) }.getOrNull()
97- if (attachment != null ) {
98- thisLogger().error(" Failed to load template ${file.path} " , t, attachment)
99- } else {
100- thisLogger().error(" Failed to load template ${file.path} " , t)
91+ runBlocking(Dispatchers .Unconfined ) {
92+ try {
93+ createVfsLoadedTemplate(modalityState, file.parent, file, bundle = bundle)
94+ ?.let (templates::add)
95+ } catch (t: Throwable ) {
96+ if (t is ControlFlowException ) {
97+ throw t
98+ }
99+
100+ val attachment = runCatching { Attachment (file.name, file.readText()) }.getOrNull()
101+ if (attachment != null ) {
102+ thisLogger().error(" Failed to load template ${file.path} " , t, attachment)
103+ } else {
104+ thisLogger().error(" Failed to load template ${file.path} " , t)
105+ }
101106 }
102107 }
103108
@@ -108,7 +113,7 @@ interface TemplateProvider {
108113 return templates
109114 }
110115
111- fun loadMessagesBundle (modalityState : ModalityState , repoRoot : VirtualFile ): ResourceBundle ? = try {
116+ suspend fun loadMessagesBundle (modalityState : ModalityState , repoRoot : VirtualFile ): ResourceBundle ? = try {
112117 val locale = DynamicBundle .getLocale()
113118 // Simplified bundle resolution, but covers all the most common cases
114119 val baseBundle = doLoadMessageBundle(
@@ -135,7 +140,7 @@ interface TemplateProvider {
135140 null
136141 }
137142
138- private fun doLoadMessageBundle (
143+ private suspend fun doLoadMessageBundle (
139144 file : VirtualFile ? ,
140145 modalityState : ModalityState ,
141146 parent : ResourceBundle ?
@@ -158,7 +163,7 @@ interface TemplateProvider {
158163 return parent
159164 }
160165
161- fun createVfsLoadedTemplate (
166+ suspend fun createVfsLoadedTemplate (
162167 modalityState : ModalityState ,
163168 templateRoot : VirtualFile ,
164169 descriptorFile : VirtualFile ,
0 commit comments