Skip to content

Commit 08759c1

Browse files
Update gladstone/roslyn api (#78057)
Dependent on #78056
2 parents e2d8d46 + 1b88ce9 commit 08759c1

File tree

6 files changed

+46
-9
lines changed

6 files changed

+46
-9
lines changed

src/LanguageServer/Protocol/Handler/Extensions/ExtensionDocumentMessageHandler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ public async Task<ExtensionMessageResponse> HandleRequestAsync(ExtensionDocument
3131
var solution = context.Document.Project.Solution;
3232

3333
var service = solution.Services.GetRequiredService<IExtensionMessageHandlerService>();
34-
var (response, _, exception) = await service.HandleExtensionDocumentMessageAsync(
34+
var (response, extensionWasUnloaded, exception) = await service.HandleExtensionDocumentMessageAsync(
3535
context.Document, request.MessageName, request.Message, cancellationToken).ConfigureAwait(false);
3636

3737
// Report any exceptions the extension itself caused while handling the request.
3838
if (exception is not null)
3939
context.Logger.LogException(exception);
4040

41-
return new ExtensionMessageResponse(response!);
41+
return new ExtensionMessageResponse(
42+
response,
43+
extensionWasUnloaded,
44+
ExtensionException.FromException(exception));
4245
}
4346
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Text.Json.Serialization;
7+
8+
namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Extensions;
9+
10+
internal sealed record class ExtensionException(
11+
[property: JsonPropertyName("typeName")] string TypeName,
12+
[property: JsonPropertyName("message")] string Message,
13+
[property: JsonPropertyName("stackTrace"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] string? StackTrace,
14+
[property: JsonPropertyName("innerException"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] ExtensionException? InnerException)
15+
{
16+
public static ExtensionException? FromException(Exception? exception)
17+
=> exception is null
18+
? null
19+
: new ExtensionException(exception.GetType().ToString(), exception.Message, exception.StackTrace, FromException(exception.InnerException));
20+
}

src/LanguageServer/Protocol/Handler/Extensions/ExtensionMessageResponse.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Extensions;
99
/// <summary>
1010
/// Return type for the roslyn/extensionWorkspaceMessage and roslyn/extensionDocumentMessage request.
1111
/// </summary>
12-
/// <param name="Response">Json response returned by the extension message handler.</param>
12+
/// <param name="Response">Json response returned by the extension message handler. Can be <see langword="null"/> if the
13+
/// extension was unloaded concurrently with the response being issued, or if the extension threw an exception while
14+
/// processing.</param>
1315
internal readonly record struct ExtensionMessageResponse(
14-
[property: JsonPropertyName("response")] string Response);
16+
[property: JsonPropertyName("response"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] string? Response,
17+
[property: JsonPropertyName("extensionWasUnloaded"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] bool ExtensionWasUnloaded,
18+
[property: JsonPropertyName("extensionException"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
19+
ExtensionException? ExtensionException);

src/LanguageServer/Protocol/Handler/Extensions/ExtensionRegisterHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public async Task<ExtensionRegisterResponse> HandleRequestAsync(ExtensionRegiste
3434
if (handlerNames.ExtensionException is not null)
3535
context.Logger.LogException(handlerNames.ExtensionException);
3636

37-
return new(handlerNames.WorkspaceMessageHandlers, handlerNames.DocumentMessageHandlers);
37+
return new(
38+
handlerNames.WorkspaceMessageHandlers,
39+
handlerNames.DocumentMessageHandlers,
40+
ExtensionException.FromException(handlerNames.ExtensionException));
3841
}
3942
}

src/LanguageServer/Protocol/Handler/Extensions/ExtensionRegisterResponse.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Extensions;
1212
/// </summary>
1313
/// <param name="WorkspaceMessageHandlers">Names of the registered non-document-specific extension message handlers.</param>
1414
/// <param name="DocumentMessageHandlers">Names of the registered document-specific extension message handlers.</param>
15-
internal readonly record struct ExtensionRegisterResponse(
15+
/// <param name="ExtensionException">Details of any exceptions that occurred during extension registration.</param>
16+
internal sealed record class ExtensionRegisterResponse(
1617
[property: JsonPropertyName("workspaceMessageHandlers")] ImmutableArray<string> WorkspaceMessageHandlers,
17-
[property: JsonPropertyName("documentMessageHandlers")] ImmutableArray<string> DocumentMessageHandlers);
18+
[property: JsonPropertyName("documentMessageHandlers")] ImmutableArray<string> DocumentMessageHandlers,
19+
[property: JsonPropertyName("extensionException"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
20+
ExtensionException? ExtensionException);

src/LanguageServer/Protocol/Handler/Extensions/ExtensionWorkspaceMessageHandler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ public async Task<ExtensionMessageResponse> HandleRequestAsync(ExtensionWorkspac
2727
var solution = context.Solution;
2828

2929
var service = solution.Services.GetRequiredService<IExtensionMessageHandlerService>();
30-
var (response, _, exception) = await service.HandleExtensionWorkspaceMessageAsync(
30+
var (response, extensionWasUnloaded, exception) = await service.HandleExtensionWorkspaceMessageAsync(
3131
solution, request.MessageName, request.Message, cancellationToken).ConfigureAwait(false);
3232

3333
// Report any exceptions the extension itself caused while handling the request.
3434
if (exception is not null)
3535
context.Logger.LogException(exception);
3636

37-
return new ExtensionMessageResponse(response!);
37+
return new ExtensionMessageResponse(
38+
response,
39+
extensionWasUnloaded,
40+
ExtensionException.FromException(exception));
3841
}
3942
}

0 commit comments

Comments
 (0)