Skip to content

Commit 9bfe55b

Browse files
committed
Allow completion resolve to run in VS Code
1 parent ebd82b3 commit 9bfe55b

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/Delegation/DelegatedCompletionItemResolver.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal class DelegatedCompletionItemResolver(
5454

5555
if (resolvedCompletionItem is not null)
5656
{
57-
resolvedCompletionItem = await PostProcessCompletionItemAsync(resolutionContext, resolvedCompletionItem, cancellationToken).ConfigureAwait(false);
57+
resolvedCompletionItem = await PostProcessCompletionItemAsync(resolutionContext, resolvedCompletionItem, clientCapabilities, cancellationToken).ConfigureAwait(false);
5858
}
5959

6060
return resolvedCompletionItem;
@@ -63,6 +63,7 @@ internal class DelegatedCompletionItemResolver(
6363
private async Task<VSInternalCompletionItem> PostProcessCompletionItemAsync(
6464
DelegatedCompletionResolutionContext context,
6565
VSInternalCompletionItem resolvedCompletionItem,
66+
VSInternalClientCapabilities clientCapabilities,
6667
CancellationToken cancellationToken)
6768
{
6869
if (context.ProjectedKind != RazorLanguageKind.CSharp)
@@ -71,7 +72,7 @@ private async Task<VSInternalCompletionItem> PostProcessCompletionItemAsync(
7172
return resolvedCompletionItem;
7273
}
7374

74-
if (!resolvedCompletionItem.VsResolveTextEditOnCommit)
75+
if (clientCapabilities.SupportsVisualStudioExtensions && !resolvedCompletionItem.VsResolveTextEditOnCommit)
7576
{
7677
// Resolve doesn't typically handle text edit resolution; however, in VS cases it does.
7778
return resolvedCompletionItem;
@@ -89,12 +90,15 @@ private async Task<VSInternalCompletionItem> PostProcessCompletionItemAsync(
8990
return resolvedCompletionItem;
9091
}
9192

92-
var formattingOptions = await _clientConnection
93-
.SendRequestAsync<TextDocumentIdentifierAndVersion, FormattingOptions?>(
94-
LanguageServerConstants.RazorGetFormattingOptionsEndpointName,
95-
documentContext.GetTextDocumentIdentifierAndVersion(),
96-
cancellationToken)
97-
.ConfigureAwait(false);
93+
// In VS we call into the VS layer to get formatting options, as the editor decides based on a multiple sources
94+
var formattingOptions = clientCapabilities.SupportsVisualStudioExtensions
95+
? await _clientConnection
96+
.SendRequestAsync<TextDocumentIdentifierAndVersion, FormattingOptions?>(
97+
LanguageServerConstants.RazorGetFormattingOptionsEndpointName,
98+
documentContext.GetTextDocumentIdentifierAndVersion(),
99+
cancellationToken)
100+
.ConfigureAwait(false)
101+
: _optionsMonitor.CurrentValue.ToFormattingOptions();
98102

99103
if (formattingOptions is null)
100104
{

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hosting/RazorLSPOptions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,13 @@ public override int GetHashCode()
106106
hash.Add(TaskListDescriptors);
107107
return hash;
108108
}
109+
110+
internal FormattingOptions ToFormattingOptions()
111+
{
112+
return new FormattingOptions()
113+
{
114+
InsertSpaces = InsertSpaces,
115+
TabSize = TabSize,
116+
};
117+
}
109118
}

0 commit comments

Comments
 (0)