diff --git a/src/main/kotlin/com/vaadin/plugin/copilot/activity/CopilotPostStartupProjectActivity.kt b/src/main/kotlin/com/vaadin/plugin/copilot/activity/CopilotPostStartupProjectActivity.kt
index c2f4886..c91da1f 100644
--- a/src/main/kotlin/com/vaadin/plugin/copilot/activity/CopilotPostStartupProjectActivity.kt
+++ b/src/main/kotlin/com/vaadin/plugin/copilot/activity/CopilotPostStartupProjectActivity.kt
@@ -5,23 +5,10 @@ import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.project.ProjectManagerListener
import com.intellij.openapi.startup.ProjectActivity
import com.vaadin.plugin.copilot.CopilotPluginUtil
-import com.vaadin.plugin.utils.VaadinProjectUtil
-import org.jetbrains.ide.BuiltInServerManager
class CopilotPostStartupProjectActivity : ProjectActivity {
override suspend fun execute(project: Project) {
-
- BuiltInServerManager.getInstance().waitForStart()
-
- if (VaadinProjectUtil.isVaadinProject(project)) {
- val dotFileDirectory = CopilotPluginUtil.getDotFileDirectory(project)
- if (dotFileDirectory == null) {
- CopilotPluginUtil.createIdeaDirectoryIfMissing(project)
- }
- CopilotPluginUtil.saveDotFile(project)
- }
-
ProjectManager.getInstance()
.addProjectManagerListener(
project,
diff --git a/src/main/kotlin/com/vaadin/plugin/copilot/listeners/CopilotModuleRootListener.kt b/src/main/kotlin/com/vaadin/plugin/copilot/listeners/CopilotModuleRootListener.kt
new file mode 100644
index 0000000..b25c202
--- /dev/null
+++ b/src/main/kotlin/com/vaadin/plugin/copilot/listeners/CopilotModuleRootListener.kt
@@ -0,0 +1,24 @@
+package com.vaadin.plugin.copilot.listeners
+
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.roots.ModuleRootEvent
+import com.intellij.openapi.roots.ModuleRootListener
+import com.vaadin.plugin.copilot.CopilotPluginUtil
+import com.vaadin.plugin.utils.VaadinProjectUtil.Companion.isVaadinProject
+
+class CopilotModuleRootListener : ModuleRootListener {
+
+ override fun rootsChanged(event: ModuleRootEvent) {
+ if (isVaadinProject(event.project)) {
+ createDotFile(event.project)
+ }
+ }
+
+ private fun createDotFile(project: Project) {
+ val dotFileDirectory = CopilotPluginUtil.getDotFileDirectory(project)
+ if (dotFileDirectory == null) {
+ CopilotPluginUtil.createIdeaDirectoryIfMissing(project)
+ }
+ CopilotPluginUtil.saveDotFile(project)
+ }
+}
diff --git a/src/main/kotlin/com/vaadin/plugin/utils/VaadinProjectUtil.kt b/src/main/kotlin/com/vaadin/plugin/utils/VaadinProjectUtil.kt
index f1b03c7..4ea1268 100644
--- a/src/main/kotlin/com/vaadin/plugin/utils/VaadinProjectUtil.kt
+++ b/src/main/kotlin/com/vaadin/plugin/utils/VaadinProjectUtil.kt
@@ -76,14 +76,16 @@ class VaadinProjectUtil {
}
fun isVaadinProject(project: Project): Boolean {
+ return ModuleManager.getInstance(project).modules.any { isVaadinModule(it) }
+ }
+
+ fun isVaadinModule(module: com.intellij.openapi.module.Module): Boolean {
var hasVaadin = false
- ModuleManager.getInstance(project).modules.forEach { module ->
- ModuleRootManager.getInstance(module).orderEntries().forEachLibrary { library: Library ->
- if (library.name?.contains(VAADIN_LIB_PREFIX) == true) {
- hasVaadin = true
- }
- true
+ ModuleRootManager.getInstance(module).orderEntries().forEachLibrary { library: Library ->
+ if (library.name?.contains(VAADIN_LIB_PREFIX) == true) {
+ hasVaadin = true
}
+ true
}
return hasVaadin
}
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 3fe2f21..4bde6ad 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -65,6 +65,8 @@
+
+
@@ -85,4 +87,10 @@
+
+
+
+