Skip to content

Commit 7ce1f4b

Browse files
authored
Fix C# completion resolve in VS (#11905)
Fixes the "Assert" that Phil was seeing
2 parents c106889 + 414c013 commit 7ce1f4b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Completion/RemoteCompletionService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Diagnostics;
77
using System.Linq;
8+
using System.Text.Json;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using Microsoft.AspNetCore.Razor;
@@ -312,6 +313,13 @@ private async ValueTask<VSInternalCompletionItem> ResolveCSharpCompletionItemAsy
312313
{
313314
request.Data = DelegatedCompletionHelper.GetOriginalCompletionItemData(request, containingCompletionList, resolutionContext.OriginalCompletionListData);
314315

316+
// Roslyn expects data to be JsonElement because we're calling into their LSP handler, but we cache their data as its underlying object, so lets
317+
// make sure to serialize if we need to.
318+
if (request.Data is not JsonElement)
319+
{
320+
request.Data = JsonSerializer.SerializeToElement(request.Data, JsonHelpers.JsonSerializerOptions);
321+
}
322+
315323
var documentSnapshot = context.Snapshot;
316324
var generatedDocument = await documentSnapshot.GetGeneratedDocumentAsync(cancellationToken).ConfigureAwait(false);
317325

0 commit comments

Comments
 (0)