Skip to content

Commit 9407981

Browse files
Sprinkle a little debugger display everywhere (#262)
Added some debuggerdisplay attributes and friends
1 parent 48bda7d commit 9407981

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+363
-25
lines changed

.vscode/csharp.code-snippets

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
// Place your csharp-language-server-protocol workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
3+
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
4+
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
5+
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
6+
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
7+
// Placeholders with the same ids are connected.
8+
// Example:
9+
// "Print to console": {
10+
// "scope": "javascript,typescript",
11+
// "prefix": "log",
12+
// "body": [
13+
// "console.log('$1');",
14+
// "$2"
15+
// ],
16+
// "description": "Log output to console"
17+
// }
18+
"Debugger Display Attribute": {
19+
"prefix": "dda",
20+
"scope": "csharp",
21+
"description": "Adds debugger display attribute",
22+
"body": [
23+
"[DebuggerDisplay(\"{\" + nameof(DebuggerDisplay) + \",nq}\")]"
24+
]
25+
},
26+
"Debugger Display Property": {
27+
"prefix": "ddc",
28+
"scope": "csharp",
29+
"description": "Adds debugger display property",
30+
"body": [
31+
"private string DebuggerDisplay => $1;",
32+
"/// <inheritdoc />",
33+
"public override string ToString() => DebuggerDisplay;"
34+
]
35+
}
36+
}

src/Dap.Protocol/Events/BreakpointEvent.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using OmniSharp.Extensions.DebugAdapter.Protocol.Models;
23
using MediatR;
34
using OmniSharp.Extensions.JsonRpc;

src/Dap.Protocol/Models/Breakpoint.cs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace OmniSharp.Extensions.DebugAdapter.Protocol.Models
55
/// <summary>
66
/// Information about a Breakpoint created in setBreakpoints or setFunctionBreakpoints.
77
/// </summary>
8+
89
public class Breakpoint
910
{
1011
/// <summary>

src/Protocol/Models/ClientInfo.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
23

34
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
@@ -7,6 +8,7 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
78
///
89
/// @since 3.15.0
910
/// </summary>
11+
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
1012
public class ClientInfo
1113
{
1214

@@ -20,5 +22,9 @@ public class ClientInfo
2022
/// </summary>
2123
[Optional]
2224
public string Version { get; set; }
25+
26+
private string DebuggerDisplay => string.IsNullOrWhiteSpace(Version) ? Name : $"{Name} ({Version})";
27+
/// <inheritdoc />
28+
public override string ToString() => DebuggerDisplay;
2329
}
2430
}

src/Protocol/Models/CodeAction.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
using System.Diagnostics;
12
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
23

34
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
45
{
6+
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
57
public class CodeAction
68
{
79
/// <summary>
@@ -48,5 +50,9 @@ public class CodeAction
4850
/// </summary>
4951
[Optional]
5052
public Command Command { get; set; }
53+
54+
private string DebuggerDisplay => $"[{Kind}] {Title}";
55+
/// <inheritdoc />
56+
public override string ToString() => DebuggerDisplay;
5157
}
5258
}

src/Protocol/Models/CodeActionKind.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
88
/// <summary>
99
/// A set of predefined code action kinds
1010
/// </summary>
11-
[DebuggerDisplay("{_value}")]
11+
[DebuggerDisplay("{" + nameof(_value) + "}")]
1212
[JsonConverter(typeof(EnumLikeStringConverter))]
1313
public readonly struct CodeActionKind : IEquatable<CodeActionKind>, IEnumLikeString
1414
{
@@ -95,6 +95,7 @@ public static implicit operator string(CodeActionKind kind)
9595
return kind._value;
9696
}
9797

98+
/// <inheritdoc />
9899
public override string ToString() => _value;
99100
public bool Equals(CodeActionKind other) => _value == other._value;
100101

src/Protocol/Models/CodeLens.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using MediatR;
23
using Newtonsoft.Json.Linq;
34
using OmniSharp.Extensions.JsonRpc;
@@ -12,6 +13,7 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
1213
/// A code lens is _unresolved_ when no command is associated to it. For performance
1314
/// reasons the creation of a code lens and resolving should be done in two stages.
1415
/// </summary>
16+
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
1517
[Method(TextDocumentNames.CodeLensResolve, Direction.ClientToServer)]
1618
public class CodeLens : ICanBeResolved, IRequest<CodeLens>
1719
{
@@ -32,5 +34,9 @@ public class CodeLens : ICanBeResolved, IRequest<CodeLens>
3234
/// </summary>
3335
[Optional]
3436
public JToken Data { get; set; }
37+
38+
private string DebuggerDisplay => $"{Range}{(Command != null ? $" Command" : "")}";
39+
/// <inheritdoc />
40+
public override string ToString() => DebuggerDisplay;
3541
}
3642
}

