[Fixes #1094] Use custom JsonConverters for serializing/deserializing TagHelperResolutionResult
This commit is contained in:
parent
5f547d8e32
commit
55d6362325
|
|
@ -10,9 +10,13 @@
|
|||
<RootNamespace>Microsoft.CodeAnalysis.Remote.Razor</RootNamespace>
|
||||
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Microsoft.VisualStudio.LanguageServices.Razor\RazorDiagnosticJsonConverter.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(RoslynDevVersion)" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Remote.Razor.ServiceHub" Version="$(RoslynDevVersion)" />
|
||||
<PackageReference Include="StreamJsonRpc" Version="1.0.2-rc" />
|
||||
<ProjectReference Include="..\Microsoft.CodeAnalysis.Razor.Workspaces\Microsoft.CodeAnalysis.Razor.Workspaces.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.Razor.Evolution\Microsoft.AspNetCore.Razor.Evolution.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Razor.Evolution;
|
||||
using Microsoft.CodeAnalysis.Razor;
|
||||
using Microsoft.VisualStudio.LanguageServices.Razor;
|
||||
|
||||
namespace Microsoft.CodeAnalysis.Remote.Razor
|
||||
{
|
||||
|
|
@ -19,11 +20,13 @@ namespace Microsoft.CodeAnalysis.Remote.Razor
|
|||
public RazorLanguageService(Stream stream, IServiceProvider serviceProvider)
|
||||
: base(stream, serviceProvider)
|
||||
{
|
||||
Rpc.JsonSerializer.Converters.Add(new RazorDiagnosticJsonConverter());
|
||||
}
|
||||
|
||||
public RazorLanguageService(IServiceProvider serviceProvider, Stream stream)
|
||||
: base(serviceProvider, stream)
|
||||
{
|
||||
Rpc.JsonSerializer.Converters.Add(new RazorDiagnosticJsonConverter());
|
||||
}
|
||||
|
||||
public async Task<TagHelperResolutionResult> GetTagHelpersAsync(Guid projectIdBytes, string projectDebugName, IEnumerable<string> assemblyNameFilters, CancellationToken cancellationToken = default(CancellationToken))
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ using Microsoft.CodeAnalysis;
|
|||
using Microsoft.CodeAnalysis.Razor;
|
||||
using Microsoft.VisualStudio.Shell;
|
||||
using Microsoft.VisualStudio.Shell.Interop;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||
{
|
||||
|
|
@ -41,10 +43,12 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
|||
{
|
||||
if (session != null)
|
||||
{
|
||||
result = await session.InvokeAsync<TagHelperResolutionResult>(
|
||||
var jsonObject = await session.InvokeAsync<JObject>(
|
||||
"GetTagHelpersAsync",
|
||||
new object[] { project.Id.Id, "Foo", assemblyNameFilters, }).ConfigureAwait(false);
|
||||
|
||||
result = GetTagHelperResolutionResult(jsonObject);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
// Per https://github.com/dotnet/roslyn/issues/12770 - there's currently no support for documentation in the OOP host
|
||||
|
|
@ -83,6 +87,18 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
|||
}
|
||||
}
|
||||
|
||||
private TagHelperResolutionResult GetTagHelperResolutionResult(JObject jsonObject)
|
||||
{
|
||||
var serializer = new JsonSerializer();
|
||||
serializer.Converters.Add(TagHelperDescriptorJsonConverter.Instance);
|
||||
serializer.Converters.Add(RazorDiagnosticJsonConverter.Instance);
|
||||
|
||||
using (var reader = jsonObject.CreateReader())
|
||||
{
|
||||
return serializer.Deserialize<TagHelperResolutionResult>(reader);
|
||||
}
|
||||
}
|
||||
|
||||
private IReadOnlyList<TagHelperDescriptor> GetDocumentedTagHelpers(Compilation compilation, IReadOnlyList<TagHelperDescriptor> tagHelpers)
|
||||
{
|
||||
var documentedTagHelpers = new List<TagHelperDescriptor>();
|
||||
|
|
|
|||
|
|
@ -10,20 +10,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
|||
private static readonly ResourceManager _resourceManager
|
||||
= new ResourceManager("Microsoft.VisualStudio.LanguageServices.Razor.Resources", typeof(Resources).GetTypeInfo().Assembly);
|
||||
|
||||
/// <summary>
|
||||
/// Deserialization of {0} type '{1}' is not supported.
|
||||
/// </summary>
|
||||
internal static string RazorDiagnosticJsonConverter_UnsupportedRazorDiagnosticType
|
||||
{
|
||||
get => GetString("RazorDiagnosticJsonConverter_UnsupportedRazorDiagnosticType");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserialization of {0} type '{1}' is not supported.
|
||||
/// </summary>
|
||||
internal static string FormatRazorDiagnosticJsonConverter_UnsupportedRazorDiagnosticType(object p0, object p1)
|
||||
=> string.Format(CultureInfo.CurrentCulture, GetString("RazorDiagnosticJsonConverter_UnsupportedRazorDiagnosticType"), p0, p1);
|
||||
|
||||
/// <summary>
|
||||
/// An unexpected exception occurred when invoking '{0}.{1}' on the Razor language service.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -54,8 +54,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
|||
return RazorDiagnostic.Create(error);
|
||||
}
|
||||
|
||||
throw new NotSupportedException(
|
||||
Resources.FormatRazorDiagnosticJsonConverter_UnsupportedRazorDiagnosticType(typeof(RazorDiagnostic).Name, typeName));
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
|
|
|
|||
|
|
@ -117,9 +117,6 @@
|
|||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="RazorDiagnosticJsonConverter_UnsupportedRazorDiagnosticType" xml:space="preserve">
|
||||
<value>Deserialization of {0} type '{1}' is not supported.</value>
|
||||
</data>
|
||||
<data name="UnexpectedException" xml:space="preserve">
|
||||
<value>An unexpected exception occurred when invoking '{0}.{1}' on the Razor language service.</value>
|
||||
</data>
|
||||
|
|
|
|||
Loading…
Reference in New Issue