Pass options around rather than using the monitor

This commit is contained in:
David Wengier 2024-10-24 14:22:57 +11:00
Родитель b0926dfddd
Коммит 3eacfbd845
14 изменённых файлов: 91 добавлений и 55 удалений

Просмотреть файл

@ -12,6 +12,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
@ -25,11 +26,13 @@ internal sealed class CodeActionResolveEndpoint(
IEnumerable<IRazorCodeActionResolver> razorCodeActionResolvers,
IEnumerable<ICSharpCodeActionResolver> csharpCodeActionResolvers,
IEnumerable<IHtmlCodeActionResolver> htmlCodeActionResolvers,
RazorLSPOptionsMonitor razorLSPOptionsMonitor,
ILoggerFactory loggerFactory) : IRazorRequestHandler<CodeAction, CodeAction>
{
private readonly FrozenDictionary<string, IRazorCodeActionResolver> _razorCodeActionResolvers = CreateResolverMap(razorCodeActionResolvers);
private readonly FrozenDictionary<string, ICSharpCodeActionResolver> _csharpCodeActionResolvers = CreateResolverMap(csharpCodeActionResolvers);
private readonly FrozenDictionary<string, IHtmlCodeActionResolver> _htmlCodeActionResolvers = CreateResolverMap(htmlCodeActionResolvers);
private readonly RazorLSPOptionsMonitor _razorLSPOptionsMonitor = razorLSPOptionsMonitor;
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<CodeActionResolveEndpoint>();
public bool MutatesSolutionState => false;
@ -54,6 +57,13 @@ internal sealed class CodeActionResolveEndpoint(
return request;
}
var options = new RazorFormattingOptions
{
TabSize = _razorLSPOptionsMonitor.CurrentValue.TabSize,
InsertSpaces = _razorLSPOptionsMonitor.CurrentValue.InsertSpaces,
CodeBlockBraceOnNextLine = _razorLSPOptionsMonitor.CurrentValue.CodeBlockBraceOnNextLine
};
request.Data = resolutionParams.Data;
switch (resolutionParams.Language)
@ -63,6 +73,7 @@ internal sealed class CodeActionResolveEndpoint(
documentContext,
request,
resolutionParams,
options,
cancellationToken).ConfigureAwait(false);
case RazorLanguageKind.CSharp:
return await ResolveCSharpCodeActionAsync(
@ -102,6 +113,7 @@ internal sealed class CodeActionResolveEndpoint(
DocumentContext documentContext,
CodeAction codeAction,
RazorCodeActionResolutionParams resolutionParams,
RazorFormattingOptions options,
CancellationToken cancellationToken)
{
if (!_razorCodeActionResolvers.TryGetValue(resolutionParams.Action, out var resolver))
@ -117,7 +129,7 @@ internal sealed class CodeActionResolveEndpoint(
return codeAction;
}
var edit = await resolver.ResolveAsync(documentContext, data, cancellationToken).ConfigureAwait(false);
var edit = await resolver.ResolveAsync(documentContext, data, options, cancellationToken).ConfigureAwait(false);
codeAction.Edit = edit;
return codeAction;
}
@ -181,8 +193,8 @@ internal sealed class CodeActionResolveEndpoint(
internal readonly struct TestAccessor(CodeActionResolveEndpoint instance)
{
public Task<CodeAction> ResolveRazorCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken)
=> instance.ResolveRazorCodeActionAsync(documentContext, codeAction, resolutionParams, cancellationToken);
public Task<CodeAction> ResolveRazorCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, RazorFormattingOptions options, CancellationToken cancellationToken)
=> instance.ResolveRazorCodeActionAsync(documentContext, codeAction, resolutionParams, options, cancellationToken);
public Task<CodeAction> ResolveCSharpCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken)
=> instance.ResolveCSharpCodeActionAsync(documentContext, codeAction, resolutionParams, cancellationToken);

Просмотреть файл

@ -19,7 +19,7 @@ internal sealed class AddUsingsCodeActionResolver : IRazorCodeActionResolver
{
public string Action => LanguageServerConstants.CodeActions.AddUsing;
public async Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken)
public async Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken)
{
var actionParams = data.Deserialize<AddUsingsCodeActionParams>();
if (actionParams is null)

Просмотреть файл

@ -34,12 +34,12 @@ internal static class CodeBlockService
/// <see cref="FormattingUtilities.InitialIndent"/><see cref="FormattingUtilities.Indent"/>}
/// </param>
/// <param name="options">
/// The <see cref="RazorLSPOptions"/> that contains information about indentation.
/// The <see cref="RazorFormattingOptions"/> that contains information about indentation.
/// </param>
/// <returns>
/// A <see cref="TextEdit"/> that will place the formatted generated method within a @code block in the file.
/// </returns>
public static TextEdit[] CreateFormattedTextEdit(RazorCodeDocument code, string templateWithMethodSignature, RazorLSPOptions options)
public static TextEdit[] CreateFormattedTextEdit(RazorCodeDocument code, string templateWithMethodSignature, RazorFormattingOptions options)
{
var csharpCodeBlock = code.GetSyntaxTree().Root.DescendantNodes()
.Select(RazorSyntaxFacts.TryGetCSharpCodeFromCodeBlock)
@ -104,7 +104,7 @@ internal static class CodeBlockService
int openBraceLineIndex,
int closeBraceLineIndex,
SourceLocation insertLocation,
RazorLSPOptions options,
RazorFormattingOptions options,
string method)
{
// The absolute index and character index of the code block's location points to the end of '@code'.

Просмотреть файл

@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Razor.Language.Extensions;
using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.Protocol;
@ -24,7 +25,7 @@ internal sealed class CreateComponentCodeActionResolver(LanguageServerFeatureOpt
public string Action => LanguageServerConstants.CodeActions.CreateComponentFromTag;
public async Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken)
public async Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken)
{
var actionParams = data.Deserialize<CreateComponentCodeActionParams>();
if (actionParams is null)

Просмотреть файл

@ -16,6 +16,7 @@ using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions;
@ -36,7 +37,7 @@ internal sealed class ExtractToCodeBehindCodeActionResolver(
public string Action => LanguageServerConstants.CodeActions.ExtractToCodeBehindAction;
public async Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken)
public async Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken)
{
var actionParams = data.Deserialize<ExtractToCodeBehindCodeActionParams>();
if (actionParams is null)

Просмотреть файл

@ -26,7 +26,7 @@ internal sealed class ExtractToComponentCodeActionResolver(
public string Action => LanguageServerConstants.CodeActions.ExtractToNewComponentAction;
public async Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken)
public async Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken)
{
if (data.ValueKind == JsonValueKind.Undefined)
{

Просмотреть файл

@ -28,12 +28,10 @@ using CSharpSyntaxFactory = Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor;
internal sealed class GenerateMethodCodeActionResolver(
RazorLSPOptionsMonitor razorLSPOptionsMonitor,
IRoslynCodeActionHelpers roslynCodeActionHelpers,
IDocumentMappingService documentMappingService,
IRazorFormattingService razorFormattingService) : IRazorCodeActionResolver
{
private readonly RazorLSPOptionsMonitor _razorLSPOptionsMonitor = razorLSPOptionsMonitor;
private readonly IRoslynCodeActionHelpers _roslynCodeActionHelpers = roslynCodeActionHelpers;
private readonly IDocumentMappingService _documentMappingService = documentMappingService;
private readonly IRazorFormattingService _razorFormattingService = razorFormattingService;
@ -50,7 +48,7 @@ internal sealed class GenerateMethodCodeActionResolver(
public string Action => LanguageServerConstants.CodeActions.GenerateEventHandler;
public async Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken)
public async Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken)
{
var actionParams = data.Deserialize<GenerateMethodCodeActionParams>();
if (actionParams is null)
@ -73,6 +71,7 @@ internal sealed class GenerateMethodCodeActionResolver(
documentContext,
razorNamespace: null,
razorClassName,
options,
cancellationToken).ConfigureAwait(false);
}
@ -86,6 +85,7 @@ internal sealed class GenerateMethodCodeActionResolver(
documentContext,
razorNamespace,
razorClassName,
options,
cancellationToken).ConfigureAwait(false);
}
@ -102,8 +102,8 @@ internal sealed class GenerateMethodCodeActionResolver(
var classLocationLineSpan = @class.GetLocation().GetLineSpan();
var formattedMethod = FormattingUtilities.AddIndentationToMethod(
templateWithMethodSignature,
_razorLSPOptionsMonitor.CurrentValue.TabSize,
_razorLSPOptionsMonitor.CurrentValue.InsertSpaces,
options.TabSize,
options.InsertSpaces,
@class.SpanStart,
classLocationLineSpan.StartLinePosition.Character,
content);
@ -130,10 +130,11 @@ internal sealed class GenerateMethodCodeActionResolver(
DocumentContext documentContext,
string? razorNamespace,
string? razorClassName,
RazorFormattingOptions options,
CancellationToken cancellationToken)
{
var templateWithMethodSignature = await PopulateMethodSignatureAsync(documentContext, actionParams, cancellationToken).ConfigureAwait(false);
var edits = CodeBlockService.CreateFormattedTextEdit(code, templateWithMethodSignature, _razorLSPOptionsMonitor.CurrentValue);
var edits = CodeBlockService.CreateFormattedTextEdit(code, templateWithMethodSignature, options);
// If there are 3 edits, this means that there is no existing @code block, so we have an edit for '@code {', the method stub, and '}'.
// Otherwise, a singular edit means that an @code block does exist and the only edit is adding the method stub.
@ -183,9 +184,9 @@ internal sealed class GenerateMethodCodeActionResolver(
{
var formattingOptions = new RazorFormattingOptions()
{
TabSize = _razorLSPOptionsMonitor.CurrentValue.TabSize,
InsertSpaces = _razorLSPOptionsMonitor.CurrentValue.InsertSpaces,
CodeBlockBraceOnNextLine = _razorLSPOptionsMonitor.CurrentValue.CodeBlockBraceOnNextLine
TabSize = options.TabSize,
InsertSpaces = options.InsertSpaces,
CodeBlockBraceOnNextLine = options.CodeBlockBraceOnNextLine
};
var formattedChange = await _razorFormattingService.TryGetCSharpCodeActionEditAsync(

Просмотреть файл

@ -4,6 +4,7 @@
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.VisualStudio.LanguageServer.Protocol;
@ -11,5 +12,5 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;
internal interface IRazorCodeActionResolver : ICodeActionResolver
{
Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken);
Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken);
}

Просмотреть файл

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc.Razor.Extensions;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Xunit;
using Xunit.Abstractions;
@ -76,7 +77,7 @@ public class AddUsingsCodeActionResolverTest(ITestOutputHelper testOutput) : Lan
});
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.Null(workspaceEdit);
@ -99,7 +100,7 @@ public class AddUsingsCodeActionResolverTest(ITestOutputHelper testOutput) : Lan
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -137,7 +138,7 @@ public class AddUsingsCodeActionResolverTest(ITestOutputHelper testOutput) : Lan
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -182,7 +183,7 @@ public class AddUsingsCodeActionResolverTest(ITestOutputHelper testOutput) : Lan
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -221,7 +222,7 @@ public class AddUsingsCodeActionResolverTest(ITestOutputHelper testOutput) : Lan
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -258,7 +259,7 @@ public class AddUsingsCodeActionResolverTest(ITestOutputHelper testOutput) : Lan
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -296,7 +297,7 @@ public class AddUsingsCodeActionResolverTest(ITestOutputHelper testOutput) : Lan
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -330,7 +331,7 @@ public class AddUsingsCodeActionResolverTest(ITestOutputHelper testOutput) : Lan
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -368,7 +369,7 @@ public class AddUsingsCodeActionResolverTest(ITestOutputHelper testOutput) : Lan
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);

Просмотреть файл

@ -43,12 +43,10 @@ public class CodeActionEndToEndTest(ITestOutputHelper testOutput) : SingleServer
private GenerateMethodCodeActionResolver[] CreateRazorCodeActionResolvers(
IRoslynCodeActionHelpers roslynCodeActionHelpers,
IRazorFormattingService razorFormattingService,
RazorLSPOptionsMonitor? optionsMonitor = null)
IRazorFormattingService razorFormattingService)
=>
[
new GenerateMethodCodeActionResolver(
optionsMonitor ?? TestRazorLSPOptionsMonitor.Create(),
roslynCodeActionHelpers,
new LspDocumentMappingService(FilePathService, new TestDocumentContextFactory(), LoggerFactory),
razorFormattingService)
@ -1044,6 +1042,7 @@ public class CodeActionEndToEndTest(ITestOutputHelper testOutput) : SingleServer
codeActionToRun,
requestContext,
languageServer,
optionsMonitor: null,
CreateRazorCodeActionResolvers(roslynCodeActionHelpers, formattingService));
var razorEdits = new List<TextChange>();
@ -1078,7 +1077,7 @@ public class CodeActionEndToEndTest(ITestOutputHelper testOutput) : SingleServer
string codeAction,
int childActionIndex = 0,
IRazorCodeActionProvider[]? razorCodeActionProviders = null,
Func<IRoslynCodeActionHelpers, IRazorFormattingService, RazorLSPOptionsMonitor?, IRazorCodeActionResolver[]>? codeActionResolversCreator = null,
Func<IRoslynCodeActionHelpers, IRazorFormattingService, IRazorCodeActionResolver[]>? codeActionResolversCreator = null,
RazorLSPOptionsMonitor? optionsMonitor = null,
Diagnostic[]? diagnostics = null)
{
@ -1091,7 +1090,7 @@ public class CodeActionEndToEndTest(ITestOutputHelper testOutput) : SingleServer
string codeAction,
int childActionIndex = 0,
IRazorCodeActionProvider[]? razorCodeActionProviders = null,
Func<IRoslynCodeActionHelpers, IRazorFormattingService, RazorLSPOptionsMonitor?, IRazorCodeActionResolver[]>? codeActionResolversCreator = null,
Func<IRoslynCodeActionHelpers, IRazorFormattingService, IRazorCodeActionResolver[]>? codeActionResolversCreator = null,
RazorLSPOptionsMonitor? optionsMonitor = null,
Diagnostic[]? diagnostics = null)
{
@ -1131,7 +1130,8 @@ public class CodeActionEndToEndTest(ITestOutputHelper testOutput) : SingleServer
codeActionToRun,
requestContext,
languageServer,
codeActionResolversCreator?.Invoke(roslynCodeActionHelpers, formattingService, optionsMonitor) ?? []);
optionsMonitor,
codeActionResolversCreator?.Invoke(roslynCodeActionHelpers, formattingService) ?? []);
var edits = new List<TextChange>();
foreach (var change in changes)
@ -1205,6 +1205,7 @@ public class CodeActionEndToEndTest(ITestOutputHelper testOutput) : SingleServer
VSInternalCodeAction codeActionToRun,
RazorRequestContext requestContext,
IClientConnection clientConnection,
RazorLSPOptionsMonitor? optionsMonitor,
IRazorCodeActionResolver[] razorResolvers)
{
var formattingService = await TestRazorFormattingService.CreateWithFullSupportAsync(LoggerFactory);
@ -1217,7 +1218,8 @@ public class CodeActionEndToEndTest(ITestOutputHelper testOutput) : SingleServer
var htmlResolvers = Array.Empty<IHtmlCodeActionResolver>();
var resolveEndpoint = new CodeActionResolveEndpoint(razorResolvers, csharpResolvers, htmlResolvers, LoggerFactory);
optionsMonitor ??= TestRazorLSPOptionsMonitor.Create();
var resolveEndpoint = new CodeActionResolveEndpoint(razorResolvers, csharpResolvers, htmlResolvers, optionsMonitor, LoggerFactory);
var resolveResult = await resolveEndpoint.HandleRequestAsync(codeActionToRun, requestContext, DisposalToken);

Просмотреть файл

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.AspNetCore.Razor.Threading;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;
@ -27,6 +28,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
razorCodeActionResolvers: [new MockRazorCodeActionResolver("Test")],
csharpCodeActionResolvers: [],
htmlCodeActionResolvers: [],
TestRazorLSPOptionsMonitor.Create(),
LoggerFactory);
var requestParams = new RazorCodeActionResolutionParams()
{
@ -61,6 +63,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
razorCodeActionResolvers: [],
[new MockCSharpCodeActionResolver("Test")],
htmlCodeActionResolvers: [],
TestRazorLSPOptionsMonitor.Create(),
LoggerFactory);
var requestParams = new RazorCodeActionResolutionParams()
{
@ -91,6 +94,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
razorCodeActionResolvers: [new MockRazorCodeActionResolver("TestRazor")],
csharpCodeActionResolvers: [new MockCSharpCodeActionResolver("TestCSharp")],
htmlCodeActionResolvers: [],
TestRazorLSPOptionsMonitor.Create(),
LoggerFactory);
var requestParams = new RazorCodeActionResolutionParams()
{
@ -121,6 +125,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
razorCodeActionResolvers: [],
csharpCodeActionResolvers: [],
htmlCodeActionResolvers: [],
TestRazorLSPOptionsMonitor.Create(),
LoggerFactory);
var requestParams = new RazorCodeActionResolutionParams()
{
@ -160,6 +165,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
razorCodeActionResolvers: [],
csharpCodeActionResolvers: [],
htmlCodeActionResolvers: [],
TestRazorLSPOptionsMonitor.Create(),
LoggerFactory);
var requestParams = new RazorCodeActionResolutionParams()
{
@ -195,6 +201,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
razorCodeActionResolvers: [],
csharpCodeActionResolvers: [new MockCSharpCodeActionResolver("Test")],
htmlCodeActionResolvers: [],
TestRazorLSPOptionsMonitor.Create(),
LoggerFactory);
var requestParams = new RazorCodeActionResolutionParams()
{
@ -234,6 +241,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
razorCodeActionResolvers: [new MockRazorCodeActionResolver("Test")],
csharpCodeActionResolvers: [],
htmlCodeActionResolvers: [],
TestRazorLSPOptionsMonitor.Create(),
LoggerFactory);
var requestParams = new RazorCodeActionResolutionParams()
{
@ -272,6 +280,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
],
csharpCodeActionResolvers: [],
htmlCodeActionResolvers: [],
TestRazorLSPOptionsMonitor.Create(),
LoggerFactory);
var codeAction = new CodeAction();
var request = new RazorCodeActionResolutionParams()
@ -286,7 +295,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
};
// Act
var resolvedCodeAction = await codeActionEndpoint.GetTestAccessor().ResolveRazorCodeActionAsync(documentContext, codeAction, request, DisposalToken);
var resolvedCodeAction = await codeActionEndpoint.GetTestAccessor().ResolveRazorCodeActionAsync(documentContext, codeAction, request, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(resolvedCodeAction.Edit);
@ -304,6 +313,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
],
csharpCodeActionResolvers: [],
htmlCodeActionResolvers: [],
TestRazorLSPOptionsMonitor.Create(),
LoggerFactory);
var codeAction = new CodeAction();
var request = new RazorCodeActionResolutionParams()
@ -318,7 +328,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
};
// Act
var resolvedCodeAction = await codeActionEndpoint.GetTestAccessor().ResolveRazorCodeActionAsync(documentContext, codeAction, request, DisposalToken);
var resolvedCodeAction = await codeActionEndpoint.GetTestAccessor().ResolveRazorCodeActionAsync(documentContext, codeAction, request, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(resolvedCodeAction.Edit);
@ -336,6 +346,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
new MockCSharpNullCodeActionResolver("B"),
],
htmlCodeActionResolvers: [],
TestRazorLSPOptionsMonitor.Create(),
LoggerFactory);
var codeAction = new CodeAction();
var request = new RazorCodeActionResolutionParams()
@ -364,6 +375,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
new MockCSharpCodeActionResolver("B"),
],
htmlCodeActionResolvers: [],
TestRazorLSPOptionsMonitor.Create(),
LoggerFactory);
var codeAction = new CodeAction();
var request = new RazorCodeActionResolutionParams()
@ -395,6 +407,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
new MockCSharpCodeActionResolver("D"),
],
htmlCodeActionResolvers: [],
TestRazorLSPOptionsMonitor.Create(),
LoggerFactory);
var codeAction = new CodeAction();
var request = new RazorCodeActionResolutionParams()
@ -420,6 +433,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
razorCodeActionResolvers: [],
csharpCodeActionResolvers: [new MockCSharpCodeActionResolver("Test")],
htmlCodeActionResolvers: [],
TestRazorLSPOptionsMonitor.Create(),
LoggerFactory);
var requestParams = new RazorCodeActionResolutionParams()
{
@ -452,7 +466,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
Action = action;
}
public Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken)
public Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken)
{
return Task.FromResult<WorkspaceEdit?>(new WorkspaceEdit());
}
@ -467,7 +481,7 @@ public class CodeActionResolutionEndpointTest(ITestOutputHelper testOutput) : La
Action = action;
}
public Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken)
public Task<WorkspaceEdit?> ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken)
{
return SpecializedTasks.Null<WorkspaceEdit>();
}

Просмотреть файл

@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Xunit;
using Xunit.Abstractions;
@ -35,7 +36,7 @@ public class CreateComponentCodeActionResolverTest(ITestOutputHelper testOutput)
});
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.Null(workspaceEdit);
@ -58,7 +59,7 @@ public class CreateComponentCodeActionResolverTest(ITestOutputHelper testOutput)
});
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.Null(workspaceEdit);
@ -81,7 +82,7 @@ public class CreateComponentCodeActionResolverTest(ITestOutputHelper testOutput)
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -112,7 +113,7 @@ public class CreateComponentCodeActionResolverTest(ITestOutputHelper testOutput)
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);

Просмотреть файл

@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Test;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
@ -46,7 +47,7 @@ public class ExtractToCodeBehindCodeActionResolverTest(ITestOutputHelper testOut
var data = JsonSerializer.SerializeToElement(CreateExtractToCodeBehindCodeActionParams(contents, "@code", "Test"));
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.Null(workspaceEdit);
@ -70,7 +71,7 @@ public class ExtractToCodeBehindCodeActionResolverTest(ITestOutputHelper testOut
var data = JsonSerializer.SerializeToElement(CreateExtractToCodeBehindCodeActionParams(contents, "@code", "Test"));
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.Null(workspaceEdit);
@ -98,7 +99,7 @@ public class ExtractToCodeBehindCodeActionResolverTest(ITestOutputHelper testOut
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -163,7 +164,7 @@ public class ExtractToCodeBehindCodeActionResolverTest(ITestOutputHelper testOut
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -236,7 +237,7 @@ public class ExtractToCodeBehindCodeActionResolverTest(ITestOutputHelper testOut
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -319,7 +320,7 @@ public class ExtractToCodeBehindCodeActionResolverTest(ITestOutputHelper testOut
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -404,7 +405,7 @@ public class ExtractToCodeBehindCodeActionResolverTest(ITestOutputHelper testOut
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -477,7 +478,7 @@ public class ExtractToCodeBehindCodeActionResolverTest(ITestOutputHelper testOut
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -542,7 +543,7 @@ public class ExtractToCodeBehindCodeActionResolverTest(ITestOutputHelper testOut
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -609,7 +610,7 @@ public class ExtractToCodeBehindCodeActionResolverTest(ITestOutputHelper testOut
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);
@ -680,7 +681,7 @@ public class ExtractToCodeBehindCodeActionResolverTest(ITestOutputHelper testOut
var data = JsonSerializer.SerializeToElement(actionParams);
// Act
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, DisposalToken);
var workspaceEdit = await resolver.ResolveAsync(documentContext, data, new RazorFormattingOptions(), DisposalToken);
// Assert
Assert.NotNull(workspaceEdit);

Просмотреть файл

@ -303,6 +303,7 @@ public class ExtractToComponentCodeActionResolverTest(ITestOutputHelper testOutp
codeActionToRun,
requestContext,
languageServer,
optionsMonitor: null,
[resolver]
);