src/Protocol/Models/Command.cs

+8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
using System.Diagnostics;
2+
using System.Linq;
13
using Newtonsoft.Json;
24
using Newtonsoft.Json.Linq;
35
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
46

57
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
68
{
9+
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
710
public class Command
811
{
912
/// <summary>
@@ -23,5 +26,10 @@ public class Command
2326
/// </summary>
2427
[Optional]
2528
public JArray Arguments { get; set; }
29+
30+
private string DebuggerDisplay =>
31+
$"{Title}{(string.IsNullOrWhiteSpace(Name) ? "" : $" {Name}")}{(Arguments == null ? "" : string.Join(", ", Arguments.Select(z => z.ToString().Trim('"'))))}";
32+
33+
public override string ToString() => DebuggerDisplay;
2634
}
2735
}

src/Protocol/Models/CommandOrCodeAction.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
using System.Diagnostics;
2+
13
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
24
{
5+
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
36
public struct CommandOrCodeAction
47
{
58
private CodeAction _codeAction;
@@ -19,8 +22,7 @@ public CommandOrCodeAction(Command value)
1922
public Command Command
2023
{
2124
get { return this._command; }
22-
set
23-
{
25+
set {
2426
this._command = value;
2527
this._codeAction = null;
2628
}
@@ -30,16 +32,14 @@ public Command Command
3032
public CodeAction CodeAction
3133
{
3234
get { return this._codeAction; }
33-
set
34-
{
35+
set {
3536
this._command = default;
3637
this._codeAction = value;
3738
}
3839
}
3940
public object RawValue
4041
{
41-
get
42-
{
42+
get {
4343
if (IsCommand) return Command;
4444
if (IsCodeAction) return CodeAction;
4545
return default;
@@ -55,5 +55,9 @@ public static implicit operator CommandOrCodeAction(CodeAction value)
5555
{
5656
return new CommandOrCodeAction(value);
5757
}
58+
59+
private string DebuggerDisplay => $"{(IsCommand ? $"command: {Command}" : IsCodeAction ? $"code action: {CodeAction}" : "...")}";
60+
/// <inheritdoc />
61+
public override string ToString() => DebuggerDisplay;
5862
}
5963
}

src/Protocol/Models/CompletionItem.cs

+7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
using System.Diagnostics;
2+
using System.Linq;
13
using MediatR;
24
using Newtonsoft.Json.Linq;
35
using OmniSharp.Extensions.JsonRpc;
46
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
57

68
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
79
{
10+
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
811
[Method(TextDocumentNames.CompletionResolve, Direction.ClientToServer)]
912
public class CompletionItem : ICanBeResolved, IRequest<CompletionItem>
1013
{
@@ -129,5 +132,9 @@ public class CompletionItem : ICanBeResolved, IRequest<CompletionItem>
129132
/// </summary>
130133
[Optional]
131134
public JToken Data { get; set; }
135+
136+
private string DebuggerDisplay => $"[{Kind}] {Label}{(Tags?.Any() == true ? $" tags: {string.Join(", ", Tags.Select(z => z.ToString()))}" : "")}";
137+
/// <inheritdoc />
138+
public override string ToString() => DebuggerDisplay;
132139
}
133140
}

src/Protocol/Models/Diagnostic.cs

+10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
using System.Diagnostics;
2+
using System.Linq;
13
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
24

35
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
46
{
7+
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
58
public class Diagnostic
69
{
710
/// <summary>
@@ -48,5 +51,12 @@ public class Diagnostic
4851
/// </summary>
4952
[Optional]
5053
public Container<DiagnosticRelatedInformation> RelatedInformation { get; set; }
54+
55+
private string DebuggerDisplay =>
56+
$"{(Code.HasValue ? $"[{Code.Value.ToString()}]" : "")}" +
57+
$"{Range}" +
58+
$"{(string.IsNullOrWhiteSpace(Source) ? "" : $" ({Source})")}" +
59+
$"{(Tags?.Any() == true ? $" [tags: {string.Join(", ", Tags.Select(z => z.ToString()))}]" : "")}" +
60+
$" {(Message?.Length > 20 ? Message.Substring(0, 20) : Message)}";
5161
}
5262
}

src/Protocol/Models/DocumentColor.cs

+8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
using System.Diagnostics;
2+
using System.Reflection.Emit;
3+
14
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
25
{
36
/// <summary>
47
/// Represents a color in RGBA space.
58
/// </summary>
9+
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
610
public class DocumentColor
711
{
812
/// <summary>
@@ -24,5 +28,9 @@ public class DocumentColor
2428
/// The alpha component of this color in the range [0-1].
2529
/// </summary>
2630
public double Alpha { get; set; }
31+
32+
private string DebuggerDisplay => $"R:{Red} G:{Green} B:{Blue} A:{Alpha}";
33+
/// <inheritdoc />
34+
public override string ToString() => DebuggerDisplay;
2735
}
2836
}

src/Protocol/Models/DocumentFilter.cs

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using Minimatch;
45
using Newtonsoft.Json;
56
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
67
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
78

89
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
910
{
11+
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
1012
public class DocumentFilter : IEquatable<DocumentFilter>
1113
{
1214
public static DocumentFilter ForPattern(string wildcard)
@@ -55,8 +57,7 @@ public static DocumentFilter ForScheme(string scheme)
5557
public string Pattern
5658
{
5759
get => _pattern;
58-
set
59-
{
60+
set {
6061
_pattern = value;
6162
_minimatcher = new Minimatcher(value, new Options() { MatchBase = true });
6263
}
@@ -78,14 +79,17 @@ public static explicit operator string(DocumentFilter documentFilter)
7879
{
7980
items.Add(documentFilter.Language);
8081
}
82+
8183
if (documentFilter.HasScheme)
8284
{
8385
items.Add(documentFilter.Scheme);
8486
}
87+
8588
if (documentFilter.HasPattern)
8689
{
8790
items.Add(documentFilter.Pattern);
8891
}
92+
8993
return $"[{string.Join(", ", items)}]";
9094
}
9195

@@ -95,33 +99,40 @@ public bool IsMatch(TextDocumentAttributes attributes)
9599
{
96100
return Language == attributes.LanguageId && Scheme == attributes.Scheme && _minimatcher.IsMatch(attributes.Uri.ToString());
97101
}
102+
98103
if (HasLanguage && HasPattern)
99104
{
100105
return Language == attributes.LanguageId && _minimatcher.IsMatch(attributes.Uri.ToString());
101106
}
107+
102108
if (HasLanguage && HasScheme)
103109
{
104110
return Language == attributes.LanguageId && Scheme == attributes.Scheme;
105111
}
112+
106113
if (HasPattern && HasScheme)
107114
{
108115
return Scheme == attributes.Scheme && _minimatcher.IsMatch(attributes.Uri.ToString());
109116
}
117+
110118
if (HasLanguage)
111119
{
112120
return Language == attributes.LanguageId;
113121
}
122+
114123
if (HasScheme)
115124
{
116125
return Scheme == attributes.Scheme;
117126
}
127+
118128
if (HasPattern)
119129
{
120130
return _minimatcher.IsMatch(attributes.Uri.ToString());
121131
}
122132

123133
return false;
124134
}
135+
125136
public bool Equals(DocumentFilter other)
126137
{
127138
if (ReferenceEquals(null, other)) return false;
@@ -134,7 +145,7 @@ public override bool Equals(object obj)
134145
if (ReferenceEquals(null, obj)) return false;
135146
if (ReferenceEquals(this, obj)) return true;
136147
if (obj.GetType() != this.GetType()) return false;
137-
return Equals((DocumentFilter) obj);
148+
return Equals((DocumentFilter)obj);
138149
}
139150

140151
public override int GetHashCode()
@@ -151,5 +162,9 @@ public override int GetHashCode()
151162
public static bool operator ==(DocumentFilter left, DocumentFilter right) => Equals(left, right);
152163

153164
public static bool operator !=(DocumentFilter left, DocumentFilter right) => !Equals(left, right);
165+
166+
private string DebuggerDisplay => (string)this;
167+
/// <inheritdoc />
168+
public override string ToString() => DebuggerDisplay;
154169
}
155170
}

0 commit comments

Comments
 (0)