From d30eb2f58e0e7ddaee643dfb061b098dc5464863 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Fri, 19 Jul 2019 10:09:07 -0700 Subject: [PATCH] Fix serialization of SourceSpan I noticed this while debugging something else in VS. It looks like the service hub is using camelCase, which wasn't covered with a diagnostic in our tests. As a result we would fail to read the data from the OOP host, and fall back to in-process tag helper discovery. \n\nCommit migrated from https://github.com/dotnet/aspnetcore-tooling/commit/63b25dbd2d4e0f18f3a8f48adf8812339b715ee6 --- .../RazorShared/RazorDiagnosticJsonConverter.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Shared/RazorShared/RazorDiagnosticJsonConverter.cs b/src/Shared/RazorShared/RazorDiagnosticJsonConverter.cs index 8f67591eb2..4bfba23eed 100644 --- a/src/Shared/RazorShared/RazorDiagnosticJsonConverter.cs +++ b/src/Shared/RazorShared/RazorDiagnosticJsonConverter.cs @@ -27,15 +27,16 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Serialization } var diagnostic = JObject.Load(reader); + var id = diagnostic[nameof(RazorDiagnostic.Id)].Value(); + var severity = diagnostic[nameof(RazorDiagnostic.Severity)].Value(); + var message = diagnostic[RazorDiagnosticMessageKey].Value(); + var span = diagnostic[nameof(RazorDiagnostic.Span)].Value(); + var filePath = span[nameof(SourceSpan.FilePath)].Value(); var absoluteIndex = span[nameof(SourceSpan.AbsoluteIndex)].Value(); var lineIndex = span[nameof(SourceSpan.LineIndex)].Value(); var characterIndex = span[nameof(SourceSpan.CharacterIndex)].Value(); var length = span[nameof(SourceSpan.Length)].Value(); - var filePath = span[nameof(SourceSpan.FilePath)].Value(); - var message = diagnostic[RazorDiagnosticMessageKey].Value(); - var id = diagnostic[nameof(RazorDiagnostic.Id)].Value(); - var severity = diagnostic[nameof(RazorDiagnostic.Severity)].Value(); var descriptor = new RazorDiagnosticDescriptor(id, () => message, (RazorDiagnosticSeverity)severity); var sourceSpan = new SourceSpan(filePath, absoluteIndex, lineIndex, characterIndex, length); @@ -53,7 +54,13 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Serialization WriteProperty(writer, RazorDiagnosticMessageKey, diagnostic.GetMessage(CultureInfo.CurrentCulture)); writer.WritePropertyName(nameof(RazorDiagnostic.Span)); - serializer.Serialize(writer, diagnostic.Span); + writer.WriteStartObject(); + WriteProperty(writer, nameof(SourceSpan.FilePath), diagnostic.Span.FilePath); + WriteProperty(writer, nameof(SourceSpan.AbsoluteIndex), diagnostic.Span.AbsoluteIndex); + WriteProperty(writer, nameof(SourceSpan.LineIndex), diagnostic.Span.LineIndex); + WriteProperty(writer, nameof(SourceSpan.CharacterIndex), diagnostic.Span.CharacterIndex); + WriteProperty(writer, nameof(SourceSpan.Length), diagnostic.Span.Length); + writer.WriteEndObject(); writer.WriteEndObject(); }