[debugger] IJPL-158332 Introduce separate hotswap action

GitOrigin-RevId: c3157e0d33661838fcb265b55a4f3339a1c5d590
This commit is contained in:
Maksim Zuev
2024-07-30 19:10:27 +02:00
committed by intellij-monorepo-bot
parent a6d0e3bffe
commit d089f3dbc7
4 changed files with 39 additions and 6 deletions

View File

@@ -338,3 +338,5 @@ notification.group.debugger.hotswap.messages=Hotswap failed
xdebugger.hotswap.status.success=Code has been reloaded
xdebugger.hotswap.tooltip.apply=Apply hot swap
xdebugger.hotswap.tooltip.description=You changed code during a debug session. Code in runtime differs from code in editor. You can apply changes manually.
action.XDebugger.Hotswap.Modified.Files.text=Compile And Reload Modified Files
action.XDebugger.Hotswap.Modified.Files.description=Recompile files modified during a debugger session and perform hot swap

View File

@@ -198,6 +198,10 @@
<group id="XDebugger.RunToCursorInlayExtraActions">
</group>
<action id="XDebugger.Hotswap.Modified.Files" class="com.intellij.xdebugger.impl.hotswap.HotSwapModifiedFilesAction">
<add-to-group group-id="DebugReloadGroup" anchor="first"/>
</action>
</actions>
<projectListeners>

View File

@@ -10,6 +10,7 @@ import com.intellij.openapi.application.EDT
import com.intellij.openapi.editor.toolbar.floating.FloatingToolbarComponent
import com.intellij.openapi.editor.toolbar.floating.FloatingToolbarProvider
import com.intellij.openapi.editor.toolbar.floating.isInsideMainEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.registry.Registry
import com.intellij.ui.AnimatedIcon
import com.intellij.ui.components.JBLabel
@@ -24,17 +25,35 @@ import java.awt.FlowLayout
import javax.swing.JComponent
import javax.swing.JPanel
internal class HotSwapModifiedFilesAction : AnAction(XDebuggerBundle.messagePointer("action.XDebugger.Hotswap.Modified.Files.text"),
XDebuggerBundle.messagePointer("action.XDebugger.Hotswap.Modified.Files.description"),
PlatformDebuggerImplIcons.Actions.Hot_swap) {
override fun actionPerformed(e: AnActionEvent) {
val session = findSessionIfReady(e.project) ?: return
HotSwapWithRebuildAction.performHotSwap(e.dataContext, session)
}
override fun update(e: AnActionEvent) {
e.presentation.isEnabledAndVisible = findSessionIfReady(e.project) != null
}
private fun findSessionIfReady(project: Project?): HotSwapSession<*>? {
if (project == null) return null
val session = HotSwapSessionManager.getInstance(project).currentSession ?: return null
if (session.currentStatus != HotSwapVisibleStatus.CHANGES_READY) return null
return session
}
override fun getActionUpdateThread() = ActionUpdateThread.BGT
}
private class HotSwapWithRebuildAction : AnAction(), CustomComponentAction {
var inProgress = false
var session: HotSwapSession<*>? = null
override fun actionPerformed(e: AnActionEvent) {
val session = session ?: return
callWithTemplate(e.dataContext, session)
}
private fun <S> callWithTemplate(context: DataContext, session: HotSwapSession<S>) {
session.provider.performHotSwap(context, session)
performHotSwap(e.dataContext, session)
}
override fun getActionUpdateThread() = ActionUpdateThread.EDT
@@ -46,6 +65,12 @@ private class HotSwapWithRebuildAction : AnAction(), CustomComponentAction {
override fun updateCustomComponent(component: JComponent, presentation: Presentation) {
(component as HotSwapToolbarComponent).update(inProgress, presentation)
}
companion object {
internal fun <S> performHotSwap(context: DataContext, session: HotSwapSession<S>) {
session.provider.performHotSwap(context, session)
}
}
}
private class HotSwapToolbarComponent(action: AnAction, presentation: Presentation, place: String)

View File

@@ -27,9 +27,11 @@ class HotSwapSessionManager(private val project: Project, private val parentScop
return hotSwapSession
}
internal val currentSession: HotSwapSession<*>? get() = sessions.lastOrNull()
internal fun addListener(listener: HotSwapChangesListener, disposable: Disposable) {
listeners.add(listener, disposable)
val currentSession = sessions.lastOrNull() ?: return
val currentSession = currentSession ?: return
listener.onStatusChanged(currentSession, currentSession.currentStatus)
}