File tree 4 files changed +22
-18
lines changed
src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin
4 files changed +22
-18
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ import com.intellij.ui.EditorNotifications
8
8
import kotlinx.coroutines.CoroutineScope
9
9
import kotlinx.coroutines.Dispatchers
10
10
import kotlinx.coroutines.launch
11
- import kotlinx.coroutines.withContext
12
11
13
12
14
13
fun lintGitlabYaml (file : PsiFile ) {
@@ -21,13 +20,10 @@ fun lint(file: PsiFile) {
21
20
val project = file.project
22
21
val pipeline = project.service<Pipeline >()
23
22
24
- CoroutineScope (Dispatchers .IO ).launch {
23
+ CoroutineScope (Dispatchers .Default ).launch {
25
24
withBackgroundProgress(file.project, GitlabLintBundle .message(" inspection.title" )) {
26
25
pipeline.accept(file)
27
-
28
- withContext(Dispatchers .Main ) {
29
- EditorNotifications .getInstance(project).updateAllNotifications()
30
- }
26
+ EditorNotifications .getInstance(project).updateAllNotifications()
31
27
}
32
28
}
33
29
}
Original file line number Diff line number Diff line change @@ -20,4 +20,4 @@ class SaveActionListener(val project: Project) : FileDocumentManagerListener {
20
20
super .beforeDocumentSaving(document)
21
21
}
22
22
}
23
- }
23
+ }
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ import com.intellij.openapi.command.WriteCommandAction
12
12
import com.intellij.openapi.components.Service
13
13
import com.intellij.openapi.components.service
14
14
import com.intellij.openapi.fileEditor.FileEditorManager
15
+ import kotlinx.coroutines.Dispatchers
16
+ import kotlinx.coroutines.withContext
15
17
16
18
@Service(Service .Level .PROJECT )
17
19
class LintContext : Middleware {
@@ -78,7 +80,7 @@ class LintContext : Middleware {
78
80
}
79
81
}
80
82
81
- private fun lintContent (
83
+ private suspend fun lintContent (
82
84
gitlab : Gitlab ,
83
85
gitlabUrl : String ,
84
86
gitlabToken : String ,
@@ -93,13 +95,15 @@ class LintContext : Middleware {
93
95
fileText = pass.file.text
94
96
}
95
97
96
- return gitlab.lintContent(
97
- gitlabUrl,
98
- gitlabToken,
99
- fileText,
100
- remoteId,
101
- branch,
102
- showGitlabTokenNotification
103
- ).get()
98
+ return withContext(Dispatchers .IO ) {
99
+ gitlab.lintContent(
100
+ gitlabUrl,
101
+ gitlabToken,
102
+ fileText,
103
+ remoteId,
104
+ branch,
105
+ showGitlabTokenNotification
106
+ ).get()
107
+ }
104
108
}
105
109
}
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ import com.intellij.openapi.components.service
17
17
import git4idea.repo.GitRemote
18
18
import git4idea.repo.GitRepository
19
19
import git4idea.repo.GitRepositoryManager
20
+ import kotlinx.coroutines.Dispatchers
21
+ import kotlinx.coroutines.withContext
20
22
21
23
@Service(Service .Level .PROJECT )
22
24
class ResolveContext : Middleware {
@@ -75,8 +77,10 @@ class ResolveContext : Middleware {
75
77
}
76
78
}
77
79
78
- private fun locateRepository (pass : Pass ): GitRepository ? {
79
- val repository = GitRepositoryManager .getInstance(pass.project).getRepositoryForFile(pass.file.virtualFile)
80
+ private suspend fun locateRepository (pass : Pass ): GitRepository ? {
81
+ val repository = withContext(Dispatchers .IO ) {
82
+ GitRepositoryManager .getInstance(pass.project).getRepositoryForFile(pass.file.virtualFile)
83
+ }
80
84
81
85
showRepositoryNotification = if (repository == null ) {
82
86
sendNotification(Notification .repositoryNotFound(), pass.project)
You can’t perform that action at this time.
0 commit comments