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

Lines changed: 36 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 10 additions & 6 deletions
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

Lines changed: 7 additions & 0 deletions
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
}

0 commit comments

Comments
 (0)