Debugger - expand variables with variablesReference
This commit is contained in:
@@ -23,4 +23,5 @@ public class Debugger
|
||||
public async Task<List<ThreadModel>> GetThreadsAtStopPoint() => await _debuggingService.GetThreadsAtStopPoint();
|
||||
public async Task<List<StackFrameModel>> GetStackFramesForThread(int threadId) => await _debuggingService.GetStackFramesForThread(threadId);
|
||||
public async Task<List<Variable>> GetVariablesForStackFrame(int frameId) => await _debuggingService.GetVariablesForStackFrame(frameId);
|
||||
public async Task<List<Variable>> GetVariablesForVariablesReference(int variablesReferenceId) => await _debuggingService.GetVariablesForVariablesReference(variablesReferenceId);
|
||||
}
|
||||
|
||||
@@ -242,6 +242,13 @@ public class DebuggingService
|
||||
return allVariables;
|
||||
}
|
||||
|
||||
public async Task<List<Variable>> GetVariablesForVariablesReference(int variablesReference)
|
||||
{
|
||||
var variablesRequest = new VariablesRequest { VariablesReference = variablesReference };
|
||||
var variablesResponse = _debugProtocolHost.SendRequestSync(variablesRequest);
|
||||
return variablesResponse.Variables;
|
||||
}
|
||||
|
||||
// netcoredbg does not provide the stack frame name in this format, so don't use this if using netcoredbg
|
||||
private static ManagedStackFrameInfo? ParseStackFrameName(string name)
|
||||
{
|
||||
|
||||
@@ -166,6 +166,10 @@ public partial class RunService(ILogger<RunService> logger, RoslynAnalysis rosly
|
||||
{
|
||||
return await _debugger!.GetVariablesForStackFrame(frameId);
|
||||
}
|
||||
public async Task<List<Variable>> GetVariablesForVariablesReference(int variablesReferenceId)
|
||||
{
|
||||
return await _debugger!.GetVariablesForVariablesReference(variablesReferenceId);
|
||||
}
|
||||
|
||||
private async Task<string> GetRunArguments(SharpIdeProjectModel project)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Ardalis.GuardClauses;
|
||||
using Godot;
|
||||
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages;
|
||||
using SharpIDE.Application.Features.Debugging;
|
||||
using SharpIDE.Application.Features.Events;
|
||||
using SharpIDE.Application.Features.Run;
|
||||
@@ -28,9 +29,38 @@ public partial class ThreadsVariablesSubTab : Control
|
||||
GlobalEvents.Instance.DebuggerExecutionStopped.Subscribe(OnDebuggerExecutionStopped);
|
||||
_threadsTree.ItemSelected += OnThreadSelected;
|
||||
_stackFramesTree.ItemSelected += OnStackFrameSelected;
|
||||
_variablesTree.ItemCollapsed += OnVariablesItemExpandedOrCollapsed;
|
||||
Project.ProjectStoppedRunning.Subscribe(ProjectStoppedRunning);
|
||||
}
|
||||
|
||||
private void OnVariablesItemExpandedOrCollapsed(TreeItem item)
|
||||
{
|
||||
var wasExpanded = item.IsCollapsed() is false;
|
||||
var metadata = item.GetMetadata(0).AsVector2I();
|
||||
var alreadyRetrievedChildren = metadata.X == 1;
|
||||
if (wasExpanded && alreadyRetrievedChildren is false)
|
||||
{
|
||||
// retrieve children
|
||||
var variablesReferenceId = metadata.Y;
|
||||
_ = Task.GodotRun(async () =>
|
||||
{
|
||||
var variables = await _runService.GetVariablesForVariablesReference(variablesReferenceId);
|
||||
await this.InvokeAsync(() =>
|
||||
{
|
||||
var firstChild = item.GetFirstChild();
|
||||
Guard.Against.Null(firstChild);
|
||||
item.RemoveChild(firstChild);
|
||||
foreach (var variable in variables)
|
||||
{
|
||||
AddVariableToTreeItem(item, variable);
|
||||
}
|
||||
// mark as retrieved
|
||||
item.SetMetadata(0, new Vector2I(1, variablesReferenceId));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
GlobalEvents.Instance.DebuggerExecutionStopped.Unsubscribe(OnDebuggerExecutionStopped);
|
||||
@@ -90,11 +120,23 @@ public partial class ThreadsVariablesSubTab : Control
|
||||
var root = _variablesTree.CreateItem();
|
||||
foreach (var variable in variables)
|
||||
{
|
||||
var variableItem = _variablesTree.CreateItem(root);
|
||||
variableItem.SetText(0, $$"""{{variable.Name}} = {{{variable.Type}}} {{variable.Value}}""");
|
||||
AddVariableToTreeItem(root, variable);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void AddVariableToTreeItem(TreeItem parentItem, Variable variable)
|
||||
{
|
||||
var variableItem = _variablesTree.CreateItem(parentItem);
|
||||
variableItem.SetText(0, $$"""{{variable.Name}} = {{{variable.Type}}} {{variable.Value}}""");
|
||||
variableItem.SetMetadata(0, new Vector2I(0, variable.VariablesReference));
|
||||
if (variable.VariablesReference is not 0)
|
||||
{
|
||||
var placeHolderItem = _variablesTree.CreateItem(variableItem);
|
||||
placeHolderItem.SetText(0, "Loading...");
|
||||
variableItem.Collapsed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task OnDebuggerExecutionStopped(ExecutionStopInfo stopInfo)
|
||||
|
||||
Reference in New Issue
Block a user