Skip to content

Commit aa3cf97

Browse files
authored
Fixing override completion in VSCode when LSP is enabled (#12039)
* Fixing override completion in VSCode when LSP is enbaled Existing code worked for the most part. The main issue was that parameters for the complex edit command come in as JsonElements in this case and need to be deserialized. * CR suggestion - simplify logic
1 parent 5a5fe14 commit aa3cf97

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/Delegation/DelegatedCompletionHelper.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Immutable;
77
using System.Diagnostics;
88
using System.Linq;
9+
using System.Text.Json;
910
using System.Threading;
1011
using System.Threading.Tasks;
1112
using Microsoft.AspNetCore.Razor.Language;
@@ -317,6 +318,14 @@ public static async Task<VSInternalCompletionItem> FormatCSharpCompletionItemAsy
317318
// rather than the one LSP knows about.
318319
if (resolvedCompletionItem.Command is { CommandIdentifier: Constants.CompleteComplexEditCommand, Arguments: var args })
319320
{
321+
// In LSP case, command parameters will be JsonElement objects and will need to be deserialized first
322+
if (args is [JsonElement textDocumentIdentifierData, JsonElement complexEditData, _, _])
323+
{
324+
args[0] = textDocumentIdentifierData.Deserialize<TextDocumentIdentifier>() ?? args[0];
325+
args[1] = complexEditData.Deserialize<TextEdit>() ?? args[1];
326+
}
327+
328+
// In cohosting case, command parameters will be of the correct types (or deserialized by now in LSP case)
320329
if (args is [TextDocumentIdentifier, TextEdit complexEdit, _, int nextCursorPosition])
321330
{
322331
var formattedTextEdit = await FormatTextEditsAsync([complexEdit], documentContext, options, formattingService, cancellationToken).ConfigureAwait(false);

0 commit comments

Comments
 (0)