diff --git a/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/GitlabLintRunner.kt b/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/GitlabLintRunner.kt index 79fe362..2ccdefe 100644 --- a/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/GitlabLintRunner.kt +++ b/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/GitlabLintRunner.kt @@ -8,7 +8,6 @@ import com.intellij.ui.EditorNotifications import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext fun lintGitlabYaml(file: PsiFile) { @@ -21,13 +20,10 @@ fun lint(file: PsiFile) { val project = file.project val pipeline = project.service() - CoroutineScope(Dispatchers.IO).launch { + CoroutineScope(Dispatchers.Default).launch { withBackgroundProgress(file.project, GitlabLintBundle.message("inspection.title")) { pipeline.accept(file) - - withContext(Dispatchers.Main) { - EditorNotifications.getInstance(project).updateAllNotifications() - } + EditorNotifications.getInstance(project).updateAllNotifications() } } } diff --git a/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/listeners/SaveActionListener.kt b/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/listeners/SaveActionListener.kt index 16f2a5a..3dbd626 100644 --- a/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/listeners/SaveActionListener.kt +++ b/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/listeners/SaveActionListener.kt @@ -20,4 +20,4 @@ class SaveActionListener(val project: Project) : FileDocumentManagerListener { super.beforeDocumentSaving(document) } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/pipeline/middleware/LintContext.kt b/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/pipeline/middleware/LintContext.kt index c1f1f59..055e4e3 100644 --- a/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/pipeline/middleware/LintContext.kt +++ b/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/pipeline/middleware/LintContext.kt @@ -12,6 +12,8 @@ import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.components.Service import com.intellij.openapi.components.service import com.intellij.openapi.fileEditor.FileEditorManager +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext @Service(Service.Level.PROJECT) class LintContext : Middleware { @@ -78,7 +80,7 @@ class LintContext : Middleware { } } - private fun lintContent( + private suspend fun lintContent( gitlab: Gitlab, gitlabUrl: String, gitlabToken: String, @@ -93,13 +95,15 @@ class LintContext : Middleware { fileText = pass.file.text } - return gitlab.lintContent( - gitlabUrl, - gitlabToken, - fileText, - remoteId, - branch, - showGitlabTokenNotification - ).get() + return withContext(Dispatchers.IO) { + gitlab.lintContent( + gitlabUrl, + gitlabToken, + fileText, + remoteId, + branch, + showGitlabTokenNotification + ).get() + } } } diff --git a/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/pipeline/middleware/ResolveContext.kt b/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/pipeline/middleware/ResolveContext.kt index 59dcc03..59dafaf 100644 --- a/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/pipeline/middleware/ResolveContext.kt +++ b/src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/pipeline/middleware/ResolveContext.kt @@ -17,6 +17,8 @@ import com.intellij.openapi.components.service import git4idea.repo.GitRemote import git4idea.repo.GitRepository import git4idea.repo.GitRepositoryManager +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext @Service(Service.Level.PROJECT) class ResolveContext : Middleware { @@ -75,8 +77,10 @@ class ResolveContext : Middleware { } } - private fun locateRepository(pass: Pass): GitRepository? { - val repository = GitRepositoryManager.getInstance(pass.project).getRepositoryForFile(pass.file.virtualFile) + private suspend fun locateRepository(pass: Pass): GitRepository? { + val repository = withContext(Dispatchers.IO) { + GitRepositoryManager.getInstance(pass.project).getRepositoryForFile(pass.file.virtualFile) + } showRepositoryNotification = if (repository == null) { sendNotification(Notification.repositoryNotFound(), pass.project)