[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>
|
<RootNamespace>Microsoft.CodeAnalysis.Remote.Razor</RootNamespace>
|
||||||
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
|
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="..\Microsoft.VisualStudio.LanguageServices.Razor\RazorDiagnosticJsonConverter.cs" />
|
||||||
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(RoslynDevVersion)" />
|
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(RoslynDevVersion)" />
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.Remote.Razor.ServiceHub" 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.CodeAnalysis.Razor.Workspaces\Microsoft.CodeAnalysis.Razor.Workspaces.csproj" />
|
||||||
<ProjectReference Include="..\Microsoft.AspNetCore.Razor.Evolution\Microsoft.AspNetCore.Razor.Evolution.csproj" />
|
<ProjectReference Include="..\Microsoft.AspNetCore.Razor.Evolution\Microsoft.AspNetCore.Razor.Evolution.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution;
|
using Microsoft.AspNetCore.Razor.Evolution;
|
||||||
using Microsoft.CodeAnalysis.Razor;
|
using Microsoft.CodeAnalysis.Razor;
|
||||||
|
using Microsoft.VisualStudio.LanguageServices.Razor;
|
||||||
|
|
||||||
namespace Microsoft.CodeAnalysis.Remote.Razor
|
namespace Microsoft.CodeAnalysis.Remote.Razor
|
||||||
{
|
{
|
||||||
|
|
@ -19,11 +20,13 @@ namespace Microsoft.CodeAnalysis.Remote.Razor
|
||||||
public RazorLanguageService(Stream stream, IServiceProvider serviceProvider)
|
public RazorLanguageService(Stream stream, IServiceProvider serviceProvider)
|
||||||
: base(stream, serviceProvider)
|
: base(stream, serviceProvider)
|
||||||
{
|
{
|
||||||
|
Rpc.JsonSerializer.Converters.Add(new RazorDiagnosticJsonConverter());
|
||||||
}
|
}
|
||||||
|
|
||||||
public RazorLanguageService(IServiceProvider serviceProvider, Stream stream)
|
public RazorLanguageService(IServiceProvider serviceProvider, Stream stream)
|
||||||
: base(serviceProvider, 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))
|
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.CodeAnalysis.Razor;
|
||||||
using Microsoft.VisualStudio.Shell;
|
using Microsoft.VisualStudio.Shell;
|
||||||
using Microsoft.VisualStudio.Shell.Interop;
|
using Microsoft.VisualStudio.Shell.Interop;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Microsoft.VisualStudio.LanguageServices.Razor
|
namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
{
|
{
|
||||||
|
|
@ -41,10 +43,12 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
{
|
{
|
||||||
if (session != null)
|
if (session != null)
|
||||||
{
|
{
|
||||||
result = await session.InvokeAsync<TagHelperResolutionResult>(
|
var jsonObject = await session.InvokeAsync<JObject>(
|
||||||
"GetTagHelpersAsync",
|
"GetTagHelpersAsync",
|
||||||
new object[] { project.Id.Id, "Foo", assemblyNameFilters, }).ConfigureAwait(false);
|
new object[] { project.Id.Id, "Foo", assemblyNameFilters, }).ConfigureAwait(false);
|
||||||
|
|
||||||
|
result = GetTagHelperResolutionResult(jsonObject);
|
||||||
|
|
||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
// Per https://github.com/dotnet/roslyn/issues/12770 - there's currently no support for documentation in the OOP host
|
// 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)
|
private IReadOnlyList<TagHelperDescriptor> GetDocumentedTagHelpers(Compilation compilation, IReadOnlyList<TagHelperDescriptor> tagHelpers)
|
||||||
{
|
{
|
||||||
var documentedTagHelpers = new List<TagHelperDescriptor>();
|
var documentedTagHelpers = new List<TagHelperDescriptor>();
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
private static readonly ResourceManager _resourceManager
|
private static readonly ResourceManager _resourceManager
|
||||||
= new ResourceManager("Microsoft.VisualStudio.LanguageServices.Razor.Resources", typeof(Resources).GetTypeInfo().Assembly);
|
= 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>
|
/// <summary>
|
||||||
/// An unexpected exception occurred when invoking '{0}.{1}' on the Razor language service.
|
/// An unexpected exception occurred when invoking '{0}.{1}' on the Razor language service.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
return RazorDiagnostic.Create(error);
|
return RazorDiagnostic.Create(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotSupportedException(
|
return null;
|
||||||
Resources.FormatRazorDiagnosticJsonConverter_UnsupportedRazorDiagnosticType(typeof(RazorDiagnostic).Name, typeName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
|
|
|
||||||
|
|
@ -117,9 +117,6 @@
|
||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</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">
|
<data name="UnexpectedException" xml:space="preserve">
|
||||||
<value>An unexpected exception occurred when invoking '{0}.{1}' on the Razor language service.</value>
|
<value>An unexpected exception occurred when invoking '{0}.{1}' on the Razor language service.</value>
|
||||||
</data>
|
</data>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue