Welcome to mirror list, hosted at ThFree Co, Russian Federation.

VsCodeObjectSource.cs « MonoDevelop.Debugger.VsCodeDebugProtocol « MonoDevelop.Debugger.VSCodeDebugProtocol « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 02fd9fc481b7920d7d515ac6102cc838708c19fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Linq;
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages;
using Mono.Debugging.Backend;
using Mono.Debugging.Client;

namespace MonoDevelop.Debugger.VsCodeDebugProtocol
{
	class VSCodeObjectSource : IObjectValueSource
	{

		int parentVariablesReference;
		int variablesReference;
		int frameId;
		VSCodeDebuggerSession vsCodeDebuggerSession;
		ObjectValue [] objValChildren;
		readonly string name;
		readonly string evalName;
		readonly string type;
		readonly string val;


		public VSCodeObjectSource (VSCodeDebuggerSession vsCodeDebuggerSession, int variablesReference, int parentVariablesReference, string name, string type, string evalName, int frameId, string val)
		{
			this.type = type ?? string.Empty;
			this.frameId = frameId;
			this.evalName = evalName;
			var indexOfType = name.LastIndexOf (" [", StringComparison.Ordinal);
			if (indexOfType != -1)
				name = name.Remove (indexOfType);
			this.name = name;
			this.vsCodeDebuggerSession = vsCodeDebuggerSession;
			this.variablesReference = variablesReference;
			this.parentVariablesReference = parentVariablesReference;
			this.val = val;
		}

		public ObjectValue [] GetChildren (ObjectPath path, int index, int count, EvaluationOptions options)
		{
			if (objValChildren == null) {
				if (variablesReference <= 0) {
					objValChildren = new ObjectValue [0];
				} else {
					using (var timer = vsCodeDebuggerSession.EvaluationStats.StartTimer ()) {
						var children = vsCodeDebuggerSession.protocolClient.SendRequestSync (new VariablesRequest (
							variablesReference
						)).Variables;
						objValChildren = children.Select (c => VSCodeDebuggerBacktrace.VsCodeVariableToObjectValue (vsCodeDebuggerSession, c.Name, c.EvaluateName, c.Type, c.Value, c.VariablesReference, variablesReference, frameId)).ToArray ();
						timer.Success = true;
					}
				}
			}
			return objValChildren;
		}

		class RawString : IRawValueString
		{
			string val;

			public RawString (string val)
			{
				this.val = val.Remove (val.Length - 1).Remove (0, 1);
			}

			public int Length {
				get {
					return val.Length;
				}
			}

			public string Value {
				get {
					return val;
				}
			}

			public string Substring (int index, int length)
			{
				return val.Substring (index, length);
			}
		}

		public object GetRawValue (ObjectPath path, EvaluationOptions options)
		{
			string val = null;
			using (var timer = vsCodeDebuggerSession.EvaluationStats.StartTimer ()) {
				val = vsCodeDebuggerSession.protocolClient.SendRequestSync (new EvaluateRequest (evalName, frameId)).Result;
				timer.Success = true;
			}
			if (val.StartsWith ("\"", StringComparison.Ordinal))
				if (options.ChunkRawStrings)
					return new RawValueString (new RawString (val));
				else
					return val.Remove (val.Length - 1).Remove (0, 1);
			else
				throw new NotImplementedException ();
		}

		public ObjectValue GetValue (ObjectPath path, EvaluationOptions options)
		{
			if (val == "null")
				return ObjectValue.CreateNullObject (this, name, type, parentVariablesReference > 0 ? ObjectValueFlags.None : ObjectValueFlags.ReadOnly);
			if (variablesReference == 0)//This is some kind of primitive...
				return ObjectValue.CreatePrimitive (this, new ObjectPath (name), type, new EvaluationResult (val), parentVariablesReference > 0 ? ObjectValueFlags.None : ObjectValueFlags.ReadOnly);
			return ObjectValue.CreateObject (this, new ObjectPath (name), type, new EvaluationResult (val), parentVariablesReference > 0 ? ObjectValueFlags.None : ObjectValueFlags.ReadOnly, null);
		}

		public void SetRawValue (ObjectPath path, object value, EvaluationOptions options)
		{
			var v = value.ToString ();
			if (type == "string")
				v = $"\"{v}\"";
			vsCodeDebuggerSession.protocolClient.SendRequestSync (new SetVariableRequest (parentVariablesReference, name, v));
		}

		public EvaluationResult SetValue (ObjectPath path, string value, EvaluationOptions options)
		{
			return new EvaluationResult (vsCodeDebuggerSession.protocolClient.SendRequestSync (new SetVariableRequest (parentVariablesReference, name, value)).Value);
		}
	}
}