Skip to content

Commit

Permalink
Fix format on paste data readon from request (#11176)
Browse files Browse the repository at this point in the history
It turns out the value comes back as a JsonElement instead of the underlying type 🤷
  • Loading branch information
ryzngard authored Nov 7, 2024
1 parent cdd0fdc commit 78bafeb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
Expand Down Expand Up @@ -56,8 +58,9 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(DocumentRangeFormattingP

if (request.Options.OtherOptions is not null &&
request.Options.OtherOptions.TryGetValue("fromPaste", out var fromPasteObj) &&
fromPasteObj is bool fromPaste)
fromPasteObj is JsonElement fromPasteElement)
{
var fromPaste = fromPasteElement.Deserialize<bool>();
if (fromPaste && !_optionsMonitor.CurrentValue.Formatting.IsOnPasteEnabled())
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.VisualStudio.LanguageServer.Protocol;
Expand Down Expand Up @@ -116,13 +118,15 @@ public async Task Handle_FormattingOnPasteDisabled_ReturnsNull()
var optionsMonitor = GetOptionsMonitor(formatOnPaste: false);
var htmlFormatter = new TestHtmlFormatter();
var endpoint = new DocumentRangeFormattingEndpoint(formattingService, htmlFormatter, optionsMonitor);
var bytes = Encoding.UTF8.GetBytes("\"True\"");
var reader = new Utf8JsonReader(bytes);
var @params = new DocumentRangeFormattingParams()
{
Options = new()
{
OtherOptions = new()
{
{ "fromPaste", true }
{ "fromPaste", JsonElement.ParseValue(ref reader) }
}
}
};
Expand Down

0 comments on commit 78bafeb

Please sign in to comment.