feat: std.Progress support in debugging

This commit is contained in:
FalsePattern 2025-03-14 23:41:14 +01:00
parent 2f8bc57fe1
commit 09ec2d79cc
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
5 changed files with 17 additions and 6 deletions

View file

@ -23,6 +23,8 @@
package com.falsepattern.zigbrains.debugger.runner.base
import com.falsepattern.zigbrains.project.run.ZigProcessHandler
import com.falsepattern.zigbrains.shared.ipc.IPCUtil
import com.falsepattern.zigbrains.shared.ipc.ipc
import com.intellij.execution.ExecutionException
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.process.ProcessEvent
@ -30,6 +32,7 @@ import com.intellij.execution.process.ProcessHandler
import com.intellij.execution.process.ProcessListener
import com.intellij.execution.ui.ConsoleView
import com.intellij.execution.ui.ConsoleViewContentType
import com.intellij.openapi.project.Project
import com.intellij.platform.util.progress.withProgressText
import com.intellij.util.io.awaitExit
import kotlinx.coroutines.Dispatchers
@ -43,9 +46,14 @@ class PreLaunchProcessListener(val console: ConsoleView) : ProcessListener {
private set
@Throws(ExecutionException::class)
suspend fun executeCommandLineWithHook(commandLine: GeneralCommandLine): Boolean {
suspend fun executeCommandLineWithHook(project: Project, commandLine: GeneralCommandLine): Boolean {
return withProgressText(commandLine.commandLineString) {
val processHandler = ZigProcessHandler(commandLine)
val ipc = IPCUtil.wrapWithIPC(commandLine)
val cli = ipc?.cli ?: commandLine
val processHandler = ZigProcessHandler(cli)
if (ipc != null) {
project.ipc?.launchWatcher(ipc, processHandler.process)
}
this@PreLaunchProcessListener.processHandler = processHandler
hook(processHandler)
processHandler.startNotify()

View file

@ -54,7 +54,7 @@ abstract class ZigDebugParametersEmitBinaryBase<ProfileState: ZigProfileState<*>
val exe = tmpDir.resolve("executable")
commandLine.addParameters("-femit-bin=${exe.absolutePathString()}")
if (listener.executeCommandLineWithHook(commandLine))
if (listener.executeCommandLineWithHook(profileState.environment.project, commandLine))
throw ExecutionException(ZigDebugBundle.message("debug.base.compile.failed.generic"))
return withContext(Dispatchers.IO) {

View file

@ -82,6 +82,7 @@ abstract class ZigDebugRunnerBase<ProfileState : ZigProfileState<*>> : ZigProgra
} catch (e: ExecutionException) {
console.print("\n", ConsoleViewContentType.ERROR_OUTPUT)
e.message?.let { listener.console.print(it, ConsoleViewContentType.SYSTEM_OUTPUT) }
throw e;
}
if (listener.isBuildFailed) {
val executionResult = DefaultExecutionResult(console, listener.processHandler)

View file

@ -61,7 +61,7 @@ class ZigDebugParametersBuild(
withProgressText("Building zig project") {
withContext(Dispatchers.IO) {
val commandLine = profileState.getCommandLine(toolchain, true)
if (listener.executeCommandLineWithHook(commandLine))
if (listener.executeCommandLineWithHook(profileState.environment.project, commandLine))
throw ExecutionException(ZigDebugBundle.message("debug.build.compile.failed.generic"))
val cfg = profileState.configuration
val workingDir = cfg.workingDirectory.path

View file

@ -85,8 +85,10 @@ exec.option.label.compiler-args=Extra compiler command line arguments
exec.option.label.exe-args=Output program command line arguments
exec.option.label.build.steps=Build steps
exec.option.label.build.args=Extra command line arguments
exec.option.label.build.exe-args-debug=Output program command line arguments (debug only)
exec.option.label.build.exe-path-debug=Output executable created by the build (debug only, autodetect if empty)
exec.option.label.build.steps-debug=Debug Build steps
exec.option.label.build.args-debug=Debug Extra command line arguments
exec.option.label.build.exe-args-debug=Debug output program command line arguments
exec.option.label.build.exe-path-debug=Debug output executable created by the build
exception.zig.empty-file-path=Empty file path
exception.translate-command-line.unbalanced-quotes=Unbalanced quotes in {0}
exception.zig-profile-state.start-process.no-toolchain=Failed to get zig toolchain from project