Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ public async Task<ExtensionMessageResponse> HandleRequestAsync(ExtensionDocument
var solution = context.Document.Project.Solution;

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

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

return new ExtensionMessageResponse(response!);
return new ExtensionMessageResponse(
response,
extensionWasUnloaded,
ExtensionException.FromException(exception));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Text.Json.Serialization;

namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Extensions;

internal sealed record class ExtensionException(
[property: JsonPropertyName("typeName")] string TypeName,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this - however I would have naively started with serializing System.Exception - I assume we don't want that here? I know the exception type may not exist on the other side, but that is something jsonrpc already has to deal with when we throw exceptions for example.

[property: JsonPropertyName("message")] string Message,
[property: JsonPropertyName("stackTrace"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] string? StackTrace,
[property: JsonPropertyName("innerException"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] ExtensionException? InnerException)
{
public static ExtensionException? FromException(Exception? exception)
=> exception is null
? null
: new ExtensionException(exception.GetType().ToString(), exception.Message, exception.StackTrace, FromException(exception.InnerException));
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Extensions;
/// <summary>
/// Return type for the roslyn/extensionWorkspaceMessage and roslyn/extensionDocumentMessage request.
/// </summary>
/// <param name="Response">Json response returned by the extension message handler.</param>
/// <param name="Response">Json response returned by the extension message handler. Can be <see langword="null"/> if the
/// extension was unloaded concurrently with the response being issued, or if the extension threw an exception while
/// processing.</param>
internal readonly record struct ExtensionMessageResponse(
[property: JsonPropertyName("response")] string Response);
[property: JsonPropertyName("response"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] string? Response,
[property: JsonPropertyName("extensionWasUnloaded"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] bool ExtensionWasUnloaded,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New field to represent a supported failure mode that does not return a respone and was not an exception itself throwing an exception.

[property: JsonPropertyName("extensionException"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
ExtensionException? ExtensionException);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matteo-prosperi up to you what you will do with this info on the gladstone side.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public async Task<ExtensionRegisterResponse> HandleRequestAsync(ExtensionRegiste
if (handlerNames.ExtensionException is not null)
context.Logger.LogException(handlerNames.ExtensionException);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dibarbet i'm still logging this here (as well as passing back to Gladstone). is that ok with you ?


return new(handlerNames.WorkspaceMessageHandlers, handlerNames.DocumentMessageHandlers);
return new(
handlerNames.WorkspaceMessageHandlers,
handlerNames.DocumentMessageHandlers,
ExtensionException.FromException(handlerNames.ExtensionException));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler.Extensions;
/// </summary>
/// <param name="WorkspaceMessageHandlers">Names of the registered non-document-specific extension message handlers.</param>
/// <param name="DocumentMessageHandlers">Names of the registered document-specific extension message handlers.</param>
internal readonly record struct ExtensionRegisterResponse(
/// <param name="ExtensionException">Details of any exceptions that occurred during extension registration.</param>
internal sealed record class ExtensionRegisterResponse(
[property: JsonPropertyName("workspaceMessageHandlers")] ImmutableArray<string> WorkspaceMessageHandlers,
[property: JsonPropertyName("documentMessageHandlers")] ImmutableArray<string> DocumentMessageHandlers);
[property: JsonPropertyName("documentMessageHandlers")] ImmutableArray<string> DocumentMessageHandlers,
[property: JsonPropertyName("extensionException"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
ExtensionException? ExtensionException);
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ public async Task<ExtensionMessageResponse> HandleRequestAsync(ExtensionWorkspac
var solution = context.Solution;

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

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

return new ExtensionMessageResponse(response!);
return new ExtensionMessageResponse(
response,
extensionWasUnloaded,
ExtensionException.FromException(exception));
}
}
Loading