refactor creation of debugger process

This commit is contained in:
Matt Parker
2026-01-06 19:15:49 +10:00
parent 60e7f9d650
commit 50fdf68bd1
6 changed files with 54 additions and 27 deletions

View File

@@ -0,0 +1,32 @@
using System.Diagnostics;
using Ardalis.GuardClauses;
using SharpIDE.Application.Features.Run;
namespace SharpIDE.Application.Features.Debugging;
public static class DebuggerProcessStreamHelper
{
public static (Stream Input, Stream Output, bool IsNetCoreDbg) NewDebuggerProcessStreamsForInfo(DebuggerExecutableInfo? debuggerExecutableInfoNullable)
{
if (debuggerExecutableInfoNullable is not {} debuggerExecutableInfo) throw new ArgumentNullException(nameof(debuggerExecutableInfoNullable), "Debugger executable info cannot be null.");
var debuggerExecutablePath = debuggerExecutableInfo.DebuggerExecutablePath;
Guard.Against.NullOrWhiteSpace(debuggerExecutablePath, nameof(debuggerExecutablePath), "Debugger executable path cannot be null or empty.");
var isNetCoreDbg = Path.GetFileNameWithoutExtension(debuggerExecutablePath).Equals("netcoredbg", StringComparison.OrdinalIgnoreCase);
var process = new Process
{
StartInfo = new ProcessStartInfo
{
//FileName = @"C:\Users\Matthew\Downloads\netcoredbg-win64\netcoredbg\netcoredbg.exe",
FileName = debuggerExecutablePath,
Arguments = "--interpreter=vscode",
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
}
};
process.Start();
return (process.StandardInput.BaseStream, process.StandardOutput.BaseStream, isNetCoreDbg);
}
}