Skip to content

Commit 78bafeb

Browse files
author
Andrew Hall
authored
Fix format on paste data readon from request (#11176)
It turns out the value comes back as a JsonElement instead of the underlying type 🤷
1 parent cdd0fdc commit 78bafeb

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentRangeFormattingEndpoint.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT license. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Linq;
7+
using System.Text.Json;
68
using System.Threading;
79
using System.Threading.Tasks;
810
using Microsoft.AspNetCore.Razor.Language;
@@ -56,8 +58,9 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(DocumentRangeFormattingP
5658

5759
if (request.Options.OtherOptions is not null &&
5860
request.Options.OtherOptions.TryGetValue("fromPaste", out var fromPasteObj) &&
59-
fromPasteObj is bool fromPaste)
61+
fromPasteObj is JsonElement fromPasteElement)
6062
{
63+
var fromPaste = fromPasteElement.Deserialize<bool>();
6164
if (fromPaste && !_optionsMonitor.CurrentValue.Formatting.IsOnPasteEnabled())
6265
{
6366
return null;

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/DocumentRangeFormattingEndpointTest.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the MIT license. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Text;
6+
using System.Text.Json;
57
using System.Threading.Tasks;
68
using Microsoft.AspNetCore.Razor.Language;
79
using Microsoft.VisualStudio.LanguageServer.Protocol;
@@ -116,13 +118,15 @@ public async Task Handle_FormattingOnPasteDisabled_ReturnsNull()
116118
var optionsMonitor = GetOptionsMonitor(formatOnPaste: false);
117119
var htmlFormatter = new TestHtmlFormatter();
118120
var endpoint = new DocumentRangeFormattingEndpoint(formattingService, htmlFormatter, optionsMonitor);
121+
var bytes = Encoding.UTF8.GetBytes("\"True\"");
122+
var reader = new Utf8JsonReader(bytes);
119123
var @params = new DocumentRangeFormattingParams()
120124
{
121125
Options = new()
122126
{
123127
OtherOptions = new()
124128
{
125-
{ "fromPaste", true }
129+
{ "fromPaste", JsonElement.ParseValue(ref reader) }
126130
}
127131
}
128132
};

0 commit comments

Comments
 (0)