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

Move culture info check #11057

Merged
merged 3 commits into from
Oct 22, 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 @@ -19,12 +19,10 @@ public RazorRequestExecutionQueue(AbstractLanguageServer<RazorRequestContext> la
_capabilitiesManager = languageServer.GetLspServices().GetRequiredService<CapabilitiesManager>();
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD003:Avoid awaiting foreign Tasks", Justification = "<Pending>")]
public override Task WrapStartRequestTaskAsync(Task nonMutatingRequestTask, bool rethrowExceptions)
protected internal override void BeforeRequest<TRequest>(TRequest request)
{
// Update the locale for this request to the desired LSP locale.
CultureInfo.CurrentUICulture = GetCultureForRequest();

return nonMutatingRequestTask;
}

private CultureInfo GetCultureForRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.LanguageServer.Protocol;
Expand Down Expand Up @@ -44,11 +45,16 @@ public async Task LocaleIsSetCorrectly()
await queue.ExecuteAsync(initializeParams, Methods.InitializeName, server.GetLspServices(), DisposalToken);

// We have to send one more request, because culture is set before any request starts, but the first initialize request has to
// be started in order to set the culture.
// The request isn't actually valid, so we wrap it in a try catch, but we don't care for this test
// be started in order to set the culture. The request must be valid because the culture is set in `BeforeRequest` but it doesn't
// have to succeed.
try
{
await queue.ExecuteAsync(JsonSerializer.SerializeToElement(new object()), VSInternalMethods.DocumentPullDiagnosticName, server.GetLspServices(), DisposalToken);
var namedPipeParams = new RazorNamedPipeConnectParams()
{
PipeName = ""
};

await queue.ExecuteAsync(JsonSerializer.SerializeToElement(namedPipeParams), CustomMessageNames.RazorNamedPipeConnectEndpointName, server.GetLspServices(), DisposalToken);
}
catch { }

Expand Down