Skip to content

Commit 74e73ec

Browse files
committed
feat: use special scope for Action coroutine
It's said that this allows idea to control the action cancellation https://plugins.jetbrains.com/docs/intellij/launching-coroutines.html#using-currentthreadcoroutinescope IO is moved inside to have less code under it
1 parent 8c12d9d commit 74e73ec

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main/kotlin/com/github/aleksandrsl/intellijluau/actions/LuauExternalFormatAction.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.github.aleksandrsl.intellijluau.actions
22

33
import com.github.aleksandrsl.intellijluau.LuauNotifications
44
import com.github.aleksandrsl.intellijluau.settings.ProjectSettingsState
5-
import com.github.aleksandrsl.intellijluau.tools.LuauCliService
65
import com.github.aleksandrsl.intellijluau.tools.StyLuaCli
76
import com.github.aleksandrsl.intellijluau.tools.ToolchainResolver
87
import com.intellij.notification.NotificationType
@@ -11,6 +10,7 @@ import com.intellij.openapi.actionSystem.AnAction
1110
import com.intellij.openapi.actionSystem.AnActionEvent
1211
import com.intellij.openapi.application.EDT
1312
import com.intellij.openapi.diagnostic.logger
13+
import com.intellij.openapi.progress.currentThreadCoroutineScope
1414
import com.intellij.openapi.project.Project
1515
import com.intellij.platform.ide.progress.withBackgroundProgress
1616
import kotlinx.coroutines.Dispatchers
@@ -38,13 +38,14 @@ class LuauExternalFormatAction : AnAction() {
3838
override fun actionPerformed(event: AnActionEvent) {
3939
val project: Project = event.project ?: return
4040

41-
val projectService = LuauCliService.getInstance(project)
4241
val notificationGroupManager = LuauNotifications.pluginNotifications()
43-
projectService.coroutineScope.launch(Dispatchers.IO) {
42+
currentThreadCoroutineScope().launch {
4443
// Why isn't modal progress working?
4544
// Do I need different contexts here?
4645
withBackgroundProgress(project, "Stylua format current document") {
47-
val result = ToolchainResolver.resolveStylua(project)?.formatDocument(project)
46+
val result = withContext(Dispatchers.IO) {
47+
ToolchainResolver.resolveStylua(project)?.formatDocument(project)
48+
}
4849
withContext(Dispatchers.EDT) {
4950
when (result) {
5051
is StyLuaCli.FormatResult.Success -> notificationGroupManager.createNotification(

0 commit comments

Comments
 (0)