feat: debugger improved error message for failed compilation
This commit is contained in:
parent
dd2104065c
commit
532292068f
7 changed files with 41 additions and 11 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -17,6 +17,16 @@ Changelog structure reference:
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Debugger
|
||||||
|
- Notify the user if zig run / zig test debugging starts, but a build.zig is present
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Debugger
|
||||||
|
- Compilation failures did not open the terminal properly and suppressed the error message
|
||||||
|
|
||||||
## [25.1.0]
|
## [25.1.0]
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
package com.falsepattern.zigbrains.debugger.runner.base
|
package com.falsepattern.zigbrains.debugger.runner.base
|
||||||
|
|
||||||
|
import com.falsepattern.zigbrains.project.run.ZigProcessHandler
|
||||||
import com.falsepattern.zigbrains.shared.cli.startIPCAwareProcess
|
import com.falsepattern.zigbrains.shared.cli.startIPCAwareProcess
|
||||||
import com.intellij.execution.ExecutionException
|
import com.intellij.execution.ExecutionException
|
||||||
import com.intellij.execution.configurations.GeneralCommandLine
|
import com.intellij.execution.configurations.GeneralCommandLine
|
||||||
|
@ -40,7 +41,7 @@ import kotlinx.coroutines.withContext
|
||||||
class PreLaunchProcessListener(val console: ConsoleView) : ProcessListener {
|
class PreLaunchProcessListener(val console: ConsoleView) : ProcessListener {
|
||||||
var isBuildFailed: Boolean = false
|
var isBuildFailed: Boolean = false
|
||||||
private set
|
private set
|
||||||
lateinit var processHandler: ProcessHandler
|
lateinit var processHandler: ZigProcessHandler.IPCAware
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@Throws(ExecutionException::class)
|
@Throws(ExecutionException::class)
|
||||||
|
@ -50,7 +51,7 @@ class PreLaunchProcessListener(val console: ConsoleView) : ProcessListener {
|
||||||
this@PreLaunchProcessListener.processHandler = processHandler
|
this@PreLaunchProcessListener.processHandler = processHandler
|
||||||
hook(processHandler)
|
hook(processHandler)
|
||||||
processHandler.startNotify()
|
processHandler.startNotify()
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.IO) {
|
||||||
processHandler.process.awaitExit()
|
processHandler.process.awaitExit()
|
||||||
}
|
}
|
||||||
runInterruptible {
|
runInterruptible {
|
||||||
|
|
|
@ -27,6 +27,7 @@ import com.falsepattern.zigbrains.project.execution.base.ZigProfileState
|
||||||
import com.falsepattern.zigbrains.project.toolchain.base.ZigToolchain
|
import com.falsepattern.zigbrains.project.toolchain.base.ZigToolchain
|
||||||
import com.intellij.execution.ExecutionException
|
import com.intellij.execution.ExecutionException
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
|
import com.intellij.openapi.util.io.toNioPathOrNull
|
||||||
import com.intellij.platform.util.progress.withProgressText
|
import com.intellij.platform.util.progress.withProgressText
|
||||||
import com.intellij.util.containers.orNull
|
import com.intellij.util.containers.orNull
|
||||||
import com.jetbrains.cidr.execution.debugger.backend.DebuggerDriverConfiguration
|
import com.jetbrains.cidr.execution.debugger.backend.DebuggerDriverConfiguration
|
||||||
|
@ -36,6 +37,7 @@ import java.io.File
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import kotlin.io.path.absolutePathString
|
import kotlin.io.path.absolutePathString
|
||||||
import kotlin.io.path.isExecutable
|
import kotlin.io.path.isExecutable
|
||||||
|
import kotlin.io.path.pathString
|
||||||
|
|
||||||
abstract class ZigDebugParametersEmitBinaryBase<ProfileState: ZigProfileState<*>>(
|
abstract class ZigDebugParametersEmitBinaryBase<ProfileState: ZigProfileState<*>>(
|
||||||
driverConfiguration: DebuggerDriverConfiguration,
|
driverConfiguration: DebuggerDriverConfiguration,
|
||||||
|
@ -49,13 +51,14 @@ abstract class ZigDebugParametersEmitBinaryBase<ProfileState: ZigProfileState<*>
|
||||||
@Throws(ExecutionException::class)
|
@Throws(ExecutionException::class)
|
||||||
private suspend fun compileExe(listener: PreLaunchProcessListener): File {
|
private suspend fun compileExe(listener: PreLaunchProcessListener): File {
|
||||||
val commandLine = profileState.getCommandLine(toolchain, true)
|
val commandLine = profileState.getCommandLine(toolchain, true)
|
||||||
|
val cliString = commandLine.getCommandLineString(commandLine.exePath.toNioPathOrNull()?.fileName?.pathString)
|
||||||
val tmpDir = FileUtil.createTempDirectory("zigbrains_debug", "", true).toPath()
|
val tmpDir = FileUtil.createTempDirectory("zigbrains_debug", "", true).toPath()
|
||||||
|
|
||||||
val exe = tmpDir.resolve("executable")
|
val exe = tmpDir.resolve("executable")
|
||||||
commandLine.addParameters("-femit-bin=${exe.absolutePathString()}")
|
commandLine.addParameters("-femit-bin=${exe.absolutePathString()}")
|
||||||
|
|
||||||
if (listener.executeCommandLineWithHook(profileState.environment.project, commandLine))
|
if (listener.executeCommandLineWithHook(profileState.environment.project, commandLine))
|
||||||
throw ExecutionException(ZigDebugBundle.message("debug.base.compile.failed.generic"))
|
throw ExecutionException(ZigDebugBundle.message("debug.base.compile.failed.generic", cliString))
|
||||||
|
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
Files.list(tmpDir).use { stream ->
|
Files.list(tmpDir).use { stream ->
|
||||||
|
|
|
@ -24,6 +24,7 @@ package com.falsepattern.zigbrains.debugger.runner.base
|
||||||
|
|
||||||
import com.falsepattern.zigbrains.debugbridge.ZigDebuggerDriverConfigurationProviderBase
|
import com.falsepattern.zigbrains.debugbridge.ZigDebuggerDriverConfigurationProviderBase
|
||||||
import com.falsepattern.zigbrains.debugger.ZigLocalDebugProcess
|
import com.falsepattern.zigbrains.debugger.ZigLocalDebugProcess
|
||||||
|
import com.falsepattern.zigbrains.debugger.runner.build.ZigDebugRunnerBuild
|
||||||
import com.falsepattern.zigbrains.project.execution.base.ZigProfileState
|
import com.falsepattern.zigbrains.project.execution.base.ZigProfileState
|
||||||
import com.falsepattern.zigbrains.project.run.ZigProgramRunner
|
import com.falsepattern.zigbrains.project.run.ZigProgramRunner
|
||||||
import com.falsepattern.zigbrains.project.toolchain.base.ZigToolchain
|
import com.falsepattern.zigbrains.project.toolchain.base.ZigToolchain
|
||||||
|
@ -41,6 +42,7 @@ import com.intellij.execution.ui.ConsoleView
|
||||||
import com.intellij.execution.ui.ConsoleViewContentType
|
import com.intellij.execution.ui.ConsoleViewContentType
|
||||||
import com.intellij.execution.ui.RunContentDescriptor
|
import com.intellij.execution.ui.RunContentDescriptor
|
||||||
import com.intellij.openapi.application.ModalityState
|
import com.intellij.openapi.application.ModalityState
|
||||||
|
import com.intellij.openapi.project.guessProjectDir
|
||||||
import com.intellij.platform.util.progress.reportProgress
|
import com.intellij.platform.util.progress.reportProgress
|
||||||
import com.intellij.xdebugger.XDebugProcess
|
import com.intellij.xdebugger.XDebugProcess
|
||||||
import com.intellij.xdebugger.XDebugProcessStarter
|
import com.intellij.xdebugger.XDebugProcessStarter
|
||||||
|
@ -82,11 +84,13 @@ abstract class ZigDebugRunnerBase<ProfileState : ZigProfileState<*>> : ZigProgra
|
||||||
}
|
}
|
||||||
} catch (e: ExecutionException) {
|
} catch (e: ExecutionException) {
|
||||||
console.print("\n", ConsoleViewContentType.ERROR_OUTPUT)
|
console.print("\n", ConsoleViewContentType.ERROR_OUTPUT)
|
||||||
e.message?.let { listener.console.print(it, ConsoleViewContentType.SYSTEM_OUTPUT) }
|
e.message?.let { listener.console.print(it, ConsoleViewContentType.ERROR_OUTPUT) }
|
||||||
throw e;
|
if (this !is ZigDebugRunnerBuild && environment.project.guessProjectDir()?.children?.any { it.name == "build.zig" } == true) {
|
||||||
|
console.print("\n Warning: build.zig file detected in project.\n Did you want to use a Zig Build task instead?", ConsoleViewContentType.ERROR_OUTPUT)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (listener.isBuildFailed) {
|
if (listener.isBuildFailed) {
|
||||||
val executionResult = DefaultExecutionResult(console, listener.processHandler)
|
val executionResult = DefaultExecutionResult(console, listener.processHandler.unwrap())
|
||||||
return@reportProgress withEDTContext(ModalityState.any()) {
|
return@reportProgress withEDTContext(ModalityState.any()) {
|
||||||
val runContentBuilder = RunContentBuilder(executionResult, environment)
|
val runContentBuilder = RunContentBuilder(executionResult, environment)
|
||||||
runContentBuilder.showRunContent(null)
|
runContentBuilder.showRunContent(null)
|
||||||
|
|
|
@ -15,7 +15,7 @@ debugger.run.unavailable.reason.download.button=Download
|
||||||
debugger.run.unavailable.reason.update=Debugger is outdated
|
debugger.run.unavailable.reason.update=Debugger is outdated
|
||||||
debugger.run.unavailable.reason.update.button=Update
|
debugger.run.unavailable.reason.update.button=Update
|
||||||
debug.build.compile.failed.boilerplate={0}\nPlease edit this intellij build configuration and specify the path of the executable created by "zig build" directly!
|
debug.build.compile.failed.boilerplate={0}\nPlease edit this intellij build configuration and specify the path of the executable created by "zig build" directly!
|
||||||
debug.base.compile.failed.generic=Failed to compile executable
|
debug.base.compile.failed.generic=Failed to compile executable with command: {0}
|
||||||
debug.base.compile.failed.no-exe=Failed to find compiled binary
|
debug.base.compile.failed.no-exe=Failed to find compiled binary
|
||||||
debug.build.compile.failed.multiple-exe=Multiple compiled binaries found
|
debug.build.compile.failed.multiple-exe=Multiple compiled binaries found
|
||||||
debug.build.compile.failed.no-workdir=Cannot find working directory to run debugged executable
|
debug.build.compile.failed.no-workdir=Cannot find working directory to run debugged executable
|
||||||
|
|
|
@ -28,14 +28,25 @@ import com.intellij.execution.process.KillableProcessHandler
|
||||||
import com.pty4j.PtyProcess
|
import com.pty4j.PtyProcess
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
|
|
||||||
class ZigProcessHandler : KillableProcessHandler {
|
open class ZigProcessHandler : KillableProcessHandler {
|
||||||
constructor(commandLine: GeneralCommandLine) : super(commandLine) {
|
constructor(commandLine: GeneralCommandLine) : super(commandLine) {
|
||||||
setHasPty(commandLine is PtyCommandLine)
|
setHasPty(commandLine is PtyCommandLine)
|
||||||
setShouldDestroyProcessRecursively(!hasPty())
|
setShouldDestroyProcessRecursively(!hasPty())
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor (process: Process, commandLine: String, charset: Charset) : super(process, commandLine, charset) {
|
protected constructor (process: Process, commandLine: String, charset: Charset) : super(process, commandLine, charset) {
|
||||||
setHasPty(process is PtyProcess)
|
setHasPty(process is PtyProcess)
|
||||||
setShouldDestroyProcessRecursively(!hasPty())
|
setShouldDestroyProcessRecursively(!hasPty())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class IPCAware : ZigProcessHandler {
|
||||||
|
val originalCommandLine: String
|
||||||
|
constructor(originalCommandLine: String, commandLine: GeneralCommandLine) : super(commandLine) {
|
||||||
|
this.originalCommandLine = originalCommandLine
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unwrap(): ZigProcessHandler {
|
||||||
|
return ZigProcessHandler(this.process, this.originalCommandLine, this.charset ?: Charsets.UTF_8)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -130,13 +130,14 @@ fun createCommandLineSafe(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(ExecutionException::class)
|
@Throws(ExecutionException::class)
|
||||||
suspend fun GeneralCommandLine.startIPCAwareProcess(project: Project?, emulateTerminal: Boolean = false): ZigProcessHandler {
|
suspend fun GeneralCommandLine.startIPCAwareProcess(project: Project?, emulateTerminal: Boolean = false): ZigProcessHandler.IPCAware {
|
||||||
|
val original = this.commandLineString
|
||||||
val ipc = if (project != null && !emulateTerminal) IPCUtil.wrapWithIPC(this) else null
|
val ipc = if (project != null && !emulateTerminal) IPCUtil.wrapWithIPC(this) else null
|
||||||
val cli = ipc?.cli ?: this
|
val cli = ipc?.cli ?: this
|
||||||
if (emulateTerminal && OS.CURRENT != OS.Windows && !cli.environment.contains("TERM")) {
|
if (emulateTerminal && OS.CURRENT != OS.Windows && !cli.environment.contains("TERM")) {
|
||||||
cli.withEnvironment("TERM", "xterm-256color")
|
cli.withEnvironment("TERM", "xterm-256color")
|
||||||
}
|
}
|
||||||
val handler = ZigProcessHandler(cli)
|
val handler = ZigProcessHandler.IPCAware(original, cli)
|
||||||
ProcessTerminatedListener.attach(handler)
|
ProcessTerminatedListener.attach(handler)
|
||||||
|
|
||||||
if (ipc != null) {
|
if (ipc != null) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue