Skip to content

Sprinkle a little debugger display everywhere #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .vscode/csharp.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// Place your csharp-language-server-protocol workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Debugger Display Attribute": {
"prefix": "dda",
"scope": "csharp",
"description": "Adds debugger display attribute",
"body": [
"[DebuggerDisplay(\"{\" + nameof(DebuggerDisplay) + \",nq}\")]"
]
},
"Debugger Display Property": {
"prefix": "ddc",
"scope": "csharp",
"description": "Adds debugger display property",
"body": [
"private string DebuggerDisplay => $1;",
"/// <inheritdoc />",
"public override string ToString() => DebuggerDisplay;"
]
}
}
1 change: 1 addition & 0 deletions src/Dap.Protocol/Events/BreakpointEvent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using OmniSharp.Extensions.DebugAdapter.Protocol.Models;
using MediatR;
using OmniSharp.Extensions.JsonRpc;
Expand Down
1 change: 1 addition & 0 deletions src/Dap.Protocol/Models/Breakpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace OmniSharp.Extensions.DebugAdapter.Protocol.Models
/// <summary>
/// Information about a Breakpoint created in setBreakpoints or setFunctionBreakpoints.
/// </summary>

public class Breakpoint
{
/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions src/Protocol/Models/ClientInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;

namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
Expand All @@ -7,6 +8,7 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
///
/// @since 3.15.0
/// </summary>
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
public class ClientInfo
{

Expand All @@ -20,5 +22,9 @@ public class ClientInfo
/// </summary>
[Optional]
public string Version { get; set; }

private string DebuggerDisplay => string.IsNullOrWhiteSpace(Version) ? Name : $"{Name} ({Version})";
/// <inheritdoc />
public override string ToString() => DebuggerDisplay;
}
}
6 changes: 6 additions & 0 deletions src/Protocol/Models/CodeAction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Diagnostics;
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;

namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
{
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
public class CodeAction
{
/// <summary>
Expand Down Expand Up @@ -48,5 +50,9 @@ public class CodeAction
/// </summary>
[Optional]
public Command Command { get; set; }

private string DebuggerDisplay => $"[{Kind}] {Title}";
/// <inheritdoc />
public override string ToString() => DebuggerDisplay;
}
}
3 changes: 2 additions & 1 deletion src/Protocol/Models/CodeActionKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
/// <summary>
/// A set of predefined code action kinds
/// </summary>
[DebuggerDisplay("{_value}")]
[DebuggerDisplay("{" + nameof(_value) + "}")]
[JsonConverter(typeof(EnumLikeStringConverter))]
public readonly struct CodeActionKind : IEquatable<CodeActionKind>, IEnumLikeString
{
Expand Down Expand Up @@ -95,6 +95,7 @@ public static implicit operator string(CodeActionKind kind)
return kind._value;
}

/// <inheritdoc />
public override string ToString() => _value;
public bool Equals(CodeActionKind other) => _value == other._value;

Expand Down
6 changes: 6 additions & 0 deletions src/Protocol/Models/CodeLens.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using MediatR;
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.JsonRpc;
Expand All @@ -12,6 +13,7 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
/// A code lens is _unresolved_ when no command is associated to it. For performance
/// reasons the creation of a code lens and resolving should be done in two stages.
/// </summary>
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
[Method(TextDocumentNames.CodeLensResolve, Direction.ClientToServer)]
public class CodeLens : ICanBeResolved, IRequest<CodeLens>
{
Expand All @@ -32,5 +34,9 @@ public class CodeLens : ICanBeResolved, IRequest<CodeLens>
/// </summary>
[Optional]
public JToken Data { get; set; }

private string DebuggerDisplay => $"{Range}{(Command != null ? $" Command" : "")}";
/// <inheritdoc />
public override string ToString() => DebuggerDisplay;
}
}
8 changes: 8 additions & 0 deletions src/Protocol/Models/Command.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Diagnostics;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;

namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
{
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
public class Command
{
/// <summary>
Expand All @@ -23,5 +26,10 @@ public class Command
/// </summary>
[Optional]
public JArray Arguments { get; set; }

private string DebuggerDisplay =>
$"{Title}{(string.IsNullOrWhiteSpace(Name) ? "" : $" {Name}")}{(Arguments == null ? "" : string.Join(", ", Arguments.Select(z => z.ToString().Trim('"'))))}";

public override string ToString() => DebuggerDisplay;
}
}
16 changes: 10 additions & 6 deletions src/Protocol/Models/CommandOrCodeAction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.Diagnostics;

namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
{
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
public struct CommandOrCodeAction
{
private CodeAction _codeAction;
Expand All @@ -19,8 +22,7 @@ public CommandOrCodeAction(Command value)
public Command Command
{
get { return this._command; }
set
{
set {
this._command = value;
this._codeAction = null;
}
Expand All @@ -30,16 +32,14 @@ public Command Command
public CodeAction CodeAction
{
get { return this._codeAction; }
set
{
set {
this._command = default;
this._codeAction = value;
}
}
public object RawValue
{
get
{
get {
if (IsCommand) return Command;
if (IsCodeAction) return CodeAction;
return default;
Expand All @@ -55,5 +55,9 @@ public static implicit operator CommandOrCodeAction(CodeAction value)
{
return new CommandOrCodeAction(value);
}

private string DebuggerDisplay => $"{(IsCommand ? $"command: {Command}" : IsCodeAction ? $"code action: {CodeAction}" : "...")}";
/// <inheritdoc />
public override string ToString() => DebuggerDisplay;
}
}
7 changes: 7 additions & 0 deletions src/Protocol/Models/CompletionItem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System.Diagnostics;
using System.Linq;
using MediatR;
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.JsonRpc;
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;

namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
{
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
[Method(TextDocumentNames.CompletionResolve, Direction.ClientToServer)]
public class CompletionItem : ICanBeResolved, IRequest<CompletionItem>
{
Expand Down Expand Up @@ -129,5 +132,9 @@ public class CompletionItem : ICanBeResolved, IRequest<CompletionItem>
/// </summary>
[Optional]
public JToken Data { get; set; }

private string DebuggerDisplay => $"[{Kind}] {Label}{(Tags?.Any() == true ? $" tags: {string.Join(", ", Tags.Select(z => z.ToString()))}" : "")}";
/// <inheritdoc />
public override string ToString() => DebuggerDisplay;
}
}
10 changes: 10 additions & 0 deletions src/Protocol/Models/Diagnostic.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.Diagnostics;
using System.Linq;
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;

namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
{
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
public class Diagnostic
{
/// <summary>
Expand Down Expand Up @@ -48,5 +51,12 @@ public class Diagnostic
/// </summary>
[Optional]
public Container<DiagnosticRelatedInformation> RelatedInformation { get; set; }

private string DebuggerDisplay =>
$"{(Code.HasValue ? $"[{Code.Value.ToString()}]" : "")}" +
$"{Range}" +
$"{(string.IsNullOrWhiteSpace(Source) ? "" : $" ({Source})")}" +
$"{(Tags?.Any() == true ? $" [tags: {string.Join(", ", Tags.Select(z => z.ToString()))}]" : "")}" +
$" {(Message?.Length > 20 ? Message.Substring(0, 20) : Message)}";
}
}
8 changes: 8 additions & 0 deletions src/Protocol/Models/DocumentColor.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System.Diagnostics;
using System.Reflection.Emit;

namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
{
/// <summary>
/// Represents a color in RGBA space.
/// </summary>
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
public class DocumentColor
{
/// <summary>
Expand All @@ -24,5 +28,9 @@ public class DocumentColor
/// The alpha component of this color in the range [0-1].
/// </summary>
public double Alpha { get; set; }

private string DebuggerDisplay => $"R:{Red} G:{Green} B:{Blue} A:{Alpha}";
/// <inheritdoc />
public override string ToString() => DebuggerDisplay;
}
}
21 changes: 18 additions & 3 deletions src/Protocol/Models/DocumentFilter.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Minimatch;
using Newtonsoft.Json;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;

namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
{
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
public class DocumentFilter : IEquatable<DocumentFilter>
{
public static DocumentFilter ForPattern(string wildcard)
Expand Down Expand Up @@ -55,8 +57,7 @@ public static DocumentFilter ForScheme(string scheme)
public string Pattern
{
get => _pattern;
set
{
set {
_pattern = value;
_minimatcher = new Minimatcher(value, new Options() { MatchBase = true });
}
Expand All @@ -78,14 +79,17 @@ public static explicit operator string(DocumentFilter documentFilter)
{
items.Add(documentFilter.Language);
}

if (documentFilter.HasScheme)
{
items.Add(documentFilter.Scheme);
}

if (documentFilter.HasPattern)
{
items.Add(documentFilter.Pattern);
}

return $"[{string.Join(", ", items)}]";
}

Expand All @@ -95,33 +99,40 @@ public bool IsMatch(TextDocumentAttributes attributes)
{
return Language == attributes.LanguageId && Scheme == attributes.Scheme && _minimatcher.IsMatch(attributes.Uri.ToString());
}

if (HasLanguage && HasPattern)
{
return Language == attributes.LanguageId && _minimatcher.IsMatch(attributes.Uri.ToString());
}

if (HasLanguage && HasScheme)
{
return Language == attributes.LanguageId && Scheme == attributes.Scheme;
}

if (HasPattern && HasScheme)
{
return Scheme == attributes.Scheme && _minimatcher.IsMatch(attributes.Uri.ToString());
}

if (HasLanguage)
{
return Language == attributes.LanguageId;
}

if (HasScheme)
{
return Scheme == attributes.Scheme;
}

if (HasPattern)
{
return _minimatcher.IsMatch(attributes.Uri.ToString());
}

return false;
}

public bool Equals(DocumentFilter other)
{
if (ReferenceEquals(null, other)) return false;
Expand All @@ -134,7 +145,7 @@ public override bool Equals(object obj)
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((DocumentFilter) obj);
return Equals((DocumentFilter)obj);
}

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

public static bool operator !=(DocumentFilter left, DocumentFilter right) => !Equals(left, right);

private string DebuggerDisplay => (string)this;
/// <inheritdoc />
public override string ToString() => DebuggerDisplay;
}
}
Loading