diff --git a/src/SharpIDE.Application/Features/Debugging/DebuggingService.cs b/src/SharpIDE.Application/Features/Debugging/DebuggingService.cs index 4ab303e..31e848a 100644 --- a/src/SharpIDE.Application/Features/Debugging/DebuggingService.cs +++ b/src/SharpIDE.Application/Features/Debugging/DebuggingService.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Reflection; using Ardalis.GuardClauses; using Microsoft.Diagnostics.NETCore.Client; using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol; @@ -6,6 +7,7 @@ using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages; using Newtonsoft.Json.Linq; using SharpIDE.Application.Features.Debugging.Experimental; using SharpIDE.Application.Features.Debugging.Experimental.VsDbg; +using SharpIDE.Application.Features.Events; using SharpIDE.Application.Features.SolutionDiscovery; namespace SharpIDE.Application.Features.Debugging; @@ -22,8 +24,8 @@ public class DebuggingService { StartInfo = new ProcessStartInfo { - FileName = @"C:\Users\Matthew\Downloads\netcoredbg-win64\netcoredbg\netcoredbg.exe", - //FileName = @"C:\Users\Matthew\.vscode-insiders\extensions\ms-dotnettools.csharp-2.83.5-win32-x64\.debugger\x86_64\vsdbg.exe", + //FileName = @"C:\Users\Matthew\Downloads\netcoredbg-win64\netcoredbg\netcoredbg.exe", + FileName = @"C:\Users\Matthew\.vscode-insiders\extensions\ms-dotnettools.csharp-2.83.5-win32-x64\.debugger\x86_64\vsdbg.exe", Arguments = "--interpreter=vscode", RedirectStandardInput = true, RedirectStandardOutput = true, @@ -64,6 +66,13 @@ public class DebuggingService debugProtocolHost.RegisterEventType(async void (@event) => { await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding); // The VS Code Debug Protocol throws if you try to send a request from the dispatcher thread + //Dictionary? test = @event.AdditionalProperties; + var prop = @event.GetType().GetProperty("AdditionalProperties", BindingFlags.NonPublic | BindingFlags.Instance); + // source, line, column + var dict = prop?.GetValue(@event) as Dictionary; + var filePath = dict?["source"]?["path"]!.Value()!; + var line = (dict?["line"]?.Value()!).Value; + GlobalEvents.InvokeDebuggerExecutionStopped(filePath, line); if (@event.Reason is StoppedEvent.ReasonValue.Exception) { Console.WriteLine("Stopped due to exception, continuing"); diff --git a/src/SharpIDE.Application/Features/Events/GlobalEvents.cs b/src/SharpIDE.Application/Features/Events/GlobalEvents.cs index ecaeadb..958d6d7 100644 --- a/src/SharpIDE.Application/Features/Events/GlobalEvents.cs +++ b/src/SharpIDE.Application/Features/Events/GlobalEvents.cs @@ -1,4 +1,6 @@ -using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; +using SharpIDE.Application.Features.Debugging; +using SharpIDE.Application.Features.SolutionDiscovery; +using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; namespace SharpIDE.Application.Features.Events; @@ -15,4 +17,7 @@ public static class GlobalEvents public static event Func ProjectStoppedRunning = _ => Task.CompletedTask; public static void InvokeProjectStoppedRunning(SharpIdeProjectModel project) => ProjectStoppedRunning?.Invoke(project); + + public static event Func DebuggerExecutionStopped = (_, _) => Task.CompletedTask; + public static void InvokeDebuggerExecutionStopped(string filePath, int line) => DebuggerExecutionStopped?.Invoke(filePath, line); } diff --git a/src/SharpIDE.Godot/SharpIdeCodeEdit.cs b/src/SharpIDE.Godot/SharpIdeCodeEdit.cs index 486f199..9439c99 100644 --- a/src/SharpIDE.Godot/SharpIdeCodeEdit.cs +++ b/src/SharpIDE.Godot/SharpIdeCodeEdit.cs @@ -12,6 +12,7 @@ using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.Text; using SharpIDE.Application.Features.Analysis; using SharpIDE.Application.Features.Debugging; +using SharpIDE.Application.Features.Events; using SharpIDE.Application.Features.SolutionDiscovery; using Task = System.Threading.Tasks.Task; @@ -36,7 +37,6 @@ public partial class SharpIdeCodeEdit : CodeEdit public override void _Ready() { - SyntaxHighlighter = _syntaxHighlighter; _popupMenu = GetNode("CodeFixesMenu"); _popupMenu.IdPressed += OnCodeFixSelected; @@ -48,6 +48,20 @@ public partial class SharpIdeCodeEdit : CodeEdit SymbolHovered += OnSymbolHovered; SymbolValidate += OnSymbolValidate; SymbolLookup += OnSymbolLookup; + GlobalEvents.DebuggerExecutionStopped += OnDebuggerExecutionStopped; + } + + private async Task OnDebuggerExecutionStopped(string filePath, int line) + { + if (filePath != _currentFile.Path) return; // TODO: handle file switching + var lineInt = line - 1; // Debugging is 1-indexed, Godot is 0-indexed + Guard.Against.Negative(lineInt, nameof(lineInt)); + + await this.InvokeAsync(() => + { + SetLineBackgroundColor(lineInt, new Color("665001")); + SetLineAsExecuting(lineInt, true); + }); } private void OnBreakpointToggled(long line)