[debugger] IJPL-158332 Compile and reload only modified files during hot swap

GitOrigin-RevId: 6b7522904b2e796b1e75b745017da70eb9b74281
This commit is contained in:
Maksim Zuev
2024-07-26 18:00:47 +02:00
committed by intellij-monorepo-bot
parent bb43d09386
commit dd4705d51f
5 changed files with 37 additions and 15 deletions

View File

@@ -27,19 +27,22 @@ internal class JvmHotSwapProvider(private val debuggerSession: DebuggerSession)
override fun performHotSwap(context: DataContext, session: HotSwapSession<VirtualFile>) {
val project = context.getData(CommonDataKeys.PROJECT) ?: return
val listener = session.createStatusListener()
HotSwapUI.getInstance(project).reloadChangedClasses(debuggerSession, true, object : HotSwapStatusListener {
override fun onSuccess(sessions: MutableList<DebuggerSession>?) {
listener.onCompleted()
}
HotSwapUI.getInstance(project).compileAndReload(debuggerSession, HotSwapStatusListenerAdapter(listener),
*session.getChanges().toTypedArray())
}
}
override fun onFailure(sessions: MutableList<DebuggerSession>?) {
listener.onFailed()
}
private class HotSwapStatusListenerAdapter(private val listener: HotSwapResultListener) : HotSwapStatusListener {
override fun onSuccess(sessions: MutableList<DebuggerSession>?) {
listener.onCompleted()
}
override fun onCancel(sessions: MutableList<DebuggerSession>?) {
listener.onCanceled()
}
})
override fun onFailure(sessions: MutableList<DebuggerSession>?) {
listener.onFailed()
}
override fun onCancel(sessions: MutableList<DebuggerSession>?) {
listener.onCanceled()
}
}

View File

@@ -19,6 +19,7 @@ public abstract class HotSwapUI {
@Nullable HotSwapStatusListener callback);
public abstract void compileAndReload(@NotNull DebuggerSession session, VirtualFile @NotNull ... files);
public abstract void compileAndReload(@NotNull DebuggerSession session, @Nullable HotSwapStatusListener callback, VirtualFile @NotNull ... files);
public abstract void addListener(HotSwapVetoableListener listener);

View File

@@ -285,8 +285,7 @@ public final class HotSwapUIImpl extends HotSwapUI {
}
else {
ProjectTask buildProjectTask = projectTaskManager.createAllModulesBuildTask(true, project);
ProjectTaskContext context = new ProjectTaskContext(callback).withUserData(HOT_SWAP_CALLBACK_KEY, callback);
projectTaskManager.run(context, buildProjectTask);
projectTaskManager.run(createContext(callback), buildProjectTask);
}
}
else {
@@ -301,13 +300,29 @@ public final class HotSwapUIImpl extends HotSwapUI {
@Override
public void compileAndReload(@NotNull DebuggerSession session, VirtualFile @NotNull ... files) {
compileAndReload(session, null, files);
}
@Override
public void compileAndReload(@NotNull DebuggerSession session, @Nullable HotSwapStatusListener callback, VirtualFile @NotNull ... files) {
dontAskHotswapAfterThisCompilation();
Project project = session.getProject();
ProjectTaskManagerImpl.putBuildOriginator(project, this.getClass());
ProjectTaskManager.getInstance(project).compile(files);
if (callback == null) {
ProjectTaskManager.getInstance(project).compile(files);
} else {
ProjectTaskManagerImpl taskManager = (ProjectTaskManagerImpl)ProjectTaskManager.getInstance(project);
ProjectTask task = taskManager.createModulesFilesTask(files);
taskManager.run(createContext(callback), task);
}
// The control flow continues at MyCompilationStatusListener.finished.
}
private static ProjectTaskContext createContext(@NotNull HotSwapStatusListener callback) {
return new ProjectTaskContext(callback).withUserData(HOT_SWAP_CALLBACK_KEY, callback);
}
public void dontAskHotswapAfterThisCompilation() {
myAskBeforeHotswap = false;
}