Skip to content

Commit

Permalink
Add setVariable Debugger Support #139
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneySprings committed Nov 8, 2024
1 parent b1fda97 commit 373ecac
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/DotNet.Meteor.Debug/DebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected override InitializeResponse HandleInitializeRequest(InitializeArgument
SupportsExceptionOptions = true,
SupportsExceptionFilterOptions = true,
SupportsCompletionsRequest = true,
SupportsSetVariable = true,
CompletionTriggerCharacters = new List<string> { "." },
ExceptionBreakpointFilters = new List<ExceptionBreakpointsFilter> {
ExceptionsFilter.AllExceptions
Expand Down Expand Up @@ -441,6 +442,22 @@ protected override CompletionsResponse HandleCompletionsRequest(CompletionsArgum
});
}
#endregion Completions
#region SetVariable
protected override SetVariableResponse HandleSetVariableRequest(SetVariableArguments arguments) {
var variablesDelegate = variableHandles.Get(arguments.VariablesReference, null);
if (variablesDelegate == null)
throw new ProtocolException("VariablesReference not found");

var variables = variablesDelegate.Invoke();
var variable = variables.FirstOrDefault(v => v.Name == arguments.Name);
if (variable == null)
throw new ProtocolException("variable not found");
// No way to use ExternalTypeResolver for setting variables. Use hardcoded value
variable.SetValue(variable.ResolveValue(arguments.Value), session.Options.EvaluationOptions);
variable.Refresh();
return CreateVariable(variable).ToSetVariableResponse();
}
#endregion SetVariable

private void TargetStopped(object? sender, MonoClient.TargetEventArgs e) {
ResetHandles();
Expand Down
11 changes: 11 additions & 0 deletions src/DotNet.Meteor.Debug/Extensions/MonoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ public static string GetMethodName(this SourceLocation sourceLocation) {
public static bool HasNullValue(this ObjectValue objectValue) {
return objectValue.Value == "(null)";
}
public static string ResolveValue(this ObjectValue variable, string value) {
var fullName = variable.TypeName;
if (string.IsNullOrEmpty(fullName))
return value;

var shortName = fullName.Split('.').Last();
if (!value.StartsWith($"new {shortName}"))
return value;

return value.Replace($"new {shortName}", $"new {fullName}");
}
public static ThreadInfo? FindThread(this SoftDebuggerSession session, long id) {
var process = session.GetProcesses().FirstOrDefault();
if (process == null)
Expand Down
9 changes: 9 additions & 0 deletions src/DotNet.Meteor.Debug/Extensions/ServerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,14 @@ public static DebugProtocol.VSSourceLinkInfo ToSourceLinkInfo(this SourceLink so
RelativeFilePath = sourceLink?.RelativeFilePath,
};
}
public static DebugProtocol.SetVariableResponse ToSetVariableResponse(this DebugProtocol.Variable variable) {
return new DebugProtocol.SetVariableResponse {
Value = variable.Value,
Type = variable.Type,
VariablesReference = variable.VariablesReference,
NamedVariables = variable.NamedVariables,
IndexedVariables = variable.IndexedVariables,
};
}
}

0 comments on commit 373ecac

Please sign in to comment.