refactor: launch coroutines instead of invokeLater
This commit is contained in:
parent
5f8da8fb4b
commit
f769ec9b2c
2 changed files with 20 additions and 6 deletions
|
|
@ -3,6 +3,7 @@ package com.github.continuedev.continueintellijextension.nextEdit
|
|||
import com.github.continuedev.continueintellijextension.listeners.ActiveHandlerManager
|
||||
import com.github.continuedev.continueintellijextension.utils.InlineCompletionUtils
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.EDT
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.LogicalPosition
|
||||
|
|
@ -22,6 +23,7 @@ import com.intellij.util.ui.JBFont
|
|||
import com.intellij.util.ui.JBUI
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import java.awt.*
|
||||
import java.awt.event.ActionEvent
|
||||
|
|
@ -42,7 +44,7 @@ data class CompletionDataForAfterJump(
|
|||
@Service(Service.Level.PROJECT)
|
||||
class NextEditJumpManager(private val project: Project) {
|
||||
|
||||
private val coroutineScope = CoroutineScope(Dispatchers.Main)
|
||||
private val coroutineScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
|
||||
// State management
|
||||
private var jumpState = JumpState()
|
||||
|
|
@ -409,7 +411,9 @@ class NextEditJumpManager(private val project: Project) {
|
|||
// Clear decorations (this will cancel popup, but won't trigger reject due to state check)
|
||||
clearJumpDecoration()
|
||||
|
||||
InlineCompletionUtils.triggerInlineCompletion(editor, project) { success -> "success: $success" }
|
||||
coroutineScope.launch(Dispatchers.EDT) {
|
||||
InlineCompletionUtils.triggerInlineCompletion(editor, project)
|
||||
}
|
||||
|
||||
// Reset accepted state after a brief moment
|
||||
coroutineScope.launch {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.github.continuedev.continueintellijextension.Position
|
|||
import com.github.continuedev.continueintellijextension.listeners.ActiveHandlerManager
|
||||
import com.github.continuedev.continueintellijextension.utils.InlineCompletionUtils
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.EDT
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.editor.Editor
|
||||
|
|
@ -20,6 +21,10 @@ import com.intellij.openapi.util.TextRange
|
|||
import com.intellij.ui.JBColor
|
||||
import com.intellij.ui.components.JBPanel
|
||||
import com.intellij.util.ui.JBUI
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import java.awt.*
|
||||
import java.awt.event.ActionEvent
|
||||
import java.awt.event.KeyEvent
|
||||
|
|
@ -29,6 +34,8 @@ import javax.swing.border.AbstractBorder
|
|||
|
||||
@Service(Service.Level.PROJECT)
|
||||
class NextEditWindowManager(private val project: Project) {
|
||||
private val coroutineScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
|
||||
private var currentPopup: JBPopup? = null
|
||||
private var deletionHighlighters: List<RangeHighlighter> = emptyList()
|
||||
private var isAccepted = false
|
||||
|
|
@ -914,10 +921,13 @@ class NextEditWindowManager(private val project: Project) {
|
|||
}
|
||||
|
||||
println("DEBUG: WriteCommandAction completed successfully")
|
||||
InlineCompletionUtils.triggerInlineCompletion(
|
||||
editor,
|
||||
project
|
||||
) { success -> println("invocation: $success") }
|
||||
|
||||
coroutineScope.launch(Dispatchers.EDT) {
|
||||
InlineCompletionUtils.triggerInlineCompletion(
|
||||
editor,
|
||||
project
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
println("ERROR: Exception in acceptEdit: ${e.message}")
|
||||
e.printStackTrace()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue