Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Save dotfile in dumb background task #169

Merged
merged 8 commits into from
Nov 21, 2024
16 changes: 14 additions & 2 deletions src/main/kotlin/com/vaadin/plugin/copilot/CopilotPluginUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import com.intellij.openapi.application.WriteAction
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.project.DumbModeTask
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.project.modules
import com.intellij.openapi.roots.CompilerModuleExtension
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.vfs.*
Expand All @@ -38,7 +40,7 @@ class CopilotPluginUtil {
val outputPath: String?
)

@JvmRecord data class ProjectInfo(val basePath: String?, val modules: List<CopilotPluginUtil.ModuleInfo>)
@JvmRecord data class ProjectInfo(val basePath: String?, val modules: List<ModuleInfo>)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sonar: Redundant qualifier


companion object {

Expand Down Expand Up @@ -96,6 +98,16 @@ class CopilotPluginUtil {
}

fun saveDotFile(project: Project) {
val task =
object : DumbModeTask() {
override fun performInDumbMode(progressIndicator: ProgressIndicator) {
saveDotFileInternal(project)
}
}
DumbService.getInstance(project).queueTask(task)
}

private fun saveDotFileInternal(project: Project) {
val dotFileDirectory = getDotFileDirectory(project)
if (dotFileDirectory != null) {
val props = Properties()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.vaadin.plugin.copilot.listeners

import com.intellij.openapi.application.WriteAction
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.project.ProjectManagerListener
Expand All @@ -16,12 +14,8 @@ class CopilotVaadinProjectListener : VaadinProjectListener {
override fun vaadinProjectDetected(project: Project) {
if (!triggered) {
triggered = true
runInEdt {
WriteAction.run<Throwable> {
saveDotFile(project)
removeDotFileOnExit(project)
}
}
saveDotFile(project)
removeDotFileOnExit(project)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrappers are not needed as both actions are using those wrappers inside

}
}

Expand Down
Loading