Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release/dev17.12 to main #10982

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private async Task<WorkspaceEdit> GenerateMethodInCodeBlockAsync(

var formattedChange = await _razorFormattingService.TryGetCSharpCodeActionEditAsync(
documentContext,
result.SelectAsArray(code.Source.Text.GetTextChange),
result.SelectAsArray(code.GetCSharpSourceText().GetTextChange),
formattingOptions,
cancellationToken).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Task<ImmutableArray<TextChange>> GetCSharpOnTypeFormattingChangesAsync(Do
triggerCharacter,
[_csharpOnTypeFormattingPass, .. _validationPasses],
collapseChanges: false,
automaticallyAddUsings: false,
isCodeActionFormattingRequest: false,
cancellationToken: cancellationToken);

public Task<ImmutableArray<TextChange>> GetHtmlOnTypeFormattingChangesAsync(DocumentContext documentContext, ImmutableArray<TextChange> htmlChanges, RazorFormattingOptions options, int hostDocumentIndex, char triggerCharacter, CancellationToken cancellationToken)
Expand All @@ -138,7 +138,7 @@ public Task<ImmutableArray<TextChange>> GetHtmlOnTypeFormattingChangesAsync(Docu
triggerCharacter,
[_htmlOnTypeFormattingPass, .. _validationPasses],
collapseChanges: false,
automaticallyAddUsings: false,
isCodeActionFormattingRequest: false,
cancellationToken: cancellationToken);

public async Task<TextChange?> TryGetSingleCSharpEditAsync(DocumentContext documentContext, TextChange csharpEdit, RazorFormattingOptions options, CancellationToken cancellationToken)
Expand All @@ -151,7 +151,7 @@ public Task<ImmutableArray<TextChange>> GetHtmlOnTypeFormattingChangesAsync(Docu
triggerCharacter: '\0',
[_csharpOnTypeFormattingPass, .. _validationPasses],
collapseChanges: false,
automaticallyAddUsings: false,
isCodeActionFormattingRequest: false,
cancellationToken: cancellationToken).ConfigureAwait(false);
return razorChanges.SingleOrDefault();
}
Expand All @@ -166,7 +166,7 @@ public Task<ImmutableArray<TextChange>> GetHtmlOnTypeFormattingChangesAsync(Docu
triggerCharacter: '\0',
[_csharpOnTypeFormattingPass],
collapseChanges: true,
automaticallyAddUsings: true,
isCodeActionFormattingRequest: true,
cancellationToken: cancellationToken).ConfigureAwait(false);
return razorChanges.SingleOrDefault();
}
Expand All @@ -183,7 +183,7 @@ public Task<ImmutableArray<TextChange>> GetHtmlOnTypeFormattingChangesAsync(Docu
triggerCharacter: '\0',
[_csharpOnTypeFormattingPass],
collapseChanges: true,
automaticallyAddUsings: false,
isCodeActionFormattingRequest: false,
cancellationToken: cancellationToken).ConfigureAwait(false);

razorChanges = UnwrapCSharpSnippets(razorChanges);
Expand Down Expand Up @@ -211,21 +211,27 @@ private async Task<ImmutableArray<TextChange>> ApplyFormattedChangesAsync(
char triggerCharacter,
ImmutableArray<IFormattingPass> formattingPasses,
bool collapseChanges,
bool automaticallyAddUsings,
bool isCodeActionFormattingRequest,
CancellationToken cancellationToken)
{
// If we only received a single edit, let's always return a single edit back.
// Otherwise, merge only if explicitly asked.
collapseChanges |= generatedDocumentChanges.Length == 1;

var documentSnapshot = documentContext.Snapshot;
var codeDocument = await _codeDocumentProvider.GetCodeDocumentAsync(documentSnapshot).ConfigureAwait(false);

// Code actions were computed on the regular document, which with FUSE could be a runtime document. We have to make
// sure for code actions specifically we are formatting that same document, or TextChange spans may not line up
var codeDocument = isCodeActionFormattingRequest
? await documentSnapshot.GetGeneratedOutputAsync(forceDesignTimeGeneratedOutput: false).ConfigureAwait(false)
: await _codeDocumentProvider.GetCodeDocumentAsync(documentSnapshot).ConfigureAwait(false);

var context = FormattingContext.CreateForOnTypeFormatting(
documentSnapshot,
codeDocument,
options,
_codeDocumentProvider,
automaticallyAddUsings,
automaticallyAddUsings: isCodeActionFormattingRequest,
hostDocumentIndex,
triggerCharacter);
var result = generatedDocumentChanges;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.AspNetCore.Razor;
using System.IO;


#if DEBUG
using System.Linq;
#endif
Expand Down Expand Up @@ -268,7 +266,6 @@ public TelemetryScope TrackLspRequest(string lspMethodName, string languageServe
new("eventscope.correlationid", correlationId));
}


/// <summary>
/// Returns values that should be set to (failureParameter1, failureParameter2) when reporting a fault.
/// Those values represent the blamed stackframe module and method name.
Expand Down