Skip to content

Commit 989251e

Browse files
authored
Merge pull request #1395 from microsoft/dev/andarno/addDisplayName
Add `JsonRpc.DisplayName` property
2 parents 7f37b36 + 6e53033 commit 989251e

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

src/StreamJsonRpc/JsonRpc.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace StreamJsonRpc;
2020
/// <summary>
2121
/// Manages a JSON-RPC connection with another entity over a <see cref="Stream"/>.
2222
/// </summary>
23+
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
2324
public class JsonRpc : IDisposableObservable, IJsonRpcFormatterCallbacks, IJsonRpcTracingCallbacks, ExceptionSerializationHelpers.IExceptionTypeLoader
2425
{
2526
/// <summary>
@@ -511,6 +512,14 @@ public JoinableTaskTokenTracker JoinableTaskTracker
511512
}
512513
}
513514

515+
/// <summary>
516+
/// Gets a human-readable name that can be used to identify this <see cref="JsonRpc"/> instance.
517+
/// </summary>
518+
/// <remarks>
519+
/// This value is not used for any RPC functionality. It's merely an aid to help backtrace this instance to its creator.
520+
/// </remarks>
521+
public string? DisplayName { get; init; }
522+
514523
/// <summary>
515524
/// Gets a <see cref="Task"/> that completes when this instance is disposed or when listening has stopped
516525
/// whether by error, disposal or the stream closing.
@@ -708,6 +717,8 @@ internal ExceptionSerializationHelpers.IExceptionTypeLoader TrimUnsafeTypeLoader
708717
/// </summary>
709718
private bool HasListeningStarted => this.readLinesTask is not null;
710719

720+
private string DebuggerDisplay => $"JsonRpc: {this.DisplayName ?? "(anonymous)"}";
721+
711722
/// <summary>
712723
/// Initializes a new instance of the <see cref="JsonRpc"/> class that uses
713724
/// <see cref="HeaderDelimitedMessageHandler"/> around messages serialized using the

src/StreamJsonRpc/NerdbankMessagePackFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public NerdbankMessagePackFormatter()
131131
public MessagePackSerializer UserDataSerializer
132132
{
133133
get => this.userDataSerializer;
134-
[MemberNotNull(nameof(this.userDataSerializer))]
134+
[MemberNotNull(nameof(userDataSerializer))]
135135
init
136136
{
137137
Requires.NotNull(value);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
/// <summary>
5+
/// <see cref="JsonRpc"/> tests that don't exercise the <see cref="IJsonRpcMessageHandler"/> or <see cref="IJsonRpcMessageFormatter"/>.
6+
/// </summary>
7+
public class JsonRpcSimpleTests
8+
{
9+
[Fact]
10+
public void DisplayName_Default()
11+
{
12+
JsonRpc jsonRpc = new JsonRpc(Stream.Null);
13+
Assert.Null(jsonRpc.DisplayName);
14+
}
15+
16+
[Fact]
17+
public void DisplayName_Settable()
18+
{
19+
JsonRpc jsonRpc = new(Stream.Null)
20+
{
21+
DisplayName = "Test name",
22+
};
23+
24+
Assert.Equal("Test name", jsonRpc.DisplayName);
25+
}
26+
}

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "2.24",
3+
"version": "2.25",
44
"publicReleaseRefSpec": [
55
"^refs/heads/main$",
66
"^refs/heads/v\\d+(?:.\\d+)?$"

0 commit comments

Comments
 (0)