From 5b5539f60c9860c1f0a43a6aa4f38b2d4e26f73f Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 24 Oct 2024 08:29:37 +1100 Subject: [PATCH 01/15] Simplify code action context --- .../CSharp/DefaultCSharpCodeActionProvider.cs | 2 +- .../TypeAccessibilityCodeActionProvider.cs | 2 +- .../CodeActions/CodeActionEndpoint.cs | 6 +-- ...omponentAccessibilityCodeActionProvider.cs | 4 +- .../ExtractToCodeBehindCodeActionProvider.cs | 4 +- .../ExtractToComponentCodeActionProvider.cs | 16 ++++---- .../Razor/GenerateMethodCodeActionProvider.cs | 2 +- .../CodeActions/RazorCodeActionContext.cs | 4 +- .../DefaultCSharpCodeActionProviderTest.cs | 30 +++++--------- ...TypeAccessibilityCodeActionProviderTest.cs | 27 +++++-------- .../Html/DefaultHtmlCodeActionProviderTest.cs | 12 +++--- ...nentAccessibilityCodeActionProviderTest.cs | 39 +++++++----------- ...tractToCodeBehindCodeActionProviderTest.cs | 40 +++++++------------ ...xtractToComponentCodeActionProviderTest.cs | 4 +- 14 files changed, 77 insertions(+), 115 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs index 92fc6052c54..9c4c239a4cf 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs @@ -67,7 +67,7 @@ public Task> ProvideAsync( } var tree = context.CodeDocument.GetSyntaxTree(); - var node = tree.Root.FindInnermostNode(context.StartLocation.AbsoluteIndex); + var node = tree.Root.FindInnermostNode(context.StartAbsoluteIndex); var isInImplicitExpression = node?.AncestorsAndSelf().Any(n => n is CSharpImplicitExpressionSyntax) ?? false; var allowList = isInImplicitExpression diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs index 1036c28168d..3130c5e749a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs @@ -215,7 +215,7 @@ static bool TryGetOwner(RazorCodeActionContext context, [NotNullWhen(true)] out return false; } - owner = syntaxTree.Root.FindInnermostNode(context.StartLocation.AbsoluteIndex); + owner = syntaxTree.Root.FindInnermostNode(context.StartAbsoluteIndex); if (owner is null) { Debug.Fail("Owner should never be null."); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs index 05de6152656..1f0028f0d4e 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs @@ -161,12 +161,12 @@ public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, V request.Range = vsCodeActionContext.SelectionRange; } - if (!sourceText.TryGetSourceLocation(request.Range.Start, out var startLocation)) + if (!sourceText.TryGetAbsoluteIndex(request.Range.Start, out var startLocation)) { return null; } - if (!sourceText.TryGetSourceLocation(request.Range.End, out var endLocation)) + if (!sourceText.TryGetAbsoluteIndex(request.Range.End, out var endLocation)) { endLocation = startLocation; } @@ -186,7 +186,7 @@ public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, V private async Task> GetDelegatedCodeActionsAsync(DocumentContext documentContext, RazorCodeActionContext context, Guid correlationId, CancellationToken cancellationToken) { - var languageKind = context.CodeDocument.GetLanguageKind(context.StartLocation.AbsoluteIndex, rightAssociative: false); + var languageKind = context.CodeDocument.GetLanguageKind(context.StartAbsoluteIndex, rightAssociative: false); // No point delegating if we're in a Razor context if (languageKind == RazorLanguageKind.Razor) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs index d7da7dff102..bbeacbcacf2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs @@ -28,7 +28,7 @@ internal sealed class ComponentAccessibilityCodeActionProvider : IRazorCodeActio public async Task> ProvideAsync(RazorCodeActionContext context, CancellationToken cancellationToken) { // Locate cursor - var node = context.CodeDocument.GetSyntaxTree().Root.FindInnermostNode(context.StartLocation.AbsoluteIndex); + var node = context.CodeDocument.GetSyntaxTree().Root.FindInnermostNode(context.StartAbsoluteIndex); if (node is null) { return []; @@ -45,7 +45,7 @@ public async Task> ProvideAsync(RazorC return []; } - if (context.StartLocation.AbsoluteIndex < startTag.SpanStart) + if (context.StartAbsoluteIndex < startTag.SpanStart) { // Cursor is before the start tag, so we shouldn't show a light bulb. This can happen // in cases where the cursor is in whitespace at the beginning of the document diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs index bc1d56dc15a..e2bb9d285e3 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs @@ -43,7 +43,7 @@ public Task> ProvideAsync(RazorCodeAct return SpecializedTasks.EmptyImmutableArray(); } - var owner = syntaxTree.Root.FindInnermostNode(context.StartLocation.AbsoluteIndex); + var owner = syntaxTree.Root.FindInnermostNode(context.StartAbsoluteIndex); if (owner is null) { _logger.LogWarning($"Owner should never be null."); @@ -85,7 +85,7 @@ public Task> ProvideAsync(RazorCodeAct } // Do not provide code action if the cursor is inside the code block - if (context.StartLocation.AbsoluteIndex > csharpCodeBlockNode.SpanStart) + if (context.StartAbsoluteIndex > csharpCodeBlockNode.SpanStart) { return SpecializedTasks.EmptyImmutableArray(); } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs index e4520945cc0..9257cefdbf0 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs @@ -77,7 +77,7 @@ public Task> ProvideAsync(RazorCodeAct private static (SyntaxNode? Start, SyntaxNode? End) GetStartAndEndElements(RazorCodeActionContext context, RazorSyntaxTree syntaxTree) { - var owner = syntaxTree.Root.FindInnermostNode(context.StartLocation.AbsoluteIndex, includeWhitespace: true); + var owner = syntaxTree.Root.FindInnermostNode(context.StartAbsoluteIndex, includeWhitespace: true); if (owner is null) { return (null, null); @@ -85,34 +85,34 @@ private static (SyntaxNode? Start, SyntaxNode? End) GetStartAndEndElements(Razor var startElementNode = owner.FirstAncestorOrSelf(IsBlockNode); - if (startElementNode is null || LocationInvalid(context.StartLocation, startElementNode)) + if (startElementNode is null || LocationInvalid(context.StartAbsoluteIndex, startElementNode)) { return (null, null); } - var endElementNode = context.StartLocation == context.EndLocation + var endElementNode = context.StartAbsoluteIndex == context.EndAbsoluteIndex ? startElementNode : GetEndElementNode(context, syntaxTree); return (startElementNode, endElementNode); - static bool LocationInvalid(SourceLocation location, SyntaxNode node) + static bool LocationInvalid(int location, SyntaxNode node) { // Make sure to test for cases where selection // is inside of a markup tag such as

hello$ there

if (node is MarkupElementSyntax markupElement) { - return location.AbsoluteIndex > markupElement.StartTag.Span.End && - location.AbsoluteIndex < markupElement.EndTag.SpanStart; + return location > markupElement.StartTag.Span.End && + location < markupElement.EndTag.SpanStart; } - return !node.Span.Contains(location.AbsoluteIndex); + return !node.Span.Contains(location); } } private static SyntaxNode? GetEndElementNode(RazorCodeActionContext context, RazorSyntaxTree syntaxTree) { - var endOwner = syntaxTree.Root.FindInnermostNode(context.EndLocation.AbsoluteIndex, includeWhitespace: true); + var endOwner = syntaxTree.Root.FindInnermostNode(context.EndAbsoluteIndex, includeWhitespace: true); if (endOwner is null) { return null; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionProvider.cs index f6fb35ddf67..7773a9ac27a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionProvider.cs @@ -30,7 +30,7 @@ public Task> ProvideAsync(RazorCodeAct } var syntaxTree = context.CodeDocument.GetSyntaxTree(); - var owner = syntaxTree.Root.FindToken(context.StartLocation.AbsoluteIndex).Parent.AssumeNotNull(); + var owner = syntaxTree.Root.FindToken(context.StartAbsoluteIndex).Parent.AssumeNotNull(); if (IsGenerateEventHandlerValid(owner, out var methodName, out var eventName)) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RazorCodeActionContext.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RazorCodeActionContext.cs index 26160e318b1..2040629f1c8 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RazorCodeActionContext.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RazorCodeActionContext.cs @@ -13,8 +13,8 @@ internal sealed record class RazorCodeActionContext( VSCodeActionParams Request, IDocumentSnapshot DocumentSnapshot, RazorCodeDocument CodeDocument, - SourceLocation StartLocation, - SourceLocation EndLocation, + int StartAbsoluteIndex, + int EndAbsoluteIndex, SourceText SourceText, bool SupportsFileCreation, bool SupportsCodeActionResolve); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs index ca735484e39..eb79d65ae4f 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs @@ -56,8 +56,7 @@ public async Task ProvideAsync_ValidCodeActions_ReturnsProvidedCodeAction() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(8, 4)); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(8, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); @@ -87,8 +86,7 @@ public async Task ProvideAsync_SupportsCodeActionResolveFalse_ValidCodeActions_R Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(8, 4), supportsCodeActionResolve: false); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(8, 4), supportsCodeActionResolve: false); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); @@ -115,8 +113,7 @@ public async Task ProvideAsync_FunctionsBlock_SingleLine_ValidCodeActions_Return Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(13, 4)); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(13, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); @@ -148,8 +145,7 @@ public async Task ProvideAsync_FunctionsBlock_OpenBraceSameLine_ValidCodeActions Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(13, 4)); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(13, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); @@ -182,8 +178,7 @@ public async Task ProvideAsync_FunctionsBlock_OpenBraceNextLine_ValidCodeActions Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(13, 4)); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(13, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); @@ -213,8 +208,7 @@ public async Task ProvideAsync_InvalidCodeActions_ReturnsNoCodeActions() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(8, 4)); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(8, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); @@ -250,8 +244,7 @@ public async Task ProvideAsync_InvalidCodeActions_ShowAllFeatureFlagOn_ReturnsCo Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(8, 4)); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(8, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); var options = new ConfigurableLanguageServerFeatureOptions(new[] { $"--{nameof(ConfigurableLanguageServerFeatureOptions.ShowAllCSharpCodeActions)}" }); @@ -296,8 +289,7 @@ public async Task ProvideAsync_ImplicitExpression_ReturnsProvidedCodeAction() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(8, 4)); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(8, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); @@ -314,7 +306,7 @@ public async Task ProvideAsync_ImplicitExpression_ReturnsProvidedCodeAction() private static RazorCodeActionContext CreateRazorCodeActionContext( VSCodeActionParams request, - SourceLocation location, + int absoluteIndex, string filePath, string text, SourceSpan componentSourceSpan, @@ -347,8 +339,8 @@ private static RazorCodeActionContext CreateRazorCodeActionContext( request, documentSnapshotMock.Object, codeDocument, - location, - location, + absoluteIndex, + absoluteIndex, codeDocument.Source.Text, supportsFileCreation, supportsCodeActionResolve); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/TypeAccessibilityCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/TypeAccessibilityCodeActionProviderTest.cs index 13d28709f66..e438ceecafd 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/TypeAccessibilityCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/TypeAccessibilityCodeActionProviderTest.cs @@ -41,8 +41,7 @@ public async Task Handle_MissingDiagnostics_ReturnsEmpty() }, }; - var location = new SourceLocation(0, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(0, 0)); + var context = CreateRazorCodeActionContext(request, absoluteIndex: 0, documentPath, contents, new SourceSpan(0, 0)); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new TypeAccessibilityCodeActionProvider(); @@ -96,8 +95,7 @@ public async Task Handle_InvalidDiagnostics_VSCode_ReturnsEmpty() } }; - var location = new SourceLocation(0, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(0, 0), supportsCodeActionResolve: false); + var context = CreateRazorCodeActionContext(request, absoluteIndex: 0, documentPath, contents, new SourceSpan(0, 0), supportsCodeActionResolve: false); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new TypeAccessibilityCodeActionProvider(); @@ -138,8 +136,7 @@ public async Task Handle_EmptyCodeActions_ReturnsEmpty() } }; - var location = new SourceLocation(0, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(0, 0)); + var context = CreateRazorCodeActionContext(request, absoluteIndex: 0, documentPath, contents, new SourceSpan(0, 0)); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new TypeAccessibilityCodeActionProvider(); @@ -189,8 +186,7 @@ public async Task Handle_ValidDiagnostic_ValidCodeAction_VSCode_ReturnsCodeActio } }; - var location = new SourceLocation(0, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(8, 4), supportsCodeActionResolve: false); + var context = CreateRazorCodeActionContext(request, absoluteIndex: 0, documentPath, contents, new SourceSpan(8, 4), supportsCodeActionResolve: false); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new TypeAccessibilityCodeActionProvider(); @@ -248,8 +244,7 @@ public async Task Handle_CodeActionInSingleLineDirective_VS_ReturnsOnlyUsingCode } }; - var location = new SourceLocation(8, 0, 8); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(8, 4), supportsCodeActionResolve: true); + var context = CreateRazorCodeActionContext(request, absoluteIndex: 8, documentPath, contents, new SourceSpan(8, 4), supportsCodeActionResolve: true); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new TypeAccessibilityCodeActionProvider(); @@ -300,8 +295,7 @@ public async Task Handle_ValidCodeAction_VS_ReturnsCodeActions() } }; - var location = new SourceLocation(0, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(8, 4), supportsCodeActionResolve: true); + var context = CreateRazorCodeActionContext(request, absoluteIndex: 0, documentPath, contents, new SourceSpan(8, 4), supportsCodeActionResolve: true); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new TypeAccessibilityCodeActionProvider(); @@ -375,8 +369,7 @@ public async Task Handle_ValidDiagnostic_MultipleValidCodeActions_VSCode_Returns } }; - var location = new SourceLocation(0, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(8, 4), supportsCodeActionResolve: false); + var context = CreateRazorCodeActionContext(request, absoluteIndex: 0, documentPath, contents, new SourceSpan(8, 4), supportsCodeActionResolve: false); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new TypeAccessibilityCodeActionProvider(); @@ -434,7 +427,7 @@ public async Task Handle_ValidDiagnostic_MultipleValidCodeActions_VSCode_Returns private static RazorCodeActionContext CreateRazorCodeActionContext( VSCodeActionParams request, - SourceLocation location, + int absoluteIndex, string filePath, string text, SourceSpan componentSourceSpan, @@ -477,8 +470,8 @@ private static RazorCodeActionContext CreateRazorCodeActionContext( request, documentSnapshotMock.Object, codeDocument, - location, - location, + absoluteIndex, + absoluteIndex, codeDocument.Source.Text, supportsFileCreation, supportsCodeActionResolve); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs index a3e529f131e..3e6e5c929ce 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs @@ -39,8 +39,7 @@ public async Task ProvideAsync_WrapsResolvableCodeActions() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents); context.CodeDocument.SetFileKind(FileKinds.Legacy); var documentMappingService = StrictMock.Of(); @@ -72,8 +71,7 @@ public async Task ProvideAsync_RemapsAndFixesEdits() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents); context.CodeDocument.SetFileKind(FileKinds.Legacy); var remappedEdit = new WorkspaceEdit @@ -140,7 +138,7 @@ public async Task ProvideAsync_RemapsAndFixesEdits() private static RazorCodeActionContext CreateRazorCodeActionContext( VSCodeActionParams request, - SourceLocation location, + int absoluteIndex, string filePath, string text, bool supportsFileCreation = true, @@ -166,8 +164,8 @@ private static RazorCodeActionContext CreateRazorCodeActionContext( request, documentSnapshotMock.Object, codeDocument, - location, - location, + absoluteIndex, + absoluteIndex, codeDocument.Source.Text, supportsFileCreation, supportsCodeActionResolve); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs index 35e31f38611..404bc2cb4d8 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs @@ -39,8 +39,7 @@ public async Task Handle_NoTagName_DoesNotProvideLightBulb() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(0, 1)); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(0, 1)); var provider = new ComponentAccessibilityCodeActionProvider(); @@ -68,8 +67,7 @@ public async Task Handle_InvalidSyntaxTree_NoStartNode() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(0, 0)); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(0, 0)); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new ComponentAccessibilityCodeActionProvider(); @@ -98,8 +96,7 @@ public async Task Handle_CursorOutsideComponent() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9)); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9)); var provider = new ComponentAccessibilityCodeActionProvider(); @@ -127,8 +124,7 @@ public async Task Handle_ExistingComponent_SupportsFileCreationTrue_ReturnsResul Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9), supportsFileCreation: true); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9), supportsFileCreation: true); var provider = new ComponentAccessibilityCodeActionProvider(); @@ -175,8 +171,7 @@ public async Task Handle_ExistingComponent_CaseIncorrect_ReturnsResults() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("CompOnent", StringComparison.Ordinal), 9), supportsFileCreation: true); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(contents.IndexOf("CompOnent", StringComparison.Ordinal), 9), supportsFileCreation: true); var provider = new ComponentAccessibilityCodeActionProvider(); @@ -225,8 +220,7 @@ @using Fully.Qualified Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("CompOnent", StringComparison.Ordinal), 9), supportsFileCreation: true); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(contents.IndexOf("CompOnent", StringComparison.Ordinal), 9), supportsFileCreation: true); var provider = new ComponentAccessibilityCodeActionProvider(); @@ -267,8 +261,7 @@ public async Task Handle_ExistingGenericComponent_SupportsFileCreationTrue_Retur Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("GenericComponent", StringComparison.Ordinal), "GenericComponent".Length), supportsFileCreation: true); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(contents.IndexOf("GenericComponent", StringComparison.Ordinal), "GenericComponent".Length), supportsFileCreation: true); var provider = new ComponentAccessibilityCodeActionProvider(); @@ -315,8 +308,7 @@ public async Task Handle_NewComponent_SupportsFileCreationTrue_ReturnsResult() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9), supportsFileCreation: true); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9), supportsFileCreation: true); var provider = new ComponentAccessibilityCodeActionProvider(); @@ -346,8 +338,7 @@ public async Task Handle_NewComponent_CaretInAttribute_ReturnsResult() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9), supportsFileCreation: true); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9), supportsFileCreation: true); var provider = new ComponentAccessibilityCodeActionProvider(); @@ -377,8 +368,7 @@ public async Task Handle_NewComponent_SupportsFileCreationFalse_ReturnsEmpty() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9), supportsFileCreation: false); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9), supportsFileCreation: false); var provider = new ComponentAccessibilityCodeActionProvider(); @@ -406,8 +396,7 @@ public async Task Handle_ExistingComponent_SupportsFileCreationFalse_ReturnsResu Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9), supportsFileCreation: false); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9), supportsFileCreation: false); var provider = new ComponentAccessibilityCodeActionProvider(); @@ -431,7 +420,7 @@ public async Task Handle_ExistingComponent_SupportsFileCreationFalse_ReturnsResu }); } - private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionParams request, SourceLocation location, string filePath, string text, SourceSpan componentSourceSpan, bool supportsFileCreation = true) + private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionParams request, int absoluteIndex, string filePath, string text, SourceSpan componentSourceSpan, bool supportsFileCreation = true) { var shortComponent = TagHelperDescriptorBuilder.Create(ComponentMetadata.Component.TagHelperKind, "Fully.Qualified.Component", "TestAssembly"); shortComponent.CaseSensitive = true; @@ -478,8 +467,8 @@ private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionP request, documentSnapshotMock.Object, codeDocument, - location, - location, + absoluteIndex, + absoluteIndex, codeDocument.Source.Text, supportsFileCreation, SupportsCodeActionResolve: true); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionProviderTest.cs index c47b2204ea4..2ab70100820 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionProviderTest.cs @@ -44,8 +44,7 @@ public async Task Handle_InvalidFileKind() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new ExtractToCodeBehindCodeActionProvider(LoggerFactory); @@ -75,8 +74,7 @@ public async Task Handle_OutsideCodeDirective() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents); var provider = new ExtractToCodeBehindCodeActionProvider(LoggerFactory); @@ -105,8 +103,7 @@ public async Task Handle_InCodeDirectiveBlock_ReturnsNull() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents); var provider = new ExtractToCodeBehindCodeActionProvider(LoggerFactory); @@ -135,8 +132,7 @@ public async Task Handle_InCodeDirectiveMalformed_ReturnsNull() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents); var provider = new ExtractToCodeBehindCodeActionProvider(LoggerFactory); @@ -170,8 +166,7 @@ void Test() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents); var provider = new ExtractToCodeBehindCodeActionProvider(LoggerFactory); @@ -211,8 +206,7 @@ public async Task Handle_InCodeDirective_SupportsFileCreationTrue_ReturnsResult( Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, supportsFileCreation: true); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, supportsFileCreation: true); var provider = new ExtractToCodeBehindCodeActionProvider(LoggerFactory); @@ -254,8 +248,7 @@ public async Task Handle_AtEndOfCodeDirectiveWithNoSpace_ReturnsResult() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, supportsFileCreation: true); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, supportsFileCreation: true); var provider = new ExtractToCodeBehindCodeActionProvider(LoggerFactory); @@ -291,8 +284,7 @@ public async Task Handle_InCodeDirective_SupportsFileCreationFalse_ReturnsNull() Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, supportsFileCreation: false); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, supportsFileCreation: false); var provider = new ExtractToCodeBehindCodeActionProvider(LoggerFactory); @@ -327,8 +319,7 @@ public async Task Handle_InFunctionsDirective_SupportsFileCreationTrue_ReturnsRe Context = new VSInternalCodeActionContext() }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents); var provider = new ExtractToCodeBehindCodeActionProvider(LoggerFactory); @@ -364,8 +355,7 @@ public async Task Handle_NullRelativePath_ReturnsNull() Context = null! }; - var location = new SourceLocation(cursorPosition, -1, -1); - var context = CreateRazorCodeActionContext(request, location, documentPath, contents, relativePath: null); + var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, relativePath: null); var provider = new ExtractToCodeBehindCodeActionProvider(LoggerFactory); @@ -376,10 +366,10 @@ public async Task Handle_NullRelativePath_ReturnsNull() Assert.Empty(commandOrCodeActionContainer); } - private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionParams request, SourceLocation location, string filePath, string text, bool supportsFileCreation = true) - => CreateRazorCodeActionContext(request, location, filePath, text, relativePath: filePath, supportsFileCreation: supportsFileCreation); + private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionParams request, int absoluteIndex, string filePath, string text, bool supportsFileCreation = true) + => CreateRazorCodeActionContext(request, absoluteIndex, filePath, text, relativePath: filePath, supportsFileCreation: supportsFileCreation); - private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionParams request, SourceLocation location, string filePath, string text, string? relativePath, bool supportsFileCreation = true) + private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionParams request, int aboluteIndex, string filePath, string text, string? relativePath, bool supportsFileCreation = true) { var sourceDocument = RazorSourceDocument.Create(text, RazorSourceDocumentProperties.Create(filePath, relativePath)); var options = RazorParserOptions.Create(o => @@ -409,8 +399,8 @@ private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionP request, documentSnapshotMock.Object, codeDocument, - location, - location, + aboluteIndex, + aboluteIndex, codeDocument.Source.Text, supportsFileCreation, SupportsCodeActionResolve: true); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionProviderTest.cs index f48347a9ca8..0fed08a4409 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionProviderTest.cs @@ -439,8 +439,8 @@ private static RazorCodeActionContext CreateRazorCodeActionContext( request, documentSnapshot.Object, codeDocument, - new SourceLocation(selectionSpan.Start, -1, -1), - new SourceLocation(selectionSpan.End, -1, -1), + selectionSpan.Start, + selectionSpan.End, sourceText, supportsFileCreation, SupportsCodeActionResolve: true); From 1e1a0fcbf4b0e31b37be1ad7f41f545404966a9a Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 24 Oct 2024 09:19:32 +1100 Subject: [PATCH 02/15] Remove unnecessary parameter --- .../CodeActions/CodeActionEndpoint.cs | 10 +++++----- .../CodeActions/CodeActionEndpointTest.cs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs index 1f0028f0d4e..82f9675e9de 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs @@ -79,7 +79,7 @@ internal sealed class CodeActionEndpoint( cancellationToken.ThrowIfCancellationRequested(); - var delegatedCodeActions = await GetDelegatedCodeActionsAsync(documentContext, razorCodeActionContext, correlationId, cancellationToken).ConfigureAwait(false); + var delegatedCodeActions = await GetDelegatedCodeActionsAsync(razorCodeActionContext, correlationId, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); @@ -184,7 +184,7 @@ public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, V return context; } - private async Task> GetDelegatedCodeActionsAsync(DocumentContext documentContext, RazorCodeActionContext context, Guid correlationId, CancellationToken cancellationToken) + private async Task> GetDelegatedCodeActionsAsync(RazorCodeActionContext context, Guid correlationId, CancellationToken cancellationToken) { var languageKind = context.CodeDocument.GetLanguageKind(context.StartAbsoluteIndex, rightAssociative: false); @@ -194,7 +194,7 @@ private async Task> GetDelegatedCodeAc return []; } - var codeActions = await GetCodeActionsFromLanguageServerAsync(languageKind, documentContext, context, correlationId, cancellationToken).ConfigureAwait(false); + var codeActions = await GetCodeActionsFromLanguageServerAsync(languageKind, context, correlationId, cancellationToken).ConfigureAwait(false); if (codeActions is not [_, ..]) { return []; @@ -265,7 +265,7 @@ private static async Task> FilterCodeA } // Internal for testing - internal async Task GetCodeActionsFromLanguageServerAsync(RazorLanguageKind languageKind, DocumentContext documentContext, RazorCodeActionContext context, Guid correlationId, CancellationToken cancellationToken) + internal async Task GetCodeActionsFromLanguageServerAsync(RazorLanguageKind languageKind, RazorCodeActionContext context, Guid correlationId, CancellationToken cancellationToken) { if (languageKind == RazorLanguageKind.CSharp) { @@ -291,7 +291,7 @@ internal async Task GetCodeActionsFromLanguageServe var delegatedParams = new DelegatedCodeActionParams() { - HostDocumentVersion = documentContext.Snapshot.Version, + HostDocumentVersion = context.DocumentSnapshot.Version, CodeActionParams = context.Request, LanguageKind = languageKind, CorrelationId = correlationId diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs index 60715601502..34e431b5769 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs @@ -528,7 +528,7 @@ public async Task GetCSharpCodeActionsFromLanguageServerAsync_InvalidRangeMappin Assert.NotNull(context); // Act - var results = await codeActionEndpoint.GetCodeActionsFromLanguageServerAsync(RazorLanguageKind.CSharp, documentContext, context, Guid.Empty, cancellationToken: default); + var results = await codeActionEndpoint.GetCodeActionsFromLanguageServerAsync(RazorLanguageKind.CSharp, context, Guid.Empty, cancellationToken: default); // Assert Assert.Empty(results); @@ -564,7 +564,7 @@ public async Task GetCSharpCodeActionsFromLanguageServerAsync_ReturnsCodeActions Assert.NotNull(context); // Act - var results = await codeActionEndpoint.GetCodeActionsFromLanguageServerAsync(RazorLanguageKind.CSharp, documentContext, context, Guid.Empty, cancellationToken: DisposalToken); + var results = await codeActionEndpoint.GetCodeActionsFromLanguageServerAsync(RazorLanguageKind.CSharp, context, Guid.Empty, cancellationToken: DisposalToken); // Assert var result = Assert.Single(results); From 03e900f14418f4605a53abb701783fe1f79dba0f Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 24 Oct 2024 11:59:18 +1100 Subject: [PATCH 03/15] Convert base resolver type to a service --- .../CSharp/CSharpCodeActionResolver.cs | 10 -- .../CSharp/DefaultCSharpCodeActionResolver.cs | 11 +- .../CSharp/ICSharpCodeActionResolver.cs | 15 ++ ...mattedRemappingCSharpCodeActionResolver.cs | 12 +- .../CodeActions/CodeActionResolveEndpoint.cs | 44 ++++-- ...lver.cs => DelegatedCodeActionResolver.cs} | 12 +- .../Html/DefaultHtmlCodeActionResolver.cs | 11 +- .../Html/HtmlCodeActionResolver.cs | 10 -- .../Html/IHtmlCodeActionResolver.cs | 15 ++ .../IDelegatedCodeActionResolver.cs | 14 ++ .../IServiceCollectionExtensions.cs | 8 +- .../DefaultCSharpCodeActionResolverTest.cs | 3 +- .../CodeActionEndToEndTest.NetFx.cs | 7 +- .../CodeActionResolutionEndpointTest.cs | 128 ++++++++---------- .../Html/DefaultHtmlCodeActionResolverTest.cs | 3 +- 15 files changed, 164 insertions(+), 139 deletions(-) delete mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/CSharpCodeActionResolver.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/ICSharpCodeActionResolver.cs rename src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/{BaseDelegatedCodeActionResolver.cs => DelegatedCodeActionResolver.cs} (54%) delete mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/HtmlCodeActionResolver.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/IHtmlCodeActionResolver.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IDelegatedCodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/CSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/CSharpCodeActionResolver.cs deleted file mode 100644 index bb2b1c3b5d9..00000000000 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/CSharpCodeActionResolver.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT license. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; - -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; - -internal abstract class CSharpCodeActionResolver(IClientConnection clientConnection) : BaseDelegatedCodeActionResolver(clientConnection) -{ -} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs index 841c7b99e16..c20bfb95d98 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs @@ -15,19 +15,20 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; internal sealed class DefaultCSharpCodeActionResolver( - IClientConnection clientConnection, - IRazorFormattingService razorFormattingService) : CSharpCodeActionResolver(clientConnection) + IDelegatedCodeActionResolver delegatedCodeActionResolver, + IRazorFormattingService razorFormattingService) : ICSharpCodeActionResolver { + private readonly IDelegatedCodeActionResolver _delegatedCodeActionResolver = delegatedCodeActionResolver; private readonly IRazorFormattingService _razorFormattingService = razorFormattingService; - public override string Action => LanguageServerConstants.CodeActions.Default; + public string Action => LanguageServerConstants.CodeActions.Default; - public async override Task ResolveAsync( + public async Task ResolveAsync( DocumentContext documentContext, CodeAction codeAction, CancellationToken cancellationToken) { - var resolvedCodeAction = await ResolveCodeActionWithServerAsync(documentContext.GetTextDocumentIdentifier(), documentContext.Snapshot.Version, RazorLanguageKind.CSharp, codeAction, cancellationToken).ConfigureAwait(false); + var resolvedCodeAction = await _delegatedCodeActionResolver.ResolveCodeActionAsync(documentContext.GetTextDocumentIdentifier(), documentContext.Snapshot.Version, RazorLanguageKind.CSharp, codeAction, cancellationToken).ConfigureAwait(false); if (resolvedCodeAction?.Edit?.DocumentChanges is null) { // Unable to resolve code action with server, return original code action diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/ICSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/ICSharpCodeActionResolver.cs new file mode 100644 index 00000000000..f0eb20ba237 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/ICSharpCodeActionResolver.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.VisualStudio.LanguageServer.Protocol; + +namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; + +internal interface ICSharpCodeActionResolver : ICodeActionResolver +{ + Task ResolveAsync(DocumentContext documentContext, CodeAction codeAction, CancellationToken cancellationToken); +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs index 2e519ca667c..0fde73bb426 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs @@ -7,7 +7,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; @@ -19,21 +18,22 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; /// Resolves and remaps the code action, without running formatting passes. /// internal sealed class UnformattedRemappingCSharpCodeActionResolver( - IClientConnection clientConnection, - IDocumentMappingService documentMappingService) : CSharpCodeActionResolver(clientConnection) + IDelegatedCodeActionResolver delegatedCodeActionResolver, + IDocumentMappingService documentMappingService) : ICSharpCodeActionResolver { + private readonly IDelegatedCodeActionResolver _delegatedCodeActionResolver = delegatedCodeActionResolver; private readonly IDocumentMappingService _documentMappingService = documentMappingService; - public override string Action => LanguageServerConstants.CodeActions.UnformattedRemap; + public string Action => LanguageServerConstants.CodeActions.UnformattedRemap; - public async override Task ResolveAsync( + public async Task ResolveAsync( DocumentContext documentContext, CodeAction codeAction, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - var resolvedCodeAction = await ResolveCodeActionWithServerAsync(documentContext.GetTextDocumentIdentifier(), documentContext.Snapshot.Version, RazorLanguageKind.CSharp, codeAction, cancellationToken).ConfigureAwait(false); + var resolvedCodeAction = await _delegatedCodeActionResolver.ResolveCodeActionAsync(documentContext.GetTextDocumentIdentifier(), documentContext.Snapshot.Version, RazorLanguageKind.CSharp, codeAction, cancellationToken).ConfigureAwait(false); if (resolvedCodeAction?.Edit?.DocumentChanges is null) { // Unable to resolve code action with server, return original code action diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs index 7d1f1dc11cf..4ec0b8cf405 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs @@ -5,6 +5,7 @@ using System.Collections.Frozen; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -14,6 +15,7 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; +using Microsoft.VisualStudio.Composition; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; @@ -21,13 +23,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; [RazorLanguageServerEndpoint(Methods.CodeActionResolveName)] internal sealed class CodeActionResolveEndpoint( IEnumerable razorCodeActionResolvers, - IEnumerable csharpCodeActionResolvers, - IEnumerable htmlCodeActionResolvers, + IEnumerable csharpCodeActionResolvers, + IEnumerable htmlCodeActionResolvers, ILoggerFactory loggerFactory) : IRazorRequestHandler { private readonly FrozenDictionary _razorCodeActionResolvers = CreateResolverMap(razorCodeActionResolvers); - private readonly FrozenDictionary _csharpCodeActionResolvers = CreateResolverMap(csharpCodeActionResolvers); - private readonly FrozenDictionary _htmlCodeActionResolvers = CreateResolverMap(htmlCodeActionResolvers); + private readonly FrozenDictionary _csharpCodeActionResolvers = CreateResolverMap(csharpCodeActionResolvers); + private readonly FrozenDictionary _htmlCodeActionResolvers = CreateResolverMap(htmlCodeActionResolvers); private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public bool MutatesSolutionState => false; @@ -52,6 +54,8 @@ public async Task HandleRequestAsync(CodeAction request, RazorReques return request; } + request.Data = resolutionParams.Data; + switch (resolutionParams.Language) { case RazorLanguageKind.Razor: @@ -118,26 +122,38 @@ private async Task ResolveRazorCodeActionAsync( return codeAction; } - private Task ResolveCSharpCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) - => ResolveDelegatedCodeActionAsync(documentContext, _csharpCodeActionResolvers, codeAction, resolutionParams, cancellationToken); + private async Task ResolveCSharpCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) + { + if (TryGetResolver(resolutionParams, _csharpCodeActionResolvers, out var resolver)) + { + return await resolver.ResolveAsync(documentContext, codeAction, cancellationToken).ConfigureAwait(false); + } - private Task ResolveHtmlCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) - => ResolveDelegatedCodeActionAsync(documentContext, _htmlCodeActionResolvers, codeAction, resolutionParams, cancellationToken); + return codeAction; + } - private async Task ResolveDelegatedCodeActionAsync(DocumentContext documentContext, FrozenDictionary resolvers, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) + private async Task ResolveHtmlCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) { - codeAction.Data = resolutionParams.Data; + if (TryGetResolver(resolutionParams, _htmlCodeActionResolvers, out var resolver)) + { + return await resolver.ResolveAsync(documentContext, codeAction, cancellationToken).ConfigureAwait(false); + } + + return codeAction; + } - if (!resolvers.TryGetValue(resolutionParams.Action, out var resolver)) + private bool TryGetResolver(RazorCodeActionResolutionParams resolutionParams, FrozenDictionary resolvers, [NotNullWhen(true)] out TResolver? resolver) + where TResolver : ICodeActionResolver + { + if (!resolvers.TryGetValue(resolutionParams.Action, out resolver)) { var codeActionId = GetCodeActionId(resolutionParams); _logger.LogWarning($"No resolver registered for {codeActionId}"); Debug.Fail($"No resolver registered for {codeActionId}."); - return codeAction; + return false; } - var resolvedCodeAction = await resolver.ResolveAsync(documentContext, codeAction, cancellationToken).ConfigureAwait(false); - return resolvedCodeAction; + return resolver is not null; } private static FrozenDictionary CreateResolverMap(IEnumerable codeActionResolvers) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/BaseDelegatedCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionResolver.cs similarity index 54% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/BaseDelegatedCodeActionResolver.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionResolver.cs index 92abf0c92e3..bc1e5331368 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/BaseDelegatedCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionResolver.cs @@ -11,19 +11,15 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; -internal abstract class BaseDelegatedCodeActionResolver(IClientConnection clientConnection) : ICodeActionResolver +internal sealed class DelegatedCodeActionResolver(IClientConnection clientConnection) : IDelegatedCodeActionResolver { - protected readonly IClientConnection ClientConnection = clientConnection; + private readonly IClientConnection _clientConnection = clientConnection; - public abstract string Action { get; } - - public abstract Task ResolveAsync(DocumentContext documentContext, CodeAction codeAction, CancellationToken cancellationToken); - - protected async Task ResolveCodeActionWithServerAsync(TextDocumentIdentifier razorFileIdentifier, int hostDocumentVersion, RazorLanguageKind languageKind, CodeAction codeAction, CancellationToken cancellationToken) + public async Task ResolveCodeActionAsync(TextDocumentIdentifier razorFileIdentifier, int hostDocumentVersion, RazorLanguageKind languageKind, CodeAction codeAction, CancellationToken cancellationToken) { var resolveCodeActionParams = new RazorResolveCodeActionParams(razorFileIdentifier, hostDocumentVersion, languageKind, codeAction); - var resolvedCodeAction = await ClientConnection.SendRequestAsync( + var resolvedCodeAction = await _clientConnection.SendRequestAsync( CustomMessageNames.RazorResolveCodeActionsEndpoint, resolveCodeActionParams, cancellationToken).ConfigureAwait(false); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionResolver.cs index 29c5bfa6125..69d679f7d99 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionResolver.cs @@ -12,19 +12,20 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; internal sealed class DefaultHtmlCodeActionResolver( - IClientConnection clientConnection, - IEditMappingService editMappingService) : HtmlCodeActionResolver(clientConnection) + IDelegatedCodeActionResolver delegatedCodeActionResolver, + IEditMappingService editMappingService) : IHtmlCodeActionResolver { + private readonly IDelegatedCodeActionResolver _delegatedCodeActionResolver = delegatedCodeActionResolver; private readonly IEditMappingService _editMappingService = editMappingService; - public override string Action => LanguageServerConstants.CodeActions.Default; + public string Action => LanguageServerConstants.CodeActions.Default; - public async override Task ResolveAsync( + public async Task ResolveAsync( DocumentContext documentContext, CodeAction codeAction, CancellationToken cancellationToken) { - var resolvedCodeAction = await ResolveCodeActionWithServerAsync(documentContext.GetTextDocumentIdentifier(), documentContext.Snapshot.Version, RazorLanguageKind.Html, codeAction, cancellationToken).ConfigureAwait(false); + var resolvedCodeAction = await _delegatedCodeActionResolver.ResolveCodeActionAsync(documentContext.GetTextDocumentIdentifier(), documentContext.Snapshot.Version, RazorLanguageKind.Html, codeAction, cancellationToken).ConfigureAwait(false); if (resolvedCodeAction?.Edit?.DocumentChanges is null) { // Unable to resolve code action with server, return original code action diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/HtmlCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/HtmlCodeActionResolver.cs deleted file mode 100644 index ad685ba8291..00000000000 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/HtmlCodeActionResolver.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT license. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; - -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; - -internal abstract class HtmlCodeActionResolver(IClientConnection clientConnection) : BaseDelegatedCodeActionResolver(clientConnection) -{ -} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/IHtmlCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/IHtmlCodeActionResolver.cs new file mode 100644 index 00000000000..92c86f6119c --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/IHtmlCodeActionResolver.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.VisualStudio.LanguageServer.Protocol; + +namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; + +internal interface IHtmlCodeActionResolver : ICodeActionResolver +{ + Task ResolveAsync(DocumentContext documentContext, CodeAction codeAction, CancellationToken cancellationToken); +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IDelegatedCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IDelegatedCodeActionResolver.cs new file mode 100644 index 00000000000..04c033f570d --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IDelegatedCodeActionResolver.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Razor.Protocol; +using Microsoft.VisualStudio.LanguageServer.Protocol; + +namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; + +internal interface IDelegatedCodeActionResolver +{ + Task ResolveCodeActionAsync(TextDocumentIdentifier razorFileIdentifier, int hostDocumentVersion, RazorLanguageKind languageKind, CodeAction codeAction, CancellationToken cancellationToken); +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs index 985d4395b83..1b06efcfddb 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs @@ -137,11 +137,13 @@ public static void AddCodeActionsServices(this IServiceCollection services) services.AddHandlerWithCapabilities(); services.AddHandler(); + services.AddSingleton(); + // CSharp Code actions services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); // Razor Code actions services.AddSingleton(); @@ -156,7 +158,7 @@ public static void AddCodeActionsServices(this IServiceCollection services) // Html Code actions services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); } public static void AddTextDocumentServices(this IServiceCollection services, LanguageServerFeatureOptions featureOptions) diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs index 57f9b3fbfac..f9f833fee39 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs @@ -173,8 +173,9 @@ private static void CreateCodeActionResolver( clientConnection ??= CreateLanguageServer(); razorFormattingService ??= CreateRazorFormattingService(documentUri); + var delegatedCodeActionResolver = new DelegatedCodeActionResolver(clientConnection); csharpCodeActionResolver = new DefaultCSharpCodeActionResolver( - clientConnection, + delegatedCodeActionResolver, razorFormattingService); documentContext = CreateDocumentContext(documentUri, codeDocument); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs index 1fee46c7657..5f448a1c54d 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs @@ -1206,12 +1206,13 @@ internal async Task GetEditsAsync( { var formattingService = await TestRazorFormattingService.CreateWithFullSupportAsync(LoggerFactory); - var csharpResolvers = new CSharpCodeActionResolver[] + var delegatedCodeActionResolver = new DelegatedCodeActionResolver(clientConnection); + var csharpResolvers = new ICSharpCodeActionResolver[] { - new DefaultCSharpCodeActionResolver(clientConnection, formattingService) + new DefaultCSharpCodeActionResolver(delegatedCodeActionResolver, formattingService) }; - var htmlResolvers = Array.Empty(); + var htmlResolvers = Array.Empty(); var resolveEndpoint = new CodeActionResolveEndpoint(razorResolvers, csharpResolvers, htmlResolvers, LoggerFactory); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs index b25ac919184..f2757cfd589 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs @@ -6,13 +6,11 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.AspNetCore.Razor.Threading; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -using Moq; using Xunit; using Xunit.Abstractions; @@ -26,11 +24,9 @@ public async Task Handle_Valid_RazorCodeAction_WithResolver() // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); var codeActionEndpoint = new CodeActionResolveEndpoint( - new IRazorCodeActionResolver[] { - new MockRazorCodeActionResolver("Test"), - }, - Array.Empty(), - Array.Empty(), + razorCodeActionResolvers: [new MockRazorCodeActionResolver("Test")], + csharpCodeActionResolvers: [], + htmlCodeActionResolvers: [], LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -62,11 +58,9 @@ public async Task Handle_Valid_CSharpCodeAction_WithResolver() // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); var codeActionEndpoint = new CodeActionResolveEndpoint( - Array.Empty(), - new CSharpCodeActionResolver[] { - new MockCSharpCodeActionResolver("Test"), - }, - Array.Empty(), + razorCodeActionResolvers: [], + [new MockCSharpCodeActionResolver("Test")], + htmlCodeActionResolvers: [], LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -94,13 +88,9 @@ public async Task Handle_Valid_CSharpCodeAction_WithMultipleLanguageResolvers() // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); var codeActionEndpoint = new CodeActionResolveEndpoint( - new IRazorCodeActionResolver[] { - new MockRazorCodeActionResolver("TestRazor"), - }, - new CSharpCodeActionResolver[] { - new MockCSharpCodeActionResolver("TestCSharp"), - }, - Array.Empty(), + razorCodeActionResolvers: [new MockRazorCodeActionResolver("TestRazor")], + csharpCodeActionResolvers: [new MockCSharpCodeActionResolver("TestCSharp")], + htmlCodeActionResolvers: [], LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -128,9 +118,9 @@ public async Task Handle_Valid_RazorCodeAction_WithoutResolver() // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); var codeActionEndpoint = new CodeActionResolveEndpoint( - Array.Empty(), - Array.Empty(), - Array.Empty(), + razorCodeActionResolvers: [], + csharpCodeActionResolvers: [], + htmlCodeActionResolvers: [], LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -167,9 +157,9 @@ public async Task Handle_Valid_CSharpCodeAction_WithoutResolver() // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); var codeActionEndpoint = new CodeActionResolveEndpoint( - Array.Empty(), - Array.Empty(), - Array.Empty(), + razorCodeActionResolvers: [], + csharpCodeActionResolvers: [], + htmlCodeActionResolvers: [], LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -202,11 +192,9 @@ public async Task Handle_Valid_RazorCodeAction_WithCSharpResolver_ResolvesNull() // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); var codeActionEndpoint = new CodeActionResolveEndpoint( - Array.Empty(), - new CSharpCodeActionResolver[] { - new MockCSharpCodeActionResolver("Test"), - }, - Array.Empty(), + razorCodeActionResolvers: [], + csharpCodeActionResolvers: [new MockCSharpCodeActionResolver("Test")], + htmlCodeActionResolvers: [], LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -243,11 +231,9 @@ public async Task Handle_Valid_CSharpCodeAction_WithRazorResolver_ResolvesNull() // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); var codeActionEndpoint = new CodeActionResolveEndpoint( - new IRazorCodeActionResolver[] { - new MockRazorCodeActionResolver("Test"), - }, - Array.Empty(), - Array.Empty(), + razorCodeActionResolvers: [new MockRazorCodeActionResolver("Test")], + csharpCodeActionResolvers: [], + htmlCodeActionResolvers: [], LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -280,12 +266,12 @@ public async Task ResolveRazorCodeAction_ResolveMultipleRazorProviders_FirstMatc // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); var codeActionEndpoint = new CodeActionResolveEndpoint( - new IRazorCodeActionResolver[] { - new MockRazorCodeActionResolver("A"), - new MockRazorNullCodeActionResolver("B"), - }, - Array.Empty(), - Array.Empty(), + razorCodeActionResolvers: [ + new MockRazorCodeActionResolver("A"), + new MockRazorNullCodeActionResolver("B"), + ], + csharpCodeActionResolvers: [], + htmlCodeActionResolvers: [], LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -312,12 +298,12 @@ public async Task ResolveRazorCodeAction_ResolveMultipleRazorProviders_SecondMat // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); var codeActionEndpoint = new CodeActionResolveEndpoint( - new IRazorCodeActionResolver[] { + razorCodeActionResolvers: [ new MockRazorNullCodeActionResolver("A"), new MockRazorCodeActionResolver("B"), - }, - Array.Empty(), - Array.Empty(), + ], + csharpCodeActionResolvers: [], + htmlCodeActionResolvers: [], LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -344,12 +330,12 @@ public async Task ResolveCSharpCodeAction_ResolveMultipleCSharpProviders_FirstMa // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); var codeActionEndpoint = new CodeActionResolveEndpoint( - Array.Empty(), - new CSharpCodeActionResolver[] { + razorCodeActionResolvers: [], + csharpCodeActionResolvers: [ new MockCSharpCodeActionResolver("A"), new MockCSharpNullCodeActionResolver("B"), - }, - Array.Empty(), + ], + htmlCodeActionResolvers: [], LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -372,12 +358,12 @@ public async Task ResolveCSharpCodeAction_ResolveMultipleCSharpProviders_SecondM // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); var codeActionEndpoint = new CodeActionResolveEndpoint( - Array.Empty(), - new CSharpCodeActionResolver[] { + razorCodeActionResolvers: [], + csharpCodeActionResolvers: [ new MockCSharpNullCodeActionResolver("A"), new MockCSharpCodeActionResolver("B"), - }, - Array.Empty(), + ], + htmlCodeActionResolvers: [], LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -400,15 +386,15 @@ public async Task ResolveCSharpCodeAction_ResolveMultipleLanguageProviders() // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); var codeActionEndpoint = new CodeActionResolveEndpoint( - new IRazorCodeActionResolver[] { + razorCodeActionResolvers: [ new MockRazorNullCodeActionResolver("A"), new MockRazorCodeActionResolver("B"), - }, - new CSharpCodeActionResolver[] { + ], + csharpCodeActionResolvers: [ new MockCSharpNullCodeActionResolver("C"), new MockCSharpCodeActionResolver("D"), - }, - Array.Empty(), + ], + htmlCodeActionResolvers: [], LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -431,11 +417,9 @@ public async Task Handle_ResolveEditBasedCodeActionCommand() // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); var codeActionEndpoint = new CodeActionResolveEndpoint( - Array.Empty(), - new CSharpCodeActionResolver[] { - new MockCSharpCodeActionResolver("Test"), - }, - Array.Empty(), + razorCodeActionResolvers: [], + csharpCodeActionResolvers: [new MockCSharpCodeActionResolver("Test")], + htmlCodeActionResolvers: [], LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -476,47 +460,45 @@ internal MockRazorCodeActionResolver(string action) private class MockRazorNullCodeActionResolver : IRazorCodeActionResolver { - public string Action { get; } + public string Action { get; } internal MockRazorNullCodeActionResolver(string action) { Action = action; } - public Task ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken) + public Task ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken) { return SpecializedTasks.Null(); } } - private class MockCSharpCodeActionResolver : CSharpCodeActionResolver + private class MockCSharpCodeActionResolver : ICSharpCodeActionResolver { - public override string Action { get; } + public string Action { get; } internal MockCSharpCodeActionResolver(string action) - : base(Mock.Of(MockBehavior.Strict)) { Action = action; } - public override Task ResolveAsync(DocumentContext documentContext, CodeAction codeAction, CancellationToken cancellationToken) + public Task ResolveAsync(DocumentContext documentContext, CodeAction codeAction, CancellationToken cancellationToken) { codeAction.Edit = new WorkspaceEdit(); return Task.FromResult(codeAction); } } - private class MockCSharpNullCodeActionResolver : CSharpCodeActionResolver + private class MockCSharpNullCodeActionResolver : ICSharpCodeActionResolver { - public override string Action { get; } + public string Action { get; } internal MockCSharpNullCodeActionResolver(string action) - : base(Mock.Of(MockBehavior.Strict)) { Action = action; } - public override Task ResolveAsync(DocumentContext documentContext, CodeAction codeAction, CancellationToken cancellationToken) + public Task ResolveAsync(DocumentContext documentContext, CodeAction codeAction, CancellationToken cancellationToken) { // This is deliberately returning null when it's not supposed to, so that if this code action // is ever returned by a method, the test will fail diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionResolverTest.cs index bbd60891454..beab8dc0f49 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionResolverTest.cs @@ -58,7 +58,8 @@ public async Task ResolveAsync_RemapsAndFixesEdits() .Setup(x => x.RemapWorkspaceEditAsync(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(remappedEdit); - var resolver = new DefaultHtmlCodeActionResolver(CreateLanguageServer(resolvedCodeAction), editMappingServiceMock.Object); + var delegatedCodeActionResolver = new DelegatedCodeActionResolver(CreateLanguageServer(resolvedCodeAction)); + var resolver = new DefaultHtmlCodeActionResolver(delegatedCodeActionResolver, editMappingServiceMock.Object); var codeAction = new RazorVSInternalCodeAction() { From 001ebcfa7edecf15809f6fc41456105b07bc016a Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 24 Oct 2024 13:24:25 +1100 Subject: [PATCH 04/15] Introduce service for getting code actions from delegated servers --- .../RazorCodeActionsBenchmark.cs | 7 ++- .../CodeActions/CodeActionEndpoint.cs | 49 +++++------------- .../DelegatedCodeActionsProvider.cs | 51 +++++++++++++++++++ .../IDelegatedCodeActionsProvider.cs | 16 ++++++ .../IServiceCollectionExtensions.cs | 1 + .../CodeActionEndToEndTest.NetFx.cs | 7 +-- .../CodeActions/CodeActionEndpointTest.cs | 11 ++-- 7 files changed, 97 insertions(+), 45 deletions(-) create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionsProvider.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IDelegatedCodeActionsProvider.cs diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs index 11fc48f289e..1a499ac2233 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs @@ -12,8 +12,8 @@ using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.AspNetCore.Razor.Telemetry; using Microsoft.CodeAnalysis.Razor.DocumentMapping; -using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; using Microsoft.CodeAnalysis.Razor.Workspaces; @@ -53,10 +53,9 @@ public async Task SetupAsync() razorCodeActionProviders: RazorLanguageServerHost.GetRequiredService>(), csharpCodeActionProviders: RazorLanguageServerHost.GetRequiredService>(), htmlCodeActionProviders: RazorLanguageServerHost.GetRequiredService>(), - clientConnection: RazorLanguageServerHost.GetRequiredService(), + delegatedCodeActionsProvider: RazorLanguageServerHost.GetRequiredService(), languageServerFeatureOptions: RazorLanguageServerHost.GetRequiredService(), - loggerFactory: RazorLanguageServerHost.GetRequiredService(), - telemetryReporter: null); + telemetryReporter: NoOpTelemetryReporter.Instance); var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp"); var projectFilePath = Path.Combine(projectRoot, "ComponentApp.csproj"); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs index 82f9675e9de..d0cea599a40 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs @@ -12,9 +12,9 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Telemetry; +using Microsoft.AspNetCore.Razor.Threading; using Microsoft.CodeAnalysis.ExternalAccess.Razor; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.Logging; @@ -24,7 +24,6 @@ using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; -using StreamJsonRpc; namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; @@ -34,22 +33,20 @@ internal sealed class CodeActionEndpoint( IEnumerable razorCodeActionProviders, IEnumerable csharpCodeActionProviders, IEnumerable htmlCodeActionProviders, - IClientConnection clientConnection, + IDelegatedCodeActionsProvider delegatedCodeActionsProvider, LanguageServerFeatureOptions languageServerFeatureOptions, - ILoggerFactory loggerFactory, - ITelemetryReporter? telemetryReporter) + ITelemetryReporter telemetryReporter) : IRazorRequestHandler[]?>, ICapabilitiesProvider { private const string LspEndpointName = Methods.TextDocumentCodeActionName; - private readonly IDocumentMappingService _documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService)); - private readonly IEnumerable _razorCodeActionProviders = razorCodeActionProviders ?? throw new ArgumentNullException(nameof(razorCodeActionProviders)); - private readonly IEnumerable _csharpCodeActionProviders = csharpCodeActionProviders ?? throw new ArgumentNullException(nameof(csharpCodeActionProviders)); - private readonly IEnumerable _htmlCodeActionProviders = htmlCodeActionProviders ?? throw new ArgumentNullException(nameof(htmlCodeActionProviders)); - private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException(nameof(languageServerFeatureOptions)); - private readonly IClientConnection _clientConnection = clientConnection ?? throw new ArgumentNullException(nameof(clientConnection)); - private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); - private readonly ITelemetryReporter? _telemetryReporter = telemetryReporter; + private readonly IDocumentMappingService _documentMappingService = documentMappingService; + private readonly IEnumerable _razorCodeActionProviders = razorCodeActionProviders; + private readonly IEnumerable _csharpCodeActionProviders = csharpCodeActionProviders; + private readonly IEnumerable _htmlCodeActionProviders = htmlCodeActionProviders; + private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions; + private readonly IDelegatedCodeActionsProvider _delegatedCodeActionsProvider = delegatedCodeActionsProvider; + private readonly ITelemetryReporter _telemetryReporter = telemetryReporter; internal bool _supportsCodeActionResolve = false; @@ -74,7 +71,7 @@ internal sealed class CodeActionEndpoint( cancellationToken.ThrowIfCancellationRequested(); var correlationId = Guid.NewGuid(); - using var __ = _telemetryReporter?.TrackLspRequest(LspEndpointName, LanguageServerConstants.RazorLanguageServerName, correlationId); + using var __ = _telemetryReporter.TrackLspRequest(LspEndpointName, LanguageServerConstants.RazorLanguageServerName, correlationId); var razorCodeActions = await GetRazorCodeActionsAsync(razorCodeActionContext, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); @@ -265,14 +262,14 @@ private static async Task> FilterCodeA } // Internal for testing - internal async Task GetCodeActionsFromLanguageServerAsync(RazorLanguageKind languageKind, RazorCodeActionContext context, Guid correlationId, CancellationToken cancellationToken) + internal Task GetCodeActionsFromLanguageServerAsync(RazorLanguageKind languageKind, RazorCodeActionContext context, Guid correlationId, CancellationToken cancellationToken) { if (languageKind == RazorLanguageKind.CSharp) { // For C# we have to map the ranges to the generated document if (!_documentMappingService.TryMapToGeneratedDocumentRange(context.CodeDocument.GetCSharpDocument(), context.Request.Range, out var projectedRange)) { - return []; + return SpecializedTasks.EmptyArray(); } var newContext = context.Request.Context; @@ -288,25 +285,7 @@ internal async Task GetCodeActionsFromLanguageServe } cancellationToken.ThrowIfCancellationRequested(); - - var delegatedParams = new DelegatedCodeActionParams() - { - HostDocumentVersion = context.DocumentSnapshot.Version, - CodeActionParams = context.Request, - LanguageKind = languageKind, - CorrelationId = correlationId - }; - - try - { - return await _clientConnection.SendRequestAsync(CustomMessageNames.RazorProvideCodeActionsEndpoint, delegatedParams, cancellationToken).ConfigureAwait(false); - } - catch (RemoteInvocationException e) - { - _telemetryReporter?.ReportFault(e, "Error getting code actions from delegate language server for {languageKind}", languageKind); - _logger.LogError(e, $"Error getting code actions from delegate language server for {languageKind}"); - return []; - } + return _delegatedCodeActionsProvider.GetDelegatedCodeActionsAsync(languageKind, context.Request, context.DocumentSnapshot.Version, correlationId, cancellationToken); } private async Task> GetRazorCodeActionsAsync(RazorCodeActionContext context, CancellationToken cancellationToken) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionsProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionsProvider.cs new file mode 100644 index 00000000000..0aca4935161 --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionsProvider.cs @@ -0,0 +1,51 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.AspNetCore.Razor.Telemetry; +using Microsoft.CodeAnalysis.Razor.Logging; +using Microsoft.CodeAnalysis.Razor.Protocol; +using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; +using Microsoft.VisualStudio.RpcContracts; +using StreamJsonRpc; + +namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; + +internal sealed class DelegatedCodeActionsProvider( + IClientConnection clientConnection, + ITelemetryReporter telemetryReporter, + ILoggerFactory loggerFactory) : IDelegatedCodeActionsProvider +{ + private readonly IClientConnection _clientConnection = clientConnection; + private readonly ITelemetryReporter _telemetryReporter = telemetryReporter; + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); + + public async Task GetDelegatedCodeActionsAsync(RazorLanguageKind languageKind, VSCodeActionParams request, int hostDocumentVersion, Guid correlationId, CancellationToken cancellationToken) + { + var delegatedParams = new DelegatedCodeActionParams() + { + HostDocumentVersion = hostDocumentVersion, + CodeActionParams = request, + LanguageKind = languageKind, + CorrelationId = correlationId + }; + + try + { + return await _clientConnection.SendRequestAsync(CustomMessageNames.RazorProvideCodeActionsEndpoint, delegatedParams, cancellationToken).ConfigureAwait(false); + } + catch (RemoteInvocationException e) + { + _telemetryReporter.ReportFault(e, "Error getting code actions from delegate language server for {languageKind}", languageKind); + _logger.LogError(e, $"Error getting code actions from delegate language server for {languageKind}"); + return []; + } + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IDelegatedCodeActionsProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IDelegatedCodeActionsProvider.cs new file mode 100644 index 00000000000..b7061c43cec --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IDelegatedCodeActionsProvider.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.Protocol; +using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; + +namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; + +internal interface IDelegatedCodeActionsProvider +{ + Task GetDelegatedCodeActionsAsync(RazorLanguageKind languageKind, VSCodeActionParams request, int hostDocumentVersion, Guid correlationId, CancellationToken cancellationToken); +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs index 1b06efcfddb..bf26133afe9 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs @@ -137,6 +137,7 @@ public static void AddCodeActionsServices(this IServiceCollection services) services.AddHandlerWithCapabilities(); services.AddHandler(); + services.AddSingleton(); services.AddSingleton(); // CSharp Code actions diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs index 5f448a1c54d..ad4f0d3b90d 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs @@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.AspNetCore.Razor.Telemetry; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; using Microsoft.AspNetCore.Razor.Utilities; @@ -1160,6 +1161,7 @@ internal async Task[]> GetCodeActionsAsync( IRazorCodeActionProvider[]? razorProviders = null, Diagnostic[]? diagnostics = null) { + var delegatedCodeActionsProvider = new DelegatedCodeActionsProvider(clientConnection, NoOpTelemetryReporter.Instance, LoggerFactory); var endpoint = new CodeActionEndpoint( DocumentMappingService.AssumeNotNull(), razorCodeActionProviders: razorProviders ?? [], @@ -1169,10 +1171,9 @@ internal async Task[]> GetCodeActionsAsync( new TypeAccessibilityCodeActionProvider() ], htmlCodeActionProviders: [], - clientConnection, + delegatedCodeActionsProvider, LanguageServerFeatureOptions.AssumeNotNull(), - LoggerFactory, - telemetryReporter: null); + NoOpTelemetryReporter.Instance); // Call GetRegistration, so the endpoint knows we support resolve endpoint.ApplyCapabilities(new(), new VSInternalClientCapabilities diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs index 34e431b5769..85848b1f4ff 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.AspNetCore.Razor.Telemetry; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.CodeAnalysis.Razor.DocumentMapping; @@ -591,15 +592,19 @@ private CodeActionEndpoint CreateEndpoint( LanguageServerFeatureOptions? languageServerFeatureOptions = null, bool supportsCodeActionResolve = false) { + var delegatedCodeActionsProvider = new DelegatedCodeActionsProvider( + clientConnection ?? StrictMock.Of(), + NoOpTelemetryReporter.Instance, + LoggerFactory); + return new CodeActionEndpoint( documentMappingService ?? CreateDocumentMappingService(), razorCodeActionProviders.NullToEmpty(), csharpCodeActionProviders.NullToEmpty(), htmlCodeActionProviders.NullToEmpty(), - clientConnection ?? StrictMock.Of(), + delegatedCodeActionsProvider, languageServerFeatureOptions ?? StrictMock.Of(x => x.SupportsFileManipulation == true), - LoggerFactory, - telemetryReporter: null) + NoOpTelemetryReporter.Instance) { _supportsCodeActionResolve = supportsCodeActionResolve }; From b0926dfdddc818a8cadcd13782781a1123eccdbf Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 24 Oct 2024 13:44:55 +1100 Subject: [PATCH 05/15] Introduce service for using our custom Roslyn endpoints --- .../ExtractToCodeBehindCodeActionResolver.cs | 18 ++----- .../Razor/GenerateMethodCodeActionResolver.cs | 28 +++-------- .../Razor/IRoslynCodeActionHelpers.cs | 15 ++++++ .../Razor/RoslynCodeActionHelpers.cs | 47 +++++++++++++++++++ .../IServiceCollectionExtensions.cs | 3 +- .../CodeActionEndToEndTest.NetFx.cs | 14 +++--- ...tractToCodeBehindCodeActionResolverTest.cs | 37 ++++++++++----- 7 files changed, 105 insertions(+), 57 deletions(-) create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRoslynCodeActionHelpers.cs create mode 100644 src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/RoslynCodeActionHelpers.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs index 130b6d75c2e..f1c968d14e3 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs @@ -27,12 +27,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; internal sealed class ExtractToCodeBehindCodeActionResolver( LanguageServerFeatureOptions languageServerFeatureOptions, - IClientConnection clientConnection) : IRazorCodeActionResolver + IRoslynCodeActionHelpers roslynCodeActionHelpers) : IRazorCodeActionResolver { private static readonly Workspace s_workspace = new AdhocWorkspace(); private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions; - private readonly IClientConnection _clientConnection = clientConnection; + private readonly IRoslynCodeActionHelpers _roslynCodeActionHelpers = roslynCodeActionHelpers; public string Action => LanguageServerConstants.CodeActions.ExtractToCodeBehindAction; @@ -137,19 +137,7 @@ private async Task GenerateCodeBehindClassAsync(IProjectSnapshot project var newFileContent = builder.ToString(); - var parameters = new FormatNewFileParams() - { - Project = new TextDocumentIdentifier - { - Uri = new Uri(project.FilePath, UriKind.Absolute) - }, - Document = new TextDocumentIdentifier - { - Uri = codeBehindUri - }, - Contents = newFileContent - }; - var fixedContent = await _clientConnection.SendRequestAsync(CustomMessageNames.RazorFormatNewFileEndpointName, parameters, cancellationToken).ConfigureAwait(false); + var fixedContent = await _roslynCodeActionHelpers.GetFormattedNewFileContentsAsync(project.FilePath, codeBehindUri, newFileContent, cancellationToken).ConfigureAwait(false); if (fixedContent is null) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs index efe227f47bf..e32e05d3861 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs @@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Differencing; using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.Formatting; @@ -28,12 +29,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; internal sealed class GenerateMethodCodeActionResolver( RazorLSPOptionsMonitor razorLSPOptionsMonitor, - IClientConnection clientConnection, + IRoslynCodeActionHelpers roslynCodeActionHelpers, IDocumentMappingService documentMappingService, IRazorFormattingService razorFormattingService) : IRazorCodeActionResolver { private readonly RazorLSPOptionsMonitor _razorLSPOptionsMonitor = razorLSPOptionsMonitor; - private readonly IClientConnection _clientConnection = clientConnection; + private readonly IRoslynCodeActionHelpers _roslynCodeActionHelpers = roslynCodeActionHelpers; private readonly IDocumentMappingService _documentMappingService = documentMappingService; private readonly IRazorFormattingService _razorFormattingService = razorFormattingService; @@ -112,15 +113,7 @@ razorClassName is null || character: 0, $"{formattedMethod}{Environment.NewLine}"); - var delegatedParams = new DelegatedSimplifyMethodParams( - new TextDocumentIdentifierAndVersion(new TextDocumentIdentifier() { Uri = codeBehindUri }, 1), - RequiresVirtualDocument: false, - edit); - - var result = await _clientConnection.SendRequestAsync( - CustomMessageNames.RazorSimplifyMethodEndpointName, - delegatedParams, - cancellationToken).ConfigureAwait(false); + var result = await _roslynCodeActionHelpers.GetSimplifiedTextEditsAsync(codeBehindUri, edit, requiresVirtualDocument: false, cancellationToken).ConfigureAwait(false); var codeBehindTextDocEdit = new TextDocumentEdit() { @@ -161,11 +154,7 @@ private async Task GenerateMethodInCodeBlockAsync( character: 0, editToSendToRoslyn.NewText); - var delegatedParams = new DelegatedSimplifyMethodParams(documentContext.GetTextDocumentIdentifierAndVersion(), RequiresVirtualDocument: true, tempTextEdit); - var result = await _clientConnection.SendRequestAsync( - CustomMessageNames.RazorSimplifyMethodEndpointName, - delegatedParams, - cancellationToken).ConfigureAwait(false); + var result = await _roslynCodeActionHelpers.GetSimplifiedTextEditsAsync(documentContext.Uri, tempTextEdit, requiresVirtualDocument: true, cancellationToken).ConfigureAwait(false); // Roslyn should have passed back 2 edits. One that contains the simplified method stub and the other that contains the new // location for the class end brace since we had asked to insert the method stub at the original class end brace location. @@ -188,12 +177,7 @@ private async Task GenerateMethodInCodeBlockAsync( .Replace(FormattingUtilities.Indent, string.Empty); var remappedEdit = VsLspFactory.CreateTextEdit(remappedRange, unformattedMethodSignature); - - var delegatedParams = new DelegatedSimplifyMethodParams(documentContext.GetTextDocumentIdentifierAndVersion(), RequiresVirtualDocument: true, remappedEdit); - var result = await _clientConnection.SendRequestAsync( - CustomMessageNames.RazorSimplifyMethodEndpointName, - delegatedParams, - cancellationToken).ConfigureAwait(false); + var result = await _roslynCodeActionHelpers.GetSimplifiedTextEditsAsync(documentContext.Uri, remappedEdit, requiresVirtualDocument: true, cancellationToken).ConfigureAwait(false); if (result is not null) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRoslynCodeActionHelpers.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRoslynCodeActionHelpers.cs new file mode 100644 index 00000000000..cc0f4d9d13c --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRoslynCodeActionHelpers.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.VisualStudio.LanguageServer.Protocol; + +namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; + +internal interface IRoslynCodeActionHelpers +{ + Task GetFormattedNewFileContentsAsync(string projectFilePath, Uri csharpFileUri, string newFileContent, CancellationToken cancellationToken); + Task GetSimplifiedTextEditsAsync(Uri codeBehindUri, TextEdit edit, bool requiresVirtualDocument, CancellationToken cancellationToken); +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/RoslynCodeActionHelpers.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/RoslynCodeActionHelpers.cs new file mode 100644 index 00000000000..e5e691ef83e --- /dev/null +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/RoslynCodeActionHelpers.cs @@ -0,0 +1,47 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.CodeAnalysis.Razor.Protocol; +using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; +using Microsoft.VisualStudio.LanguageServer.Protocol; + +namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; + +internal sealed class RoslynCodeActionHelpers(IClientConnection clientConnection) : IRoslynCodeActionHelpers +{ + private readonly IClientConnection _clientConnection = clientConnection; + + public Task GetFormattedNewFileContentsAsync(string projectFilePath, Uri csharpFileUri, string newFileContent, CancellationToken cancellationToken) + { + var parameters = new FormatNewFileParams() + { + Project = new TextDocumentIdentifier + { + Uri = new Uri(projectFilePath, UriKind.Absolute) + }, + Document = new TextDocumentIdentifier + { + Uri = csharpFileUri + }, + Contents = newFileContent + }; + return _clientConnection.SendRequestAsync(CustomMessageNames.RazorFormatNewFileEndpointName, parameters, cancellationToken); + } + + public Task GetSimplifiedTextEditsAsync(Uri codeBehindUri, TextEdit edit, bool requiresVirtualDocument, CancellationToken cancellationToken) + { + var delegatedParams = new DelegatedSimplifyMethodParams( + new TextDocumentIdentifierAndVersion(new TextDocumentIdentifier() { Uri = codeBehindUri }, 1), + requiresVirtualDocument, + edit); + + return _clientConnection.SendRequestAsync( + CustomMessageNames.RazorSimplifyMethodEndpointName, + delegatedParams, + cancellationToken); + } +} diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs index bf26133afe9..b8b484434db 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs @@ -139,6 +139,7 @@ public static void AddCodeActionsServices(this IServiceCollection services) services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); // CSharp Code actions services.AddSingleton(); @@ -150,7 +151,7 @@ public static void AddCodeActionsServices(this IServiceCollection services) services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs index ad4f0d3b90d..a48608358e0 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs @@ -42,14 +42,14 @@ public class CodeActionEndToEndTest(ITestOutputHelper testOutput) : SingleServer private const string CodeBehindTestReplaceNamespace = "$$Replace_Namespace$$"; private GenerateMethodCodeActionResolver[] CreateRazorCodeActionResolvers( - IClientConnection clientConnection, + IRoslynCodeActionHelpers roslynCodeActionHelpers, IRazorFormattingService razorFormattingService, RazorLSPOptionsMonitor? optionsMonitor = null) => [ new GenerateMethodCodeActionResolver( optionsMonitor ?? TestRazorLSPOptionsMonitor.Create(), - clientConnection, + roslynCodeActionHelpers, new LspDocumentMappingService(FilePathService, new TestDocumentContextFactory(), LoggerFactory), razorFormattingService) ]; @@ -1039,11 +1039,12 @@ private async Task ValidateCodeBehindFileAsync( Assert.NotNull(codeActionToRun); var formattingService = await TestRazorFormattingService.CreateWithFullSupportAsync(LoggerFactory); + var roslynCodeActionHelpers = new RoslynCodeActionHelpers(languageServer); var changes = await GetEditsAsync( codeActionToRun, requestContext, languageServer, - CreateRazorCodeActionResolvers(languageServer, formattingService)); + CreateRazorCodeActionResolvers(roslynCodeActionHelpers, formattingService)); var razorEdits = new List(); var codeBehindEdits = new List(); @@ -1077,7 +1078,7 @@ private Task ValidateCodeActionAsync( string codeAction, int childActionIndex = 0, IRazorCodeActionProvider[]? razorCodeActionProviders = null, - Func? codeActionResolversCreator = null, + Func? codeActionResolversCreator = null, RazorLSPOptionsMonitor? optionsMonitor = null, Diagnostic[]? diagnostics = null) { @@ -1090,7 +1091,7 @@ private async Task ValidateCodeActionAsync( string codeAction, int childActionIndex = 0, IRazorCodeActionProvider[]? razorCodeActionProviders = null, - Func? codeActionResolversCreator = null, + Func? codeActionResolversCreator = null, RazorLSPOptionsMonitor? optionsMonitor = null, Diagnostic[]? diagnostics = null) { @@ -1125,11 +1126,12 @@ private async Task ValidateCodeActionAsync( Assert.NotNull(codeActionToRun); var formattingService = await TestRazorFormattingService.CreateWithFullSupportAsync(LoggerFactory, codeDocument, optionsMonitor?.CurrentValue); + var roslynCodeActionHelpers = new RoslynCodeActionHelpers(languageServer); var changes = await GetEditsAsync( codeActionToRun, requestContext, languageServer, - codeActionResolversCreator?.Invoke(languageServer, formattingService, optionsMonitor) ?? []); + codeActionResolversCreator?.Invoke(roslynCodeActionHelpers, formattingService, optionsMonitor) ?? []); var edits = new List(); foreach (var change in changes) diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionResolverTest.cs index 50b1868090c..1b1af10b233 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionResolverTest.cs @@ -33,7 +33,7 @@ public async Task Handle_Unsupported() { // Arrange var documentPath = new Uri("c:\\Test.razor"); - var contents = $$""" + var contents = """ @page "/test" @code { private int x = 1; } """; @@ -41,7 +41,8 @@ public async Task Handle_Unsupported() codeDocument.SetUnsupported(); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, _languageServer); + var roslynCodeActionHelpers = new RoslynCodeActionHelpers(_languageServer); + var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, roslynCodeActionHelpers); var data = JsonSerializer.SerializeToElement(CreateExtractToCodeBehindCodeActionParams(contents, "@code", "Test")); // Act @@ -56,7 +57,7 @@ public async Task Handle_InvalidFileKind() { // Arrange var documentPath = new Uri("c:\\Test.razor"); - var contents = $$""" + var contents = """ @page "/test" @code { private int x = 1; } """; @@ -64,7 +65,8 @@ public async Task Handle_InvalidFileKind() codeDocument.SetFileKind(FileKinds.Legacy); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, _languageServer); + var roslynCodeActionHelpers = new RoslynCodeActionHelpers(_languageServer); + var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, roslynCodeActionHelpers); var data = JsonSerializer.SerializeToElement(CreateExtractToCodeBehindCodeActionParams(contents, "@code", "Test")); // Act @@ -90,7 +92,8 @@ public async Task Handle_ExtractCodeBlock() Assert.True(codeDocument.TryComputeNamespace(fallbackToRootNamespace: true, out var @namespace)); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, _languageServer); + var roslynCodeActionHelpers = new RoslynCodeActionHelpers(_languageServer); + var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, roslynCodeActionHelpers); var actionParams = CreateExtractToCodeBehindCodeActionParams(contents, "@code", @namespace); var data = JsonSerializer.SerializeToElement(actionParams); @@ -154,7 +157,8 @@ public async Task Handle_ExtractCodeBlock2() Assert.True(codeDocument.TryComputeNamespace(fallbackToRootNamespace: true, out var @namespace)); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, _languageServer); + var roslynCodeActionHelpers = new RoslynCodeActionHelpers(_languageServer); + var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, roslynCodeActionHelpers); var actionParams = CreateExtractToCodeBehindCodeActionParams(contents, "@code", @namespace); var data = JsonSerializer.SerializeToElement(actionParams); @@ -226,7 +230,8 @@ private void M() Assert.True(codeDocument.TryComputeNamespace(fallbackToRootNamespace: true, out var @namespace)); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, _languageServer); + var roslynCodeActionHelpers = new RoslynCodeActionHelpers(_languageServer); + var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, roslynCodeActionHelpers); var actionParams = CreateExtractToCodeBehindCodeActionParams(contents, "@code", @namespace); var data = JsonSerializer.SerializeToElement(actionParams); @@ -308,7 +313,8 @@ private void M() Assert.True(codeDocument.TryComputeNamespace(fallbackToRootNamespace: true, out var @namespace)); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, _languageServer); + var roslynCodeActionHelpers = new RoslynCodeActionHelpers(_languageServer); + var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, roslynCodeActionHelpers); var actionParams = CreateExtractToCodeBehindCodeActionParams(contents, "@code", @namespace); var data = JsonSerializer.SerializeToElement(actionParams); @@ -392,7 +398,8 @@ private void M() Assert.True(codeDocument.TryComputeNamespace(fallbackToRootNamespace: true, out var @namespace)); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, _languageServer); + var roslynCodeActionHelpers = new RoslynCodeActionHelpers(_languageServer); + var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, roslynCodeActionHelpers); var actionParams = CreateExtractToCodeBehindCodeActionParams(contents, "@code", @namespace); var data = JsonSerializer.SerializeToElement(actionParams); @@ -464,7 +471,8 @@ public async Task Handle_ExtractFunctionsBlock() Assert.True(codeDocument.TryComputeNamespace(fallbackToRootNamespace: true, out var @namespace)); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, _languageServer); + var roslynCodeActionHelpers = new RoslynCodeActionHelpers(_languageServer); + var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, roslynCodeActionHelpers); var actionParams = CreateExtractToCodeBehindCodeActionParams(contents, "@functions", @namespace); var data = JsonSerializer.SerializeToElement(actionParams); @@ -528,7 +536,8 @@ @using System.Diagnostics Assert.True(codeDocument.TryComputeNamespace(fallbackToRootNamespace: true, out var @namespace)); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, _languageServer); + var roslynCodeActionHelpers = new RoslynCodeActionHelpers(_languageServer); + var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, roslynCodeActionHelpers); var actionParams = CreateExtractToCodeBehindCodeActionParams(contents, "@code", @namespace); var data = JsonSerializer.SerializeToElement(actionParams); @@ -594,7 +603,8 @@ public async Task Handle_ExtractCodeBlockWithDirectives() Assert.True(codeDocument.TryComputeNamespace(fallbackToRootNamespace: true, out var @namespace)); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, _languageServer); + var roslynCodeActionHelpers = new RoslynCodeActionHelpers(_languageServer); + var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, roslynCodeActionHelpers); var actionParams = CreateExtractToCodeBehindCodeActionParams(contents, "@code", @namespace); var data = JsonSerializer.SerializeToElement(actionParams); @@ -664,7 +674,8 @@ public async Task Handle_ExtractCodeBlock_CallsRoslyn() }); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, languageServer); + var roslynCodeActionHelpers = new RoslynCodeActionHelpers(languageServer); + var resolver = new ExtractToCodeBehindCodeActionResolver(TestLanguageServerFeatureOptions.Instance, roslynCodeActionHelpers); var actionParams = CreateExtractToCodeBehindCodeActionParams(contents, "@code", @namespace); var data = JsonSerializer.SerializeToElement(actionParams); From 3eacfbd8458998665198c33d859fc8c998a05ed7 Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 24 Oct 2024 14:22:57 +1100 Subject: [PATCH 06/15] Pass options around rather than using the monitor --- .../CodeActions/CodeActionResolveEndpoint.cs | 18 ++++++++++++--- .../Razor/AddUsingsCodeActionResolver.cs | 2 +- .../CodeActions/Razor/CodeBlockService.cs | 6 ++--- .../CreateComponentCodeActionResolver.cs | 3 ++- .../ExtractToCodeBehindCodeActionResolver.cs | 3 ++- .../ExtractToComponentCodeActionResolver.cs | 2 +- .../Razor/GenerateMethodCodeActionResolver.cs | 19 +++++++-------- .../Razor/IRazorCodeActionResolver.cs | 3 ++- .../AddUsingsCodeActionResolverTest.cs | 19 +++++++-------- .../CodeActionEndToEndTest.NetFx.cs | 16 +++++++------ .../CodeActionResolutionEndpointTest.cs | 22 ++++++++++++++---- .../CreateComponentCodeActionResolverTest.cs | 9 ++++---- ...tractToCodeBehindCodeActionResolverTest.cs | 23 ++++++++++--------- ...ToComponentCodeActionResolverTest.NetFx.cs | 1 + 14 files changed, 91 insertions(+), 55 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs index 4ec0b8cf405..83ae35cd3c2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs @@ -12,6 +12,7 @@ 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 razorCodeActionResolvers, IEnumerable csharpCodeActionResolvers, IEnumerable htmlCodeActionResolvers, + RazorLSPOptionsMonitor razorLSPOptionsMonitor, ILoggerFactory loggerFactory) : IRazorRequestHandler { private readonly FrozenDictionary _razorCodeActionResolvers = CreateResolverMap(razorCodeActionResolvers); private readonly FrozenDictionary _csharpCodeActionResolvers = CreateResolverMap(csharpCodeActionResolvers); private readonly FrozenDictionary _htmlCodeActionResolvers = CreateResolverMap(htmlCodeActionResolvers); + private readonly RazorLSPOptionsMonitor _razorLSPOptionsMonitor = razorLSPOptionsMonitor; private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public bool MutatesSolutionState => false; @@ -54,6 +57,13 @@ public async Task HandleRequestAsync(CodeAction request, RazorReques 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 @@ public async Task HandleRequestAsync(CodeAction request, RazorReques documentContext, request, resolutionParams, + options, cancellationToken).ConfigureAwait(false); case RazorLanguageKind.CSharp: return await ResolveCSharpCodeActionAsync( @@ -102,6 +113,7 @@ private async Task ResolveRazorCodeActionAsync( DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, + RazorFormattingOptions options, CancellationToken cancellationToken) { if (!_razorCodeActionResolvers.TryGetValue(resolutionParams.Action, out var resolver)) @@ -117,7 +129,7 @@ private async Task ResolveRazorCodeActionAsync( 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 @@ private static string GetCodeActionId(RazorCodeActionResolutionParams resolution internal readonly struct TestAccessor(CodeActionResolveEndpoint instance) { - public Task ResolveRazorCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) - => instance.ResolveRazorCodeActionAsync(documentContext, codeAction, resolutionParams, cancellationToken); + public Task ResolveRazorCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, RazorFormattingOptions options, CancellationToken cancellationToken) + => instance.ResolveRazorCodeActionAsync(documentContext, codeAction, resolutionParams, options, cancellationToken); public Task ResolveCSharpCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) => instance.ResolveCSharpCodeActionAsync(documentContext, codeAction, resolutionParams, cancellationToken); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/AddUsingsCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/AddUsingsCodeActionResolver.cs index 9ecb00dc643..c8c1cdc4305 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/AddUsingsCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/AddUsingsCodeActionResolver.cs @@ -19,7 +19,7 @@ internal sealed class AddUsingsCodeActionResolver : IRazorCodeActionResolver { public string Action => LanguageServerConstants.CodeActions.AddUsing; - public async Task ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken) + public async Task ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken) { var actionParams = data.Deserialize(); if (actionParams is null) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs index 01869f6106e..f4cff29e71b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs @@ -34,12 +34,12 @@ internal static class CodeBlockService /// } /// /// - /// The that contains information about indentation. + /// The that contains information about indentation. /// /// /// A that will place the formatted generated method within a @code block in the file. /// - 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 @@ private static string FormatMethodInCodeBlock( 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'. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CreateComponentCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CreateComponentCodeActionResolver.cs index ff58cdea1fe..5b9d9072842 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CreateComponentCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CreateComponentCodeActionResolver.cs @@ -12,6 +12,7 @@ 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 ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken) + public async Task ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken) { var actionParams = data.Deserialize(); if (actionParams is null) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs index f1c968d14e3..245d2042aee 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs @@ -16,6 +16,7 @@ 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 ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken) + public async Task ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken) { var actionParams = data.Deserialize(); if (actionParams is null) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs index a0a265359f5..1cc26c623ef 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs @@ -26,7 +26,7 @@ internal sealed class ExtractToComponentCodeActionResolver( public string Action => LanguageServerConstants.CodeActions.ExtractToNewComponentAction; - public async Task ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken) + public async Task ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken) { if (data.ValueKind == JsonValueKind.Undefined) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs index e32e05d3861..9e96d2a71b6 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs @@ -28,12 +28,10 @@ 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 ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken) + public async Task ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken) { var actionParams = data.Deserialize(); if (actionParams is null) @@ -73,6 +71,7 @@ razorClassName is null || documentContext, razorNamespace: null, razorClassName, + options, cancellationToken).ConfigureAwait(false); } @@ -86,6 +85,7 @@ razorClassName is null || documentContext, razorNamespace, razorClassName, + options, cancellationToken).ConfigureAwait(false); } @@ -102,8 +102,8 @@ razorClassName is null || 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 @@ private async Task GenerateMethodInCodeBlockAsync( 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 @@ private async Task GenerateMethodInCodeBlockAsync( { 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( diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRazorCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRazorCodeActionResolver.cs index 07632324055..6999a43bbff 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRazorCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRazorCodeActionResolver.cs @@ -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 ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken); + Task ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken); } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/AddUsingsCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/AddUsingsCodeActionResolverTest.cs index e2bd806f51b..ac6e915e6b9 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/AddUsingsCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/AddUsingsCodeActionResolverTest.cs @@ -9,6 +9,7 @@ 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 async Task Handle_Unsupported() }); // 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 async Task Handle_AddOneUsingToEmpty() 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 async Task Handle_AddOneUsingToComponentPageDirective() 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 @@ @model IndexModel 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 async Task Handle_AddOneUsingToHTML() 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 @@ @namespace Testing 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 @@ @namespace Testing 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 async Task Handle_AddOneUsingToUsings() 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 @@ @using System.Linq 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); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs index a48608358e0..0a1fa4be88c 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs @@ -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 @@ private async Task ValidateCodeBehindFileAsync( codeActionToRun, requestContext, languageServer, + optionsMonitor: null, CreateRazorCodeActionResolvers(roslynCodeActionHelpers, formattingService)); var razorEdits = new List(); @@ -1078,7 +1077,7 @@ private Task ValidateCodeActionAsync( string codeAction, int childActionIndex = 0, IRazorCodeActionProvider[]? razorCodeActionProviders = null, - Func? codeActionResolversCreator = null, + Func? codeActionResolversCreator = null, RazorLSPOptionsMonitor? optionsMonitor = null, Diagnostic[]? diagnostics = null) { @@ -1091,7 +1090,7 @@ private async Task ValidateCodeActionAsync( string codeAction, int childActionIndex = 0, IRazorCodeActionProvider[]? razorCodeActionProviders = null, - Func? codeActionResolversCreator = null, + Func? codeActionResolversCreator = null, RazorLSPOptionsMonitor? optionsMonitor = null, Diagnostic[]? diagnostics = null) { @@ -1131,7 +1130,8 @@ private async Task ValidateCodeActionAsync( codeActionToRun, requestContext, languageServer, - codeActionResolversCreator?.Invoke(roslynCodeActionHelpers, formattingService, optionsMonitor) ?? []); + optionsMonitor, + codeActionResolversCreator?.Invoke(roslynCodeActionHelpers, formattingService) ?? []); var edits = new List(); foreach (var change in changes) @@ -1205,6 +1205,7 @@ internal async Task GetEditsAsync( VSInternalCodeAction codeActionToRun, RazorRequestContext requestContext, IClientConnection clientConnection, + RazorLSPOptionsMonitor? optionsMonitor, IRazorCodeActionResolver[] razorResolvers) { var formattingService = await TestRazorFormattingService.CreateWithFullSupportAsync(LoggerFactory); @@ -1217,7 +1218,8 @@ internal async Task GetEditsAsync( var htmlResolvers = Array.Empty(); - 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); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs index f2757cfd589..1dfeb8359e3 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs @@ -8,6 +8,7 @@ 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 async Task Handle_Valid_RazorCodeAction_WithResolver() razorCodeActionResolvers: [new MockRazorCodeActionResolver("Test")], csharpCodeActionResolvers: [], htmlCodeActionResolvers: [], + TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -61,6 +63,7 @@ public async Task Handle_Valid_CSharpCodeAction_WithResolver() razorCodeActionResolvers: [], [new MockCSharpCodeActionResolver("Test")], htmlCodeActionResolvers: [], + TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -91,6 +94,7 @@ public async Task Handle_Valid_CSharpCodeAction_WithMultipleLanguageResolvers() razorCodeActionResolvers: [new MockRazorCodeActionResolver("TestRazor")], csharpCodeActionResolvers: [new MockCSharpCodeActionResolver("TestCSharp")], htmlCodeActionResolvers: [], + TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -121,6 +125,7 @@ public async Task Handle_Valid_RazorCodeAction_WithoutResolver() razorCodeActionResolvers: [], csharpCodeActionResolvers: [], htmlCodeActionResolvers: [], + TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -160,6 +165,7 @@ public async Task Handle_Valid_CSharpCodeAction_WithoutResolver() razorCodeActionResolvers: [], csharpCodeActionResolvers: [], htmlCodeActionResolvers: [], + TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -195,6 +201,7 @@ public async Task Handle_Valid_RazorCodeAction_WithCSharpResolver_ResolvesNull() razorCodeActionResolvers: [], csharpCodeActionResolvers: [new MockCSharpCodeActionResolver("Test")], htmlCodeActionResolvers: [], + TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -234,6 +241,7 @@ public async Task Handle_Valid_CSharpCodeAction_WithRazorResolver_ResolvesNull() razorCodeActionResolvers: [new MockRazorCodeActionResolver("Test")], csharpCodeActionResolvers: [], htmlCodeActionResolvers: [], + TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -272,6 +280,7 @@ public async Task ResolveRazorCodeAction_ResolveMultipleRazorProviders_FirstMatc ], csharpCodeActionResolvers: [], htmlCodeActionResolvers: [], + TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -286,7 +295,7 @@ public async Task ResolveRazorCodeAction_ResolveMultipleRazorProviders_FirstMatc }; // 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 async Task ResolveRazorCodeAction_ResolveMultipleRazorProviders_SecondMat ], csharpCodeActionResolvers: [], htmlCodeActionResolvers: [], + TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -318,7 +328,7 @@ public async Task ResolveRazorCodeAction_ResolveMultipleRazorProviders_SecondMat }; // 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 async Task ResolveCSharpCodeAction_ResolveMultipleCSharpProviders_FirstMa new MockCSharpNullCodeActionResolver("B"), ], htmlCodeActionResolvers: [], + TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -364,6 +375,7 @@ public async Task ResolveCSharpCodeAction_ResolveMultipleCSharpProviders_SecondM new MockCSharpCodeActionResolver("B"), ], htmlCodeActionResolvers: [], + TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -395,6 +407,7 @@ public async Task ResolveCSharpCodeAction_ResolveMultipleLanguageProviders() new MockCSharpCodeActionResolver("D"), ], htmlCodeActionResolvers: [], + TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -420,6 +433,7 @@ public async Task Handle_ResolveEditBasedCodeActionCommand() razorCodeActionResolvers: [], csharpCodeActionResolvers: [new MockCSharpCodeActionResolver("Test")], htmlCodeActionResolvers: [], + TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var requestParams = new RazorCodeActionResolutionParams() { @@ -452,7 +466,7 @@ internal MockRazorCodeActionResolver(string action) Action = action; } - public Task ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken) + public Task ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken) { return Task.FromResult(new WorkspaceEdit()); } @@ -467,7 +481,7 @@ internal MockRazorNullCodeActionResolver(string action) Action = action; } - public Task ResolveAsync(DocumentContext documentContext, JsonElement data, CancellationToken cancellationToken) + public Task ResolveAsync(DocumentContext documentContext, JsonElement data, RazorFormattingOptions options, CancellationToken cancellationToken) { return SpecializedTasks.Null(); } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/CreateComponentCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/CreateComponentCodeActionResolverTest.cs index 7052915a379..a31fe7e31e0 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/CreateComponentCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/CreateComponentCodeActionResolverTest.cs @@ -10,6 +10,7 @@ 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 async Task Handle_Unsupported() }); // 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 async Task Handle_InvalidFileKind() }); // 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 async Task Handle_CreateComponent() 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 @@ @namespace Another.Namespace 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); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionResolverTest.cs index 1b1af10b233..246e82d1ad2 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionResolverTest.cs @@ -12,6 +12,7 @@ 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 async Task Handle_Unsupported() 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 async Task Handle_InvalidFileKind() 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 async Task Handle_ExtractCodeBlock() 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 async Task Handle_ExtractCodeBlock2() 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 @@ private void M() 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 @@ private void M() 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 @@ private void M() 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 async Task Handle_ExtractFunctionsBlock() 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 @@ @using System.Diagnostics 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 async Task Handle_ExtractCodeBlockWithDirectives() 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 async Task Handle_ExtractCodeBlock_CallsRoslyn() 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); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionResolverTest.NetFx.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionResolverTest.NetFx.cs index b59ce1d296e..5d4ae0b7b63 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionResolverTest.NetFx.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionResolverTest.NetFx.cs @@ -303,6 +303,7 @@ private async Task TestAsync( codeActionToRun, requestContext, languageServer, + optionsMonitor: null, [resolver] ); From 0f8af989134c869fd772451445c07c31af41ab9a Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 24 Oct 2024 14:32:07 +1100 Subject: [PATCH 07/15] Move helper method --- .../Html/DefaultHtmlCodeActionProvider.cs | 3 ++- .../Formatting/HtmlFormatter.cs | 18 --------------- .../WrapWithTag/WrapWithTagEndpoint.cs | 3 ++- .../Formatting/FormattingUtilities.cs | 22 ++++++++++++++++++- .../WrapWithTag/WrapWithTagEndpointTests.cs | 10 ++++----- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionProvider.cs index 6468b503881..eaa2e85277d 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionProvider.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; @@ -55,7 +56,7 @@ public static async Task RemapAndFixHtmlCodeActionEditAsync(IEditMappingService foreach (var edit in documentEdits) { - edit.Edits = HtmlFormatter.FixHtmlTextEdits(htmlSourceText, edit.Edits); + edit.Edits = FormattingUtilities.FixHtmlTextEdits(htmlSourceText, edit.Edits); } codeAction.Edit = new WorkspaceEdit diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormatter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormatter.cs index d2504d8e1ef..16dcfbc0446 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormatter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormatter.cs @@ -81,22 +81,4 @@ public async Task> GetOnTypeFormattingEditsAsync( var sourceText = await documentSnapshot.GetTextAsync(cancellationToken).ConfigureAwait(false); return result.Edits.SelectAsArray(sourceText.GetTextChange); } - - /// - /// Sometimes the Html language server will send back an edit that contains a tilde, because the generated - /// document we send them has lots of tildes. In those cases, we need to do some extra work to compute the - /// minimal text edits - /// - // Internal for testing - public static TextEdit[] FixHtmlTextEdits(SourceText htmlSourceText, TextEdit[] edits) - { - // Avoid computing a minimal diff if we don't need to - if (!edits.Any(static e => e.NewText.Contains("~"))) - return edits; - - var changes = edits.SelectAsArray(htmlSourceText.GetTextChange); - - var fixedChanges = htmlSourceText.MinimizeTextChanges(changes); - return [.. fixedChanges.Select(htmlSourceText.GetTextEdit)]; - } } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/WrapWithTag/WrapWithTagEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/WrapWithTag/WrapWithTagEndpoint.cs index 67359999a29..2b2df489b6b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/WrapWithTag/WrapWithTagEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/WrapWithTag/WrapWithTagEndpoint.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Text; @@ -122,7 +123,7 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(WrapWithTagParams reques if (htmlResponse.TextEdits is not null) { var htmlSourceText = await documentContext.GetHtmlSourceTextAsync(cancellationToken).ConfigureAwait(false); - htmlResponse.TextEdits = HtmlFormatter.FixHtmlTextEdits(htmlSourceText, htmlResponse.TextEdits); + htmlResponse.TextEdits = FormattingUtilities.FixHtmlTextEdits(htmlSourceText, htmlResponse.TextEdits); } return htmlResponse; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingUtilities.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingUtilities.cs index 99c81c15cc6..fb2315899e2 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingUtilities.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingUtilities.cs @@ -2,11 +2,13 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Collections.Immutable; +using System.Linq; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.CodeAnalysis.Text; -using Roslyn.LanguageServer.Protocol; +using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.Razor.Formatting; @@ -260,4 +262,22 @@ static bool IsWhitespace(char c) return builder.DrainToImmutable(); } } + + /// + /// Sometimes the Html language server will send back an edit that contains a tilde, because the generated + /// document we send them has lots of tildes. In those cases, we need to do some extra work to compute the + /// minimal text edits + /// + // Internal for testing + public static TextEdit[] FixHtmlTextEdits(SourceText htmlSourceText, TextEdit[] edits) + { + // Avoid computing a minimal diff if we don't need to + if (!edits.Any(static e => e.NewText.Contains("~"))) + return edits; + + var changes = edits.SelectAsArray(htmlSourceText.GetTextChange); + + var fixedChanges = htmlSourceText.MinimizeTextChanges(changes); + return [.. fixedChanges.Select(htmlSourceText.GetTextEdit)]; + } } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/WrapWithTag/WrapWithTagEndpointTests.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/WrapWithTag/WrapWithTagEndpointTests.cs index 53072c32790..ce85b88177c 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/WrapWithTag/WrapWithTagEndpointTests.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/WrapWithTag/WrapWithTagEndpointTests.cs @@ -3,13 +3,11 @@ using System; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; @@ -302,7 +300,7 @@ public async Task CleanUpTextEdits_NoTilde() }; var htmlSourceText = await context.GetHtmlSourceTextAsync(DisposalToken); - var edits = HtmlFormatter.FixHtmlTextEdits(htmlSourceText, computedEdits); + var edits = FormattingUtilities.FixHtmlTextEdits(htmlSourceText, computedEdits); Assert.Same(computedEdits, edits); var finalText = inputSourceText.WithChanges(edits.Select(inputSourceText.GetTextChange)); @@ -342,7 +340,7 @@ public async Task CleanUpTextEdits_BadEditWithTilde() }; var htmlSourceText = await context.GetHtmlSourceTextAsync(DisposalToken); - var edits = HtmlFormatter.FixHtmlTextEdits(htmlSourceText, computedEdits); + var edits = FormattingUtilities.FixHtmlTextEdits(htmlSourceText, computedEdits); Assert.NotSame(computedEdits, edits); var finalText = inputSourceText.WithChanges(edits.Select(inputSourceText.GetTextChange)); @@ -382,7 +380,7 @@ public async Task CleanUpTextEdits_GoodEditWithTilde() }; var htmlSourceText = await context.GetHtmlSourceTextAsync(DisposalToken); - var edits = HtmlFormatter.FixHtmlTextEdits(htmlSourceText, computedEdits); + var edits = FormattingUtilities.FixHtmlTextEdits(htmlSourceText, computedEdits); Assert.NotSame(computedEdits, edits); var finalText = inputSourceText.WithChanges(edits.Select(inputSourceText.GetTextChange)); From 5e1609848a05054ed843f33c4d0112fde2b7e9cc Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 24 Oct 2024 14:45:17 +1100 Subject: [PATCH 08/15] Remove unused usings --- .../CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs | 1 - .../CodeActions/CSharp/ICSharpCodeActionResolver.cs | 1 - .../CodeActions/CodeActionEndpoint.cs | 1 - .../CodeActions/CodeActionResolveEndpoint.cs | 1 - .../CodeActions/DelegatedCodeActionResolver.cs | 1 - .../CodeActions/Html/DefaultHtmlCodeActionProvider.cs | 1 - .../CodeActions/Html/DefaultHtmlCodeActionResolver.cs | 1 - .../CodeActions/Html/IHtmlCodeActionResolver.cs | 1 - .../CodeActions/Models/CodeActionExtensions.cs | 1 - .../CodeActions/Razor/CodeBlockService.cs | 2 -- .../Razor/ExtractToCodeBehindCodeActionProvider.cs | 1 - .../Razor/ExtractToCodeBehindCodeActionResolver.cs | 3 --- .../Razor/ExtractToComponentCodeActionProvider.cs | 6 ------ .../CodeActions/Razor/GenerateMethodCodeActionProvider.cs | 1 - .../CodeActions/Razor/GenerateMethodCodeActionResolver.cs | 2 -- .../CodeActions/Razor/IRazorCodeActionProvider.cs | 1 - .../CodeActions/RazorCodeActionContext.cs | 1 - 17 files changed, 26 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs index c20bfb95d98..3230a2e2a37 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/ICSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/ICSharpCodeActionResolver.cs index f0eb20ba237..ba19663122f 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/ICSharpCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/ICSharpCodeActionResolver.cs @@ -3,7 +3,6 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs index d0cea599a40..4369d06beb8 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs @@ -17,7 +17,6 @@ using Microsoft.AspNetCore.Razor.Threading; using Microsoft.CodeAnalysis.ExternalAccess.Razor; using Microsoft.CodeAnalysis.Razor.DocumentMapping; -using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs index 83ae35cd3c2..ad7303a6f0c 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs @@ -16,7 +16,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; -using Microsoft.VisualStudio.Composition; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionResolver.cs index bc1e5331368..611f26781d1 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionResolver.cs @@ -4,7 +4,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; -using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionProvider.cs index eaa2e85277d..65dbde547ab 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionProvider.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; -using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.Formatting; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionResolver.cs index 69d679f7d99..0954944cfc3 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionResolver.cs @@ -3,7 +3,6 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/IHtmlCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/IHtmlCodeActionResolver.cs index 92c86f6119c..8a4807e8c18 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/IHtmlCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/IHtmlCodeActionResolver.cs @@ -3,7 +3,6 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/CodeActionExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/CodeActionExtensions.cs index 2da1169f8dc..1628431489c 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/CodeActionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/CodeActionExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using System; using System.Linq; using System.Text.Json; using System.Text.Json.Nodes; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs index f4cff29e71b..6a2d637869c 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs @@ -5,8 +5,6 @@ using System.Linq; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Formatting; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs index e2bb9d285e3..9d9054c659f 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs index 245d2042aee..6d0b512c5ab 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs @@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Intermediate; using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis; @@ -18,8 +17,6 @@ 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; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs index 9257cefdbf0..f7eceef38af 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs @@ -1,23 +1,17 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; -using ICSharpCode.Decompiler.CSharp.Syntax; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Syntax; using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; -using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Threading; using Microsoft.CodeAnalysis.Razor; -using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; -using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionProvider.cs index 7773a9ac27a..2a68d220419 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionProvider.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; -using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Syntax; using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.Threading; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs index 9e96d2a71b6..92dad7c0741 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs @@ -12,11 +12,9 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Differencing; using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.Formatting; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRazorCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRazorCodeActionProvider.cs index 76f118fa86a..034f31dfff6 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRazorCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRazorCodeActionProvider.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using System.Collections.Generic; using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RazorCodeActionContext.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RazorCodeActionContext.cs index 2040629f1c8..1926b0ad7aa 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RazorCodeActionContext.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RazorCodeActionContext.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using System; using Microsoft.AspNetCore.Razor.Language; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; From 6d7d0ab113207d22cbc652792ec2a4d67d333de4 Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 24 Oct 2024 14:52:41 +1100 Subject: [PATCH 09/15] Move files around --- .../CodeActions/{Razor => }/RoslynCodeActionHelpers.cs | 0 .../CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs | 0 .../CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs | 0 .../CodeActions/CSharp/ICSharpCodeActionProvider.cs | 0 .../CodeActions/CSharp/ICSharpCodeActionResolver.cs | 0 .../CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs | 0 .../CSharp/UnformattedRemappingCSharpCodeActionResolver.cs | 0 .../CodeActions/Html/DefaultHtmlCodeActionProvider.cs | 0 .../CodeActions/Html/DefaultHtmlCodeActionResolver.cs | 0 .../CodeActions/Html/IHtmlCodeActionProvider.cs | 0 .../CodeActions/Html/IHtmlCodeActionResolver.cs | 0 .../CodeActions/ICodeActionProvider.cs | 0 .../CodeActions/ICodeActionResolver.cs | 0 .../CodeActions/IDelegatedCodeActionResolver.cs | 0 .../CodeActions/IDelegatedCodeActionsProvider.cs | 0 .../CodeActions/Models/AddUsingsCodeActionParams.cs | 0 .../CodeActions/Models/CodeActionExtensions.cs | 0 .../CodeActions/Models/CreateComponentCodeActionParams.cs | 0 .../CodeActions/Models/ExtractToCodeBehindCodeActionParams.cs | 0 .../CodeActions/Models/ExtractToComponentCodeActionParams.cs | 0 .../CodeActions/Models/GenerateMethodCodeActionParams.cs | 0 .../CodeActions/Models/RazorCodeActionResolutionParams.cs | 0 .../CodeActions/Models/RazorVSInternalCodeAction.cs | 0 .../CodeActions/Razor/AddUsingsCodeActionResolver.cs | 0 .../CodeActions/Razor/CodeBlockService.cs | 0 .../CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs | 0 .../CodeActions/Razor/CreateComponentCodeActionResolver.cs | 0 .../CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs | 0 .../CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs | 0 .../CodeActions/Razor/ExtractToComponentCodeActionProvider.cs | 0 .../CodeActions/Razor/ExtractToComponentCodeActionResolver.cs | 0 .../CodeActions/Razor/GenerateMethodCodeActionProvider.cs | 0 .../CodeActions/Razor/GenerateMethodCodeActionResolver.cs | 0 .../CodeActions/Razor/IRazorCodeActionProvider.cs | 0 .../CodeActions/Razor/IRazorCodeActionResolver.cs | 0 .../CodeActions/Razor/IRoslynCodeActionHelpers.cs | 0 .../CodeActions/Razor/RazorCodeActionFactory.cs | 0 .../CodeActions/RazorCodeActionContext.cs | 0 38 files changed, 0 insertions(+), 0 deletions(-) rename src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/{Razor => }/RoslynCodeActionHelpers.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/CSharp/ICSharpCodeActionProvider.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/CSharp/ICSharpCodeActionResolver.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Html/DefaultHtmlCodeActionProvider.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Html/DefaultHtmlCodeActionResolver.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Html/IHtmlCodeActionProvider.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Html/IHtmlCodeActionResolver.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/ICodeActionProvider.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/ICodeActionResolver.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/IDelegatedCodeActionResolver.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/IDelegatedCodeActionsProvider.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Models/AddUsingsCodeActionParams.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Models/CodeActionExtensions.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Models/CreateComponentCodeActionParams.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Models/ExtractToCodeBehindCodeActionParams.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Models/ExtractToComponentCodeActionParams.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Models/GenerateMethodCodeActionParams.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Models/RazorCodeActionResolutionParams.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Models/RazorVSInternalCodeAction.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/AddUsingsCodeActionResolver.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/CodeBlockService.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/CreateComponentCodeActionResolver.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/GenerateMethodCodeActionProvider.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/GenerateMethodCodeActionResolver.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/IRazorCodeActionProvider.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/IRazorCodeActionResolver.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/IRoslynCodeActionHelpers.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/Razor/RazorCodeActionFactory.cs (100%) rename src/Razor/src/{Microsoft.AspNetCore.Razor.LanguageServer => Microsoft.CodeAnalysis.Razor.Workspaces}/CodeActions/RazorCodeActionContext.cs (100%) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/RoslynCodeActionHelpers.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RoslynCodeActionHelpers.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/RoslynCodeActionHelpers.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RoslynCodeActionHelpers.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/ICSharpCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/ICSharpCodeActionProvider.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/ICSharpCodeActionProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/ICSharpCodeActionProvider.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/ICSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/ICSharpCodeActionResolver.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/ICSharpCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/ICSharpCodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionProvider.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionProvider.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionResolver.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/DefaultHtmlCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/IHtmlCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/IHtmlCodeActionProvider.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/IHtmlCodeActionProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/IHtmlCodeActionProvider.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/IHtmlCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/IHtmlCodeActionResolver.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Html/IHtmlCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/IHtmlCodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/ICodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionProvider.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/ICodeActionProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionProvider.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/ICodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionResolver.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/ICodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IDelegatedCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/IDelegatedCodeActionResolver.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IDelegatedCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/IDelegatedCodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IDelegatedCodeActionsProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/IDelegatedCodeActionsProvider.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IDelegatedCodeActionsProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/IDelegatedCodeActionsProvider.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/AddUsingsCodeActionParams.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/AddUsingsCodeActionParams.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/AddUsingsCodeActionParams.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/AddUsingsCodeActionParams.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/CodeActionExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/CodeActionExtensions.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/CodeActionExtensions.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/CodeActionExtensions.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/CreateComponentCodeActionParams.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/CreateComponentCodeActionParams.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/CreateComponentCodeActionParams.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/CreateComponentCodeActionParams.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/ExtractToCodeBehindCodeActionParams.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/ExtractToCodeBehindCodeActionParams.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/ExtractToCodeBehindCodeActionParams.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/ExtractToCodeBehindCodeActionParams.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/ExtractToComponentCodeActionParams.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/ExtractToComponentCodeActionParams.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/ExtractToComponentCodeActionParams.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/ExtractToComponentCodeActionParams.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/GenerateMethodCodeActionParams.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/GenerateMethodCodeActionParams.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/GenerateMethodCodeActionParams.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/GenerateMethodCodeActionParams.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/RazorCodeActionResolutionParams.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/RazorCodeActionResolutionParams.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/RazorCodeActionResolutionParams.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/RazorCodeActionResolutionParams.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/RazorVSInternalCodeAction.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/RazorVSInternalCodeAction.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/RazorVSInternalCodeAction.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/RazorVSInternalCodeAction.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/AddUsingsCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/AddUsingsCodeActionResolver.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/AddUsingsCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/AddUsingsCodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CodeBlockService.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CodeBlockService.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CodeBlockService.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CreateComponentCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CreateComponentCodeActionResolver.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CreateComponentCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CreateComponentCodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/GenerateMethodCodeActionProvider.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/GenerateMethodCodeActionProvider.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/GenerateMethodCodeActionResolver.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/GenerateMethodCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/GenerateMethodCodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRazorCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRazorCodeActionProvider.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRazorCodeActionProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRazorCodeActionProvider.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRazorCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRazorCodeActionResolver.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRazorCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRazorCodeActionResolver.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRoslynCodeActionHelpers.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRoslynCodeActionHelpers.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/IRoslynCodeActionHelpers.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRoslynCodeActionHelpers.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/RazorCodeActionFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RazorCodeActionFactory.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/RazorCodeActionFactory.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RazorCodeActionFactory.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RazorCodeActionContext.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/RazorCodeActionContext.cs similarity index 100% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RazorCodeActionContext.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/RazorCodeActionContext.cs From ab55c388e2408927be3942833187a19e3ff0f4ad Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 24 Oct 2024 15:12:32 +1100 Subject: [PATCH 10/15] Move string resources --- .../Resources/SR.resx | 15 ----------- .../Resources/xlf/SR.cs.xlf | 25 ------------------- .../Resources/xlf/SR.de.xlf | 25 ------------------- .../Resources/xlf/SR.es.xlf | 25 ------------------- .../Resources/xlf/SR.fr.xlf | 25 ------------------- .../Resources/xlf/SR.it.xlf | 25 ------------------- .../Resources/xlf/SR.ja.xlf | 25 ------------------- .../Resources/xlf/SR.ko.xlf | 25 ------------------- .../Resources/xlf/SR.pl.xlf | 25 ------------------- .../Resources/xlf/SR.pt-BR.xlf | 25 ------------------- .../Resources/xlf/SR.ru.xlf | 25 ------------------- .../Resources/xlf/SR.tr.xlf | 25 ------------------- .../Resources/xlf/SR.zh-Hans.xlf | 25 ------------------- .../Resources/xlf/SR.zh-Hant.xlf | 25 ------------------- .../Resources/SR.resx | 15 +++++++++++ .../Resources/xlf/SR.cs.xlf | 25 +++++++++++++++++++ .../Resources/xlf/SR.de.xlf | 25 +++++++++++++++++++ .../Resources/xlf/SR.es.xlf | 25 +++++++++++++++++++ .../Resources/xlf/SR.fr.xlf | 25 +++++++++++++++++++ .../Resources/xlf/SR.it.xlf | 25 +++++++++++++++++++ .../Resources/xlf/SR.ja.xlf | 25 +++++++++++++++++++ .../Resources/xlf/SR.ko.xlf | 25 +++++++++++++++++++ .../Resources/xlf/SR.pl.xlf | 25 +++++++++++++++++++ .../Resources/xlf/SR.pt-BR.xlf | 25 +++++++++++++++++++ .../Resources/xlf/SR.ru.xlf | 25 +++++++++++++++++++ .../Resources/xlf/SR.tr.xlf | 25 +++++++++++++++++++ .../Resources/xlf/SR.zh-Hans.xlf | 25 +++++++++++++++++++ .../Resources/xlf/SR.zh-Hant.xlf | 25 +++++++++++++++++++ ...nentAccessibilityCodeActionProviderTest.cs | 14 +++++------ 29 files changed, 347 insertions(+), 347 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/SR.resx b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/SR.resx index f652571c68b..8d81b01ff12 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/SR.resx +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/SR.resx @@ -123,24 +123,12 @@ Changes: - - Create component from tag - Document {0} was not found. - - Extract block to code behind - File was externally modified: {0} - - Generate Async Event Handler '{0}' - - - Generate Event Handler '{0}' - "Re-trigger completions..." @@ -153,7 +141,4 @@ statement - - Extract element to new component - \ No newline at end of file diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.cs.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.cs.xlf index 50a3db2584a..eeba363efa3 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.cs.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.cs.xlf @@ -12,41 +12,16 @@ Změny: - - Create component from tag - Vytvořit komponentu ze značky - - Document {0} was not found. Dokument {0} nebyl nalezen. - - Extract block to code behind - Extrahovat blok do kódu na pozadí - - - - Extract element to new component - Extrahovat element do nové komponenty - - File was externally modified: {0} Došlo k externí úpravě souboru: {0} - - Generate Async Event Handler '{0}' - Generovat asynchronní obslužnou rutinu události {0} - - - - Generate Event Handler '{0}' - Generovat obslužnou rutinu události {0} - - "Re-trigger completions..." Aktivovat znovu dokončení… diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.de.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.de.xlf index 82383d256ab..82833f9ad63 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.de.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.de.xlf @@ -12,41 +12,16 @@ Änderungen: - - Create component from tag - Komponente aus Tag erstellen - - Document {0} was not found. Dokument „{0}“ wurde nicht gefunden. - - Extract block to code behind - Block auf CodeBehind extrahieren - - - - Extract element to new component - Element in neue Komponente extrahieren - - File was externally modified: {0} Datei wurde extern modifiziert: {0}. - - Generate Async Event Handler '{0}' - Asynchronen Ereignishandler "{0}" generieren - - - - Generate Event Handler '{0}' - Ereignishandler "{0}" generieren - - "Re-trigger completions..." "Abschlüsse erneut auslösen..." diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.es.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.es.xlf index ef0adbcc20d..53a119cdd71 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.es.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.es.xlf @@ -12,41 +12,16 @@ Cambios: - - Create component from tag - Crear un componente a partir de la etiqueta - - Document {0} was not found. No se encontró el documento {0}. - - Extract block to code behind - Extraer el bloque al código subyacente - - - - Extract element to new component - Extraer elemento a componente nuevo - - File was externally modified: {0} El archivo se modificó externamente: {0} - - Generate Async Event Handler '{0}' - Generar controlador de eventos asincrónicos ''{0}'' - - - - Generate Event Handler '{0}' - Generar controlador de eventos ''{0}'' - - "Re-trigger completions..." "Volver a desencadenar las finalizaciones..." diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.fr.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.fr.xlf index faefba378b1..c80298226e1 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.fr.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.fr.xlf @@ -12,41 +12,16 @@ Modifications : - - Create component from tag - Créer un composant à partir de la balise - - Document {0} was not found. Le document {0} est introuvable. - - Extract block to code behind - Extraire le bloc vers le code-behind - - - - Extract element to new component - Extraire l’élément vers un nouveau composant - - File was externally modified: {0} Le fichier a été modifié en externe : {0} - - Generate Async Event Handler '{0}' - Générer le gestionnaire d’événements asynchrone « {0} » - - - - Generate Event Handler '{0}' - Générer le gestionnaire d’événements '{0}' - - "Re-trigger completions..." « Déclencher à nouveau les complétions... » diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.it.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.it.xlf index 03349a73eec..779482b3f74 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.it.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.it.xlf @@ -12,41 +12,16 @@ Modifiche: - - Create component from tag - Crea componente da tag - - Document {0} was not found. Impossibile trovare il documento{0}. - - Extract block to code behind - Estrai il blocco in code-behind - - - - Extract element to new component - Estrarre elemento nel nuovo componente - - File was externally modified: {0} Il file è stato modificato esternamente: {0} - - Generate Async Event Handler '{0}' - Genera gestore dell'evento '{0}' asincrono - - - - Generate Event Handler '{0}' - Genera gestore dell'evento '{0}' - - "Re-trigger completions..." "Riattiva i completamenti..." diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ja.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ja.xlf index 81b2eb97913..e4b6fd84472 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ja.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ja.xlf @@ -12,41 +12,16 @@ 変更: - - Create component from tag - タグからコンポーネントを作成する - - Document {0} was not found. ドキュメント {0}が見つかりませんでした。 - - Extract block to code behind - ブロック抽出から分離コード - - - - Extract element to new component - 要素を新しいコンポーネントに抽出する - - File was externally modified: {0} ファイルが外部で変更されました: {0} - - Generate Async Event Handler '{0}' - 非同期イベント ハンドラー '{0}' の生成 - - - - Generate Event Handler '{0}' - イベント ハンドラー '{0}' の生成 - - "Re-trigger completions..." "再トリガーの完了..." diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ko.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ko.xlf index e7f265e494f..78d84e15ac0 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ko.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ko.xlf @@ -12,41 +12,16 @@ 변경 내용: - - Create component from tag - 태그에서 구성 요소 만들기 - - Document {0} was not found. 문서 {0}을(를) 찾을 수 없습니다. - - Extract block to code behind - 코드 숨김에 블록 추출 - - - - Extract element to new component - 새 구성 요소에 요소 추출 - - File was externally modified: {0} {0}의 파일이 외부에서 수정되었습니다. - - Generate Async Event Handler '{0}' - 비동기 이벤트 처리기 '{0}' 생성 - - - - Generate Event Handler '{0}' - 이벤트 처리기 '{0}' 생성 - - "Re-trigger completions..." "완료된 항목 다시 트리거" diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pl.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pl.xlf index ce76233da57..6005e177fbe 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pl.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pl.xlf @@ -12,41 +12,16 @@ Zmiany: - - Create component from tag - Utwórz składnik z tagu - - Document {0} was not found. Nie znaleziono {0} dokumentu. - - Extract block to code behind - Wyodrębnij blok do kodu znajdującego się poza - - - - Extract element to new component - Wyodrębnij element do nowego składnika - - File was externally modified: {0} Plik został zmodyfikowany na zewnątrz: {0} - - Generate Async Event Handler '{0}' - Generuj asynchroniczny program obsługi zdarzeń „{0}” - - - - Generate Event Handler '{0}' - Generuj obsługę zdarzeń „{0}” - - "Re-trigger completions..." "Ponownie wyzwalaj uzupełniania..." diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pt-BR.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pt-BR.xlf index 46d39dc3345..40310d8a76b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pt-BR.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pt-BR.xlf @@ -12,41 +12,16 @@ Alterações: - - Create component from tag - Criar componente a partir da marca - - Document {0} was not found. O documento {0} não foi encontrado. - - Extract block to code behind - Extrair o bloco para codificar atrás - - - - Extract element to new component - Extrair elemento para o novo componente - - File was externally modified: {0} O arquivo foi modificado externamente: {0} - - Generate Async Event Handler '{0}' - Gerar Manipulador de Eventos Assíncronos '{0}' - - - - Generate Event Handler '{0}' - Gerar manipulador de eventos '{0}' - - "Re-trigger completions..." "Disparar conclusões novamente..." diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ru.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ru.xlf index 25c67fe9d08..b70366d41f1 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ru.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ru.xlf @@ -12,41 +12,16 @@ Изменения: - - Create component from tag - Создание компонента из тега - - Document {0} was not found. Документ {0} не найден. - - Extract block to code behind - Извлечь блок в код программной части - - - - Extract element to new component - Извлечь элемент в новый компонент - - File was externally modified: {0} Файл был изменен извне: {0} - - Generate Async Event Handler '{0}' - Создать обработчик асинхронных событий "{0}" - - - - Generate Event Handler '{0}' - Создать обработчик событий "{0}" - - "Re-trigger completions..." "Повторный запуск завершений..." diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.tr.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.tr.xlf index 09ede15c645..45da9f4fe04 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.tr.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.tr.xlf @@ -12,41 +12,16 @@ Değişiklikler: - - Create component from tag - Etiketten bileşen oluştur - - Document {0} was not found. Belge {0} bulunamadı. - - Extract block to code behind - Bloğu arkadaki koda ayıkla - - - - Extract element to new component - Öğeyi yeni bileşene ayıklayın - - File was externally modified: {0} Dosya dışarıdan değiştirildi: {0} - - Generate Async Event Handler '{0}' - '{0}' Asenkron Olay İşleyicisini Oluştur - - - - Generate Event Handler '{0}' - '{0}' Olay İşleyicisi Oluştur - - "Re-trigger completions..." "Tamamlamaları yeniden tetikleyin..." diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hans.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hans.xlf index dcf087f5dc4..a4aed030c76 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hans.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hans.xlf @@ -12,41 +12,16 @@ 更改: - - Create component from tag - 从标记创建组件 - - Document {0} was not found. 找不到文档 {0}。 - - Extract block to code behind - 将块提取到代码隐藏中 - - - - Extract element to new component - 将元素提取到新组件 - - File was externally modified: {0} 已从外部修改了文件: {0}。 - - Generate Async Event Handler '{0}' - 生成异步事件处理程序“{0}” - - - - Generate Event Handler '{0}' - 生成事件处理程序 "{0}" - - "Re-trigger completions..." “重新触发完成…” diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hant.xlf b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hant.xlf index e79025401e8..64b5e1dff29 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hant.xlf +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hant.xlf @@ -12,41 +12,16 @@ 變更: - - Create component from tag - 從標籤建立元件 - - Document {0} was not found. 找不到文件 {0}。 - - Extract block to code behind - 擷取區塊以在後方編碼 - - - - Extract element to new component - 將元素擷取至新元件 - - File was externally modified: {0} 已在外部修改檔案: {0} - - Generate Async Event Handler '{0}' - 產生非同步事件處理常式 '{0}' - - - - Generate Event Handler '{0}' - 產生事件處理常式 '{0}' - - "Re-trigger completions..." "重新觸發完成..." diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/SR.resx b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/SR.resx index e0a0efc1cdd..fabffe08501 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/SR.resx +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/SR.resx @@ -172,4 +172,19 @@ Razor TagHelper Element Glyph + + Create component from tag + + + Extract block to code behind + + + Extract element to new component + + + Generate Async Event Handler '{0}' + + + Generate Event Handler '{0}' + \ No newline at end of file diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.cs.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.cs.xlf index 31f86168480..1a785ad2458 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.cs.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.cs.xlf @@ -7,6 +7,11 @@ Hodnota nesmí být null ani prázdný řetězec. + + Create component from tag + Create component from tag + + Diagnostics after: Diagnostika po: @@ -39,6 +44,16 @@ Úprava na {0} odstraní neprázdný obsah {1}. + + Extract block to code behind + Extract block to code behind + + + + Extract element to new component + Extract element to new component + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. Operace formátování je ukončována, protože by zavedla nebo odebrala jednu z více diagnostik. @@ -49,6 +64,16 @@ Operace formátování je ukončována, protože by přidala nebo odstranila neprázdný obsah. + + Generate Async Event Handler '{0}' + Generate Async Event Handler '{0}' + + + + Generate Event Handler '{0}' + Generate Event Handler '{0}' + + Invalid offset. Neplatný posun diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.de.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.de.xlf index 1726a2f73d0..3f8cd5c10e4 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.de.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.de.xlf @@ -7,6 +7,11 @@ Der Wert darf nicht NULL oder eine leere Zeichenfolge sein. + + Create component from tag + Create component from tag + + Diagnostics after: Diagnose nach: @@ -39,6 +44,16 @@ Das Bearbeiten bei {0} löscht den Nicht-Leerraum-Inhalt "{1}". + + Extract block to code behind + Extract block to code behind + + + + Extract element to new component + Extract element to new component + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. Ein Formatierungsvorgang wird abgebrochen, weil er eine oder mehrere Diagnosen einführen oder entfernen würde. @@ -49,6 +64,16 @@ Ein Formatierungsvorgang wird abgebrochen, da er Nicht-Leerraum-Inhalte hinzufügen oder löschen würde. + + Generate Async Event Handler '{0}' + Generate Async Event Handler '{0}' + + + + Generate Event Handler '{0}' + Generate Event Handler '{0}' + + Invalid offset. Ungültiger Offset. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.es.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.es.xlf index af8cec0ae9d..d2d1471e192 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.es.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.es.xlf @@ -7,6 +7,11 @@ El valor no puede ser nulo ni una cadena vacía. + + Create component from tag + Create component from tag + + Diagnostics after: Diagnósticos después de: @@ -39,6 +44,16 @@ Editar en {0} eliminar el contenido que no es un espacio en blanco "{1}" . + + Extract block to code behind + Extract block to code behind + + + + Extract element to new component + Extract element to new component + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. Se está abandonando una operación de formato porque introduciría o quitaría uno de más diagnósticos. @@ -49,6 +64,16 @@ Se está abandonando una operación de formato porque agregaría o eliminaría contenido que no es un espacio en blanco. + + Generate Async Event Handler '{0}' + Generate Async Event Handler '{0}' + + + + Generate Event Handler '{0}' + Generate Event Handler '{0}' + + Invalid offset. Desplazamiento no válido. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.fr.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.fr.xlf index 83af245e366..b5921857f2d 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.fr.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.fr.xlf @@ -7,6 +7,11 @@ La valeur ne peut pas être Null ni être une chaîne vide. + + Create component from tag + Create component from tag + + Diagnostics after: Diagnostics après : @@ -39,6 +44,16 @@ Modifier à {0} supprime le contenu autre qu’un espace « {1} ». + + Extract block to code behind + Extract block to code behind + + + + Extract element to new component + Extract element to new component + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. Une opération de formatage est en cours d’abandon, car elle introduit ou supprime un ou plusieurs diagnostics. @@ -49,6 +64,16 @@ Une opération de formatage est en cours d’abandon, car elle ajouterait ou supprimerait du contenu qui n’est pas un espace blanc. + + Generate Async Event Handler '{0}' + Generate Async Event Handler '{0}' + + + + Generate Event Handler '{0}' + Generate Event Handler '{0}' + + Invalid offset. Décalage non valide. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.it.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.it.xlf index 5317948e62d..5ba05125e8b 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.it.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.it.xlf @@ -7,6 +7,11 @@ Il valore non può essere null o una stringa vuota. + + Create component from tag + Create component from tag + + Diagnostics after: Diagnostica dopo: @@ -39,6 +44,16 @@ La modifica in {0} elimina contenuti diversi da spazi vuoti '{1}'. + + Extract block to code behind + Extract block to code behind + + + + Extract element to new component + Extract element to new component + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. È in corso l'abbandono di un'operazione di formato perché comporterebbe l'introduzione o la rimozione di una o più operazioni di diagnostica. @@ -49,6 +64,16 @@ È in corso l'abbandono di un'operazione di formattazione perché aggiungerebbe o eliminerebbe contenuto diverso da spazi vuoti. + + Generate Async Event Handler '{0}' + Generate Async Event Handler '{0}' + + + + Generate Event Handler '{0}' + Generate Event Handler '{0}' + + Invalid offset. Offset non valido. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ja.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ja.xlf index 55bbf78dcd9..4e3ae6ccef1 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ja.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ja.xlf @@ -7,6 +7,11 @@ 値を null または空の文字列にすることはできません。 + + Create component from tag + Create component from tag + + Diagnostics after: 次の時間が経過した後の診断: @@ -39,6 +44,16 @@ {0} で削除すると空白以外のスペース '{1}' が追加されます。 + + Extract block to code behind + Extract block to code behind + + + + Extract element to new component + Extract element to new component + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. 書式設定操作は、さらに診断の 1 つを導入または削除するため、破棄されています。 @@ -49,6 +64,16 @@ 書式設定操作は、空白以外のコンテンツを追加または削除するため、破棄されています。 + + Generate Async Event Handler '{0}' + Generate Async Event Handler '{0}' + + + + Generate Event Handler '{0}' + Generate Event Handler '{0}' + + Invalid offset. 無効なオフセットです。 diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ko.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ko.xlf index 2931b15ec1e..bb4ebfe7e22 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ko.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ko.xlf @@ -7,6 +7,11 @@ 값은 null이거나 빈 문자열일 수 없습니다. + + Create component from tag + Create component from tag + + Diagnostics after: 다음 이후 진단: @@ -39,6 +44,16 @@ {0}에서 편집은 공백이 아닌 콘텐츠 '{1}'을(를) 삭제합니다. + + Extract block to code behind + Extract block to code behind + + + + Extract element to new component + Extract element to new component + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. 서식 작업이 중단되는 이유는 진단 중 하나를 더 도입하거나 제거할 수 있기 때문입니다. @@ -49,6 +64,16 @@ 공백이 아닌 콘텐츠를 추가하거나 삭제하기 때문에 형식 작업이 중단됩니다. + + Generate Async Event Handler '{0}' + Generate Async Event Handler '{0}' + + + + Generate Event Handler '{0}' + Generate Event Handler '{0}' + + Invalid offset. 오프셋이 유효하지 않습니다. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pl.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pl.xlf index 60f05b66521..4483b647eef 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pl.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pl.xlf @@ -7,6 +7,11 @@ Wartość nie może być wartością null ani pustym ciągiem. + + Create component from tag + Create component from tag + + Diagnostics after: Diagnostyka po: @@ -39,6 +44,16 @@ Edycja na stronie {0} usuwa zawartość bez białych znaków „{1}”. + + Extract block to code behind + Extract block to code behind + + + + Extract element to new component + Extract element to new component + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. Operacja formatowania jest porzucana, ponieważ spowodowałaby wprowadzenie lub usunięcie jednej z większej liczby diagnostyki. @@ -49,6 +64,16 @@ Operacja formatowania jest porzucana, ponieważ doda lub usunie zawartość bez białych znaków. + + Generate Async Event Handler '{0}' + Generate Async Event Handler '{0}' + + + + Generate Event Handler '{0}' + Generate Event Handler '{0}' + + Invalid offset. Nieprawidłowe przesunięcie. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pt-BR.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pt-BR.xlf index e834585d7ed..844983e712f 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pt-BR.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pt-BR.xlf @@ -7,6 +7,11 @@ O valor não pode ser nulo ou uma cadeia de caracteres vazia. + + Create component from tag + Create component from tag + + Diagnostics after: Diagnóstico após: @@ -39,6 +44,16 @@ Editar em {0} exclui o conteúdo que não é espaço em branco ''{1}''. + + Extract block to code behind + Extract block to code behind + + + + Extract element to new component + Extract element to new component + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. Uma operação de formato está sendo abandonada porque introduziria ou removeria um ou mais diagnósticos. @@ -49,6 +64,16 @@ Uma operação de formato está sendo abandonada porque adicionaria ou excluiria conteúdo que não é espaço em branco. + + Generate Async Event Handler '{0}' + Generate Async Event Handler '{0}' + + + + Generate Event Handler '{0}' + Generate Event Handler '{0}' + + Invalid offset. Deslocamento inválido. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ru.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ru.xlf index b4577c8ec99..6a7bc8759ad 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ru.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ru.xlf @@ -7,6 +7,11 @@ Значение не может быть NULL или пустой строкой. + + Create component from tag + Create component from tag + + Diagnostics after: Диагностика после: @@ -39,6 +44,16 @@ Редактирование {0} удаляет содержимое, не являющееся пробелами "{1}". + + Extract block to code behind + Extract block to code behind + + + + Extract element to new component + Extract element to new component + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. Операция форматирования отменяется, поскольку она вводит или удаляет одну или несколько диагностик. @@ -49,6 +64,16 @@ Операция форматирования отменяется, поскольку она может добавить или удалить содержимое, отличное от пробелов. + + Generate Async Event Handler '{0}' + Generate Async Event Handler '{0}' + + + + Generate Event Handler '{0}' + Generate Event Handler '{0}' + + Invalid offset. Недопустимое смещение. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.tr.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.tr.xlf index 0faa1367043..55a39ce6657 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.tr.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.tr.xlf @@ -7,6 +7,11 @@ Değer null veya boş bir dize olamaz. + + Create component from tag + Create component from tag + + Diagnostics after: Şundan sonraki tanılama: @@ -39,6 +44,16 @@ {0} konumunda düzenleme, '{1}' boşluk dışı içeriğini siler. + + Extract block to code behind + Extract block to code behind + + + + Extract element to new component + Extract element to new component + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. Bir veya daha fazla tanılamayı ortaya çıkarabileceği veya kaldırabileceği için biçimlendirme işlemi bırakılıyor. @@ -49,6 +64,16 @@ Boşluk dışı içeriği ekleyebileceği veya silebileceği için biçimlendirme işlemi bırakıl. + + Generate Async Event Handler '{0}' + Generate Async Event Handler '{0}' + + + + Generate Event Handler '{0}' + Generate Event Handler '{0}' + + Invalid offset. Geçersiz uzaklık. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hans.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hans.xlf index 51764818206..1881033599b 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hans.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hans.xlf @@ -7,6 +7,11 @@ 值不能为 null 或空字符串。 + + Create component from tag + Create component from tag + + Diagnostics after: 诊断后: @@ -39,6 +44,16 @@ 于 {0} 编辑,删除非空格内容“{1}”。 + + Extract block to code behind + Extract block to code behind + + + + Extract element to new component + Extract element to new component + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. 正在放弃格式操作,因为它会引入或删除其他诊断之一。 @@ -49,6 +64,16 @@ 正在放弃格式操作,因为它会添加或删除非空格内容。 + + Generate Async Event Handler '{0}' + Generate Async Event Handler '{0}' + + + + Generate Event Handler '{0}' + Generate Event Handler '{0}' + + Invalid offset. 偏移无效。 diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hant.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hant.xlf index 74d00b2d74b..fa8c0f7b398 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hant.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hant.xlf @@ -7,6 +7,11 @@ 值不能為 Null 或空字串。 + + Create component from tag + Create component from tag + + Diagnostics after: 在以下事項之後的診斷: @@ -39,6 +44,16 @@ 在 {0} 處編輯將刪除非空白內容 '{1}'。 + + Extract block to code behind + Extract block to code behind + + + + Extract element to new component + Extract element to new component + + A format operation is being abandoned because it would introduce or remove one of more diagnostics. 將放棄格式化作業,因為它將引入或移除一個或多個診斷。 @@ -49,6 +64,16 @@ 將放棄格式化作業,因為它將新增或删除非空白內容。 + + Generate Async Event Handler '{0}' + Generate Async Event Handler '{0}' + + + + Generate Event Handler '{0}' + Generate Event Handler '{0}' + + Invalid offset. 位移無效。 diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs index 404bc2cb4d8..9e25a59b518 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs @@ -16,7 +16,7 @@ using Moq; using Xunit; using Xunit.Abstractions; -using LanguageServerSR = Microsoft.AspNetCore.Razor.LanguageServer.Resources.SR; +using WorkspacesSR = Microsoft.CodeAnalysis.Razor.Workspaces.Resources.SR; namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; @@ -148,7 +148,7 @@ public async Task Handle_ExistingComponent_SupportsFileCreationTrue_ReturnsResul }, e => { - Assert.Equal(LanguageServerSR.Create_Component_FromTag_Title, e.Title); + Assert.Equal(WorkspacesSR.Create_Component_FromTag_Title, e.Title); Assert.NotNull(e.Data); Assert.Null(e.Edit); }); @@ -195,7 +195,7 @@ public async Task Handle_ExistingComponent_CaseIncorrect_ReturnsResults() }, e => { - Assert.Equal(LanguageServerSR.Create_Component_FromTag_Title, e.Title); + Assert.Equal(WorkspacesSR.Create_Component_FromTag_Title, e.Title); Assert.NotNull(e.Data); Assert.Null(e.Edit); }); @@ -238,7 +238,7 @@ @using Fully.Qualified }, e => { - Assert.Equal(LanguageServerSR.Create_Component_FromTag_Title, e.Title); + Assert.Equal(WorkspacesSR.Create_Component_FromTag_Title, e.Title); Assert.NotNull(e.Data); Assert.Null(e.Edit); }); @@ -285,7 +285,7 @@ public async Task Handle_ExistingGenericComponent_SupportsFileCreationTrue_Retur }, e => { - Assert.Equal(LanguageServerSR.Create_Component_FromTag_Title, e.Title); + Assert.Equal(WorkspacesSR.Create_Component_FromTag_Title, e.Title); Assert.NotNull(e.Data); Assert.Null(e.Edit); }); @@ -317,7 +317,7 @@ public async Task Handle_NewComponent_SupportsFileCreationTrue_ReturnsResult() // Assert var command = Assert.Single(commandOrCodeActionContainer); - Assert.Equal(LanguageServerSR.Create_Component_FromTag_Title, command.Title); + Assert.Equal(WorkspacesSR.Create_Component_FromTag_Title, command.Title); Assert.NotNull(command.Data); } @@ -347,7 +347,7 @@ public async Task Handle_NewComponent_CaretInAttribute_ReturnsResult() // Assert var command = Assert.Single(commandOrCodeActionContainer); - Assert.Equal(LanguageServerSR.Create_Component_FromTag_Title, command.Title); + Assert.Equal(WorkspacesSR.Create_Component_FromTag_Title, command.Title); Assert.NotNull(command.Data); } From ab201926a85bec850f176ef5349353c2c9a85c63 Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 24 Oct 2024 16:36:56 +1100 Subject: [PATCH 11/15] Fix all namespace and using directives Should be no changes in this commit other than those two syntax constructs --- .../LanguageServer/RazorCodeActionsBenchmark.cs | 1 + .../CodeActions/CodeActionEndpoint.cs | 3 ++- .../CodeActions/CodeActionResolveEndpoint.cs | 3 ++- .../CodeActions/DelegatedCodeActionResolver.cs | 1 + .../CodeActions/DelegatedCodeActionsProvider.cs | 7 ++----- .../CodeActions/RoslynCodeActionHelpers.cs | 1 + .../Extensions/IServiceCollectionExtensions.cs | 3 ++- .../CSharp/DefaultCSharpCodeActionProvider.cs | 5 ++--- .../CSharp/DefaultCSharpCodeActionResolver.cs | 3 +-- .../CSharp/ICSharpCodeActionProvider.cs | 2 +- .../CSharp/ICSharpCodeActionResolver.cs | 2 +- .../CSharp/TypeAccessibilityCodeActionProvider.cs | 15 ++++++++++----- ...nformattedRemappingCSharpCodeActionResolver.cs | 3 +-- .../Html/DefaultHtmlCodeActionProvider.cs | 4 ++-- .../Html/DefaultHtmlCodeActionResolver.cs | 2 +- .../CodeActions/Html/IHtmlCodeActionProvider.cs | 2 +- .../CodeActions/Html/IHtmlCodeActionResolver.cs | 2 +- .../CodeActions/ICodeActionProvider.cs | 5 ++--- .../CodeActions/ICodeActionResolver.cs | 2 +- .../CodeActions/IDelegatedCodeActionResolver.cs | 2 +- .../CodeActions/IDelegatedCodeActionsProvider.cs | 4 ++-- .../Models/AddUsingsCodeActionParams.cs | 2 +- .../CodeActions/Models/CodeActionExtensions.cs | 3 ++- .../Models/CreateComponentCodeActionParams.cs | 2 +- .../Models/ExtractToCodeBehindCodeActionParams.cs | 2 +- .../Models/ExtractToComponentCodeActionParams.cs | 2 +- .../Models/GenerateMethodCodeActionParams.cs | 2 +- .../Models/RazorCodeActionResolutionParams.cs | 2 +- .../Models/RazorVSInternalCodeAction.cs | 2 +- .../Razor/AddUsingsCodeActionResolver.cs | 4 ++-- .../CodeActions/Razor/CodeBlockService.cs | 3 +-- .../ComponentAccessibilityCodeActionProvider.cs | 10 ++++++---- .../Razor/CreateComponentCodeActionResolver.cs | 5 +++-- .../ExtractToCodeBehindCodeActionProvider.cs | 8 ++++---- .../ExtractToCodeBehindCodeActionResolver.cs | 7 +++---- .../Razor/ExtractToComponentCodeActionProvider.cs | 7 ++++--- .../Razor/ExtractToComponentCodeActionResolver.cs | 7 ++++--- .../Razor/GenerateMethodCodeActionProvider.cs | 8 +++++--- .../Razor/GenerateMethodCodeActionResolver.cs | 5 ++--- .../CodeActions/Razor/IRazorCodeActionProvider.cs | 4 ++-- .../CodeActions/Razor/IRazorCodeActionResolver.cs | 2 +- .../CodeActions/Razor/IRoslynCodeActionHelpers.cs | 2 +- .../CodeActions/Razor/RazorCodeActionFactory.cs | 4 ++-- .../CodeActions/RazorCodeActionContext.cs | 2 +- .../AddUsingsCodeActionResolverTest.cs | 3 ++- .../CSharp/DefaultCSharpCodeActionProviderTest.cs | 3 ++- .../CSharp/DefaultCSharpCodeActionResolverTest.cs | 1 + .../TypeAccessibilityCodeActionProviderTest.cs | 3 ++- .../CodeActions/CodeActionEndToEndTest.NetFx.cs | 5 +++-- .../CodeActions/CodeActionEndpointTest.cs | 3 ++- .../CodeActionResolutionEndpointTest.cs | 3 ++- .../Html/DefaultHtmlCodeActionProviderTest.cs | 3 ++- .../Html/DefaultHtmlCodeActionResolverTest.cs | 3 ++- ...omponentAccessibilityCodeActionProviderTest.cs | 1 + .../CreateComponentCodeActionResolverTest.cs | 3 ++- .../ExtractToCodeBehindCodeActionProviderTest.cs | 3 ++- .../ExtractToCodeBehindCodeActionResolverTest.cs | 3 ++- .../ExtractToComponentCodeActionProviderTest.cs | 6 +++--- ...ractToComponentCodeActionResolverTest.NetFx.cs | 2 +- ...legatingEndpointTestBase.TestLanguageServer.cs | 2 +- 60 files changed, 118 insertions(+), 96 deletions(-) diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs index 1a499ac2233..c948cc412b7 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs @@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Telemetry; +using Microsoft.CodeAnalysis.Razor.CodeActions; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs index 4369d06beb8..e69621f7a45 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs @@ -10,12 +10,13 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Telemetry; using Microsoft.AspNetCore.Razor.Threading; using Microsoft.CodeAnalysis.ExternalAccess.Razor; +using Microsoft.CodeAnalysis.Razor.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs index ad7303a6f0c..0a8f414b5cd 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs @@ -9,9 +9,10 @@ using System.Text.Json; using System.Threading; 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.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionResolver.cs index 611f26781d1..37b453c0dee 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionResolver.cs @@ -4,6 +4,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.CodeAnalysis.Razor.CodeActions; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionsProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionsProvider.cs index 0aca4935161..ce02a2982cf 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionsProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/DelegatedCodeActionsProvider.cs @@ -2,18 +2,15 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Telemetry; +using Microsoft.CodeAnalysis.Razor.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; -using Microsoft.VisualStudio.RpcContracts; using StreamJsonRpc; namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RoslynCodeActionHelpers.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RoslynCodeActionHelpers.cs index e5e691ef83e..0da843edba0 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RoslynCodeActionHelpers.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RoslynCodeActionHelpers.cs @@ -5,6 +5,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; +using Microsoft.CodeAnalysis.Razor.CodeActions; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs index b8b484434db..e158d34b6f9 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; using Microsoft.AspNetCore.Razor.LanguageServer.Common; using Microsoft.AspNetCore.Razor.LanguageServer.Completion; using Microsoft.AspNetCore.Razor.LanguageServer.Completion.Delegation; @@ -20,6 +19,8 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Semantic; using Microsoft.AspNetCore.Razor.LanguageServer.SpellCheck; using Microsoft.AspNetCore.Razor.ProjectEngineHost; +using Microsoft.CodeAnalysis.Razor.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Razor; using Microsoft.CodeAnalysis.Razor.Completion; using Microsoft.CodeAnalysis.Razor.Diagnostics; using Microsoft.CodeAnalysis.Razor.DocumentMapping; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs index 9c4c239a4cf..6c71c730de8 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; @@ -10,13 +9,13 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Threading; using Microsoft.CodeAnalysis.ExternalAccess.Razor; using Microsoft.CodeAnalysis.Razor.Workspaces; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal sealed class DefaultCSharpCodeActionProvider(LanguageServerFeatureOptions languageServerFeatureOptions) : ICSharpCodeActionProvider { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs index 3230a2e2a37..c53682f87f9 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -11,7 +10,7 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal sealed class DefaultCSharpCodeActionResolver( IDelegatedCodeActionResolver delegatedCodeActionResolver, diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/ICSharpCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/ICSharpCodeActionProvider.cs index f06c05eef43..98ab617d932 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/ICSharpCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/ICSharpCodeActionProvider.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal interface ICSharpCodeActionProvider : ICodeActionProvider { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/ICSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/ICSharpCodeActionResolver.cs index ba19663122f..36d4ae4a03a 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/ICSharpCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/ICSharpCodeActionResolver.cs @@ -6,7 +6,7 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal interface ICSharpCodeActionResolver : ICodeActionResolver { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs index 3130c5e749a..1b192552084 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs @@ -11,16 +11,21 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Razor; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Threading; using Microsoft.CodeAnalysis.ExternalAccess.Razor; using Microsoft.CodeAnalysis.Razor.Formatting; +using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; +using LspDiagnostic = Microsoft.VisualStudio.LanguageServer.Protocol.Diagnostic; +using LspDiagnosticSeverity = Microsoft.VisualStudio.LanguageServer.Protocol.DiagnosticSeverity; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; + +using SyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode; internal sealed class TypeAccessibilityCodeActionProvider : ICSharpCodeActionProvider { @@ -67,7 +72,7 @@ private static ImmutableArray ProcessCodeActionsVSCod ImmutableArray codeActions) { var diagnostics = context.Request.Context.Diagnostics.Where(diagnostic => - diagnostic is { Severity: DiagnosticSeverity.Error, Code: { } code } && + diagnostic is { Severity: LspDiagnosticSeverity.Error, Code: { } code } && code.TryGetSecond(out var str) && s_supportedDiagnostics.Any(d => str.Equals(d, StringComparison.OrdinalIgnoreCase))); @@ -256,7 +261,7 @@ static bool IsSingleLineDirectiveNode(SyntaxNode owner) private static RazorVSInternalCodeAction CreateFQNCodeAction( RazorCodeActionContext context, - Diagnostic fqnDiagnostic, + LspDiagnostic fqnDiagnostic, RazorVSInternalCodeAction nonFQNCodeAction, string fullyQualifiedName) { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs index 0fde73bb426..c87710518bd 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using System; using System.Diagnostics; using System.Linq; using System.Threading; @@ -12,7 +11,7 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; /// /// Resolves and remaps the code action, without running formatting passes. diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionProvider.cs index 65dbde547ab..28c1ed3af29 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionProvider.cs @@ -5,7 +5,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.Formatting; @@ -13,7 +13,7 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal sealed class DefaultHtmlCodeActionProvider(IEditMappingService editMappingService) : IHtmlCodeActionProvider { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionResolver.cs index 0954944cfc3..bc5e3c8834a 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionResolver.cs @@ -8,7 +8,7 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal sealed class DefaultHtmlCodeActionResolver( IDelegatedCodeActionResolver delegatedCodeActionResolver, diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/IHtmlCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/IHtmlCodeActionProvider.cs index 0c6296d3d1b..8404d6de4bd 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/IHtmlCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/IHtmlCodeActionProvider.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal interface IHtmlCodeActionProvider : ICodeActionProvider { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/IHtmlCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/IHtmlCodeActionResolver.cs index 8a4807e8c18..e6ed1800723 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/IHtmlCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/IHtmlCodeActionResolver.cs @@ -6,7 +6,7 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal interface IHtmlCodeActionResolver : ICodeActionResolver { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionProvider.cs index 593b99b4a09..8c68a6b2183 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionProvider.cs @@ -1,13 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using System.Collections.Generic; using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal interface ICodeActionProvider { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionResolver.cs index 5c5d1b17067..99a0253a9ea 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionResolver.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal interface ICodeActionResolver { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/IDelegatedCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/IDelegatedCodeActionResolver.cs index 04c033f570d..62a8fcd3c27 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/IDelegatedCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/IDelegatedCodeActionResolver.cs @@ -6,7 +6,7 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal interface IDelegatedCodeActionResolver { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/IDelegatedCodeActionsProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/IDelegatedCodeActionsProvider.cs index b7061c43cec..8e10c980990 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/IDelegatedCodeActionsProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/IDelegatedCodeActionsProvider.cs @@ -4,11 +4,11 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal interface IDelegatedCodeActionsProvider { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/AddUsingsCodeActionParams.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/AddUsingsCodeActionParams.cs index 85859ba9fc0..df5b4e5d055 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/AddUsingsCodeActionParams.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/AddUsingsCodeActionParams.cs @@ -4,7 +4,7 @@ using System.Text.Json.Serialization; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Models; internal sealed class AddUsingsCodeActionParams { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/CodeActionExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/CodeActionExtensions.cs index 1628431489c..3661d10f485 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/CodeActionExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/CodeActionExtensions.cs @@ -4,10 +4,11 @@ using System.Linq; using System.Text.Json; using System.Text.Json.Nodes; +using Microsoft.AspNetCore.Razor; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Models; internal static class CodeActionExtensions { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/CreateComponentCodeActionParams.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/CreateComponentCodeActionParams.cs index 13ac1990ad4..b4f4479f409 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/CreateComponentCodeActionParams.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/CreateComponentCodeActionParams.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Models; internal sealed class CreateComponentCodeActionParams { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/ExtractToCodeBehindCodeActionParams.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/ExtractToCodeBehindCodeActionParams.cs index c2ba34075ab..fb6779d96a9 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/ExtractToCodeBehindCodeActionParams.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/ExtractToCodeBehindCodeActionParams.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Models; internal sealed class ExtractToCodeBehindCodeActionParams { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/ExtractToComponentCodeActionParams.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/ExtractToComponentCodeActionParams.cs index e87fd19404b..c476cae310e 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/ExtractToComponentCodeActionParams.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/ExtractToComponentCodeActionParams.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Models; internal sealed class ExtractToComponentCodeActionParams { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/GenerateMethodCodeActionParams.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/GenerateMethodCodeActionParams.cs index 2416cf869d7..002e048714a 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/GenerateMethodCodeActionParams.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/GenerateMethodCodeActionParams.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Models; internal sealed class GenerateMethodCodeActionParams { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/RazorCodeActionResolutionParams.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/RazorCodeActionResolutionParams.cs index 39344f0fed0..5fa246b822f 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/RazorCodeActionResolutionParams.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/RazorCodeActionResolutionParams.cs @@ -5,7 +5,7 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Models; internal sealed class RazorCodeActionResolutionParams { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/RazorVSInternalCodeAction.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/RazorVSInternalCodeAction.cs index dc53eff8e46..844be0bd0a6 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/RazorVSInternalCodeAction.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Models/RazorVSInternalCodeAction.cs @@ -5,7 +5,7 @@ using System.Text.Json.Serialization; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Models; [DataContract] internal sealed class RazorVSInternalCodeAction : VSInternalCodeAction diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/AddUsingsCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/AddUsingsCodeActionResolver.cs index c8c1cdc4305..d5f7b7c335d 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/AddUsingsCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/AddUsingsCodeActionResolver.cs @@ -7,13 +7,13 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal sealed class AddUsingsCodeActionResolver : IRazorCodeActionResolver { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CodeBlockService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CodeBlockService.cs index 6a2d637869c..a68c3e0d896 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CodeBlockService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CodeBlockService.cs @@ -6,12 +6,11 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Syntax; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Razor; internal static class CodeBlockService { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs index bbeacbcacf2..28a44f8d41e 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ComponentAccessibilityCodeActionProvider.cs @@ -8,20 +8,22 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Utilities; -using Microsoft.CodeAnalysis.Razor; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Razor; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.VisualStudio.Editor.Razor; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; + +using SyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode; internal sealed class ComponentAccessibilityCodeActionProvider : IRazorCodeActionProvider { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CreateComponentCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CreateComponentCodeActionResolver.cs index 5b9d9072842..f04b2cf4e82 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CreateComponentCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CreateComponentCodeActionResolver.cs @@ -10,14 +10,15 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal sealed class CreateComponentCodeActionResolver(LanguageServerFeatureOptions languageServerFeatureOptions) : IRazorCodeActionResolver { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs index 9d9054c659f..54730e8cabd 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs @@ -11,14 +11,14 @@ using Microsoft.AspNetCore.Razor.Language.Components; using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Razor; using Microsoft.AspNetCore.Razor.Threading; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal sealed class ExtractToCodeBehindCodeActionProvider(ILoggerFactory loggerFactory) : IRazorCodeActionProvider { @@ -127,6 +127,6 @@ private static bool TryGetNamespace(RazorCodeDocument codeDocument, [NotNullWhen // good namespace to extract to => codeDocument.TryComputeNamespace(fallbackToRootNamespace: true, out @namespace); - private static bool HasUnsupportedChildren(Language.Syntax.SyntaxNode node) + private static bool HasUnsupportedChildren(RazorSyntaxNode node) => node.DescendantNodes().Any(n => n is MarkupBlockSyntax or CSharpTransitionSyntax or RazorCommentBlockSyntax); } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs index 6d0b512c5ab..25cc910e853 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs @@ -8,20 +8,19 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Intermediate; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Utilities; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Formatting; -using Microsoft.CodeAnalysis.Razor; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal sealed class ExtractToCodeBehindCodeActionResolver( LanguageServerFeatureOptions languageServerFeatureOptions, diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs index f7eceef38af..695e3a5f1fa 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs @@ -8,14 +8,15 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.Threading; -using Microsoft.CodeAnalysis.Razor; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Razor; + +using SyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode; internal sealed class ExtractToComponentCodeActionProvider() : IRazorCodeActionProvider { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs index 1cc26c623ef..9ffc571f000 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs @@ -6,18 +6,19 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Utilities; -using Microsoft.CodeAnalysis.Razor; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Razor; internal sealed class ExtractToComponentCodeActionResolver( LanguageServerFeatureOptions languageServerFeatureOptions) : IRazorCodeActionResolver diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/GenerateMethodCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/GenerateMethodCodeActionProvider.cs index 2a68d220419..bd421fabff6 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/GenerateMethodCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/GenerateMethodCodeActionProvider.cs @@ -7,16 +7,18 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.Threading; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using SyntaxFacts = Microsoft.CodeAnalysis.CSharp.SyntaxFacts; -using SyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Razor; + +using SyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode; internal sealed class GenerateMethodCodeActionProvider : IRazorCodeActionProvider { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/GenerateMethodCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/GenerateMethodCodeActionResolver.cs index 92dad7c0741..129d7fca5da 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/GenerateMethodCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/GenerateMethodCodeActionResolver.cs @@ -11,11 +11,10 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Razor; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; @@ -23,7 +22,7 @@ using Microsoft.VisualStudio.LanguageServer.Protocol; using CSharpSyntaxFactory = Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Razor; internal sealed class GenerateMethodCodeActionResolver( IRoslynCodeActionHelpers roslynCodeActionHelpers, diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRazorCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRazorCodeActionProvider.cs index 034f31dfff6..39724fcfffe 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRazorCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRazorCodeActionProvider.cs @@ -4,9 +4,9 @@ using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal interface IRazorCodeActionProvider { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRazorCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRazorCodeActionResolver.cs index 6999a43bbff..d9418b20570 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRazorCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRazorCodeActionResolver.cs @@ -8,7 +8,7 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal interface IRazorCodeActionResolver : ICodeActionResolver { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRoslynCodeActionHelpers.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRoslynCodeActionHelpers.cs index cc0f4d9d13c..9d57b459fe9 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRoslynCodeActionHelpers.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/IRoslynCodeActionHelpers.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal interface IRoslynCodeActionHelpers { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RazorCodeActionFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RazorCodeActionFactory.cs index b1b02a89607..c383b7734ed 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RazorCodeActionFactory.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/RazorCodeActionFactory.cs @@ -3,11 +3,11 @@ using System; using System.Text.Json; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; +namespace Microsoft.CodeAnalysis.Razor.CodeActions.Razor; internal static class RazorCodeActionFactory { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/RazorCodeActionContext.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/RazorCodeActionContext.cs index 1926b0ad7aa..053b54c51b8 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/RazorCodeActionContext.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/RazorCodeActionContext.cs @@ -6,7 +6,7 @@ using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; using Microsoft.CodeAnalysis.Text; -namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; +namespace Microsoft.CodeAnalysis.Razor.CodeActions; internal sealed record class RazorCodeActionContext( VSCodeActionParams Request, diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/AddUsingsCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/AddUsingsCodeActionResolverTest.cs index ac6e915e6b9..43f70862743 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/AddUsingsCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/AddUsingsCodeActionResolverTest.cs @@ -7,8 +7,9 @@ using System.Threading.Tasks; 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.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.VisualStudio.LanguageServer.Protocol; using Xunit; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs index eb79d65ae4f..ecf383b9de7 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs @@ -7,11 +7,12 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; +using Microsoft.CodeAnalysis.Razor.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; using Microsoft.CodeAnalysis.Testing; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs index f9f833fee39..19c09c6cfd7 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.CodeActions; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/TypeAccessibilityCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/TypeAccessibilityCodeActionProviderTest.cs index e438ceecafd..62a825f53cd 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/TypeAccessibilityCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/TypeAccessibilityCodeActionProviderTest.cs @@ -9,9 +9,10 @@ using Microsoft.AspNetCore.Mvc.Razor.Extensions; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs index 0a1fa4be88c..e17c4fa449c 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs @@ -10,8 +10,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; @@ -21,6 +19,9 @@ using Microsoft.AspNetCore.Razor.Utilities; using Microsoft.CodeAnalysis.ExternalAccess.Razor; using Microsoft.CodeAnalysis.Razor; +using Microsoft.CodeAnalysis.Razor.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Razor; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; using Microsoft.CodeAnalysis.Razor.Workspaces; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs index 85848b1f4ff..623187543a1 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs @@ -10,11 +10,12 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Telemetry; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs index 1dfeb8359e3..0d6c0754c93 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs @@ -5,9 +5,10 @@ using System.Text.Json; using System.Threading; 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.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs index 3e6e5c929ce..fa0f3fcbd95 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs @@ -7,9 +7,10 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionResolverTest.cs index beab8dc0f49..9c7a979f2b4 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionResolverTest.cs @@ -4,10 +4,11 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs index 9e25a59b518..ead2575f81f 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Razor.Language.Components; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.CodeActions; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; using Microsoft.CodeAnalysis.Testing; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/CreateComponentCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/CreateComponentCodeActionResolverTest.cs index a31fe7e31e0..af29121699b 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/CreateComponentCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/CreateComponentCodeActionResolverTest.cs @@ -6,10 +6,11 @@ using System.Text.Json; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -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.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.VisualStudio.LanguageServer.Protocol; using Xunit; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionProviderTest.cs index 2ab70100820..55249ff1040 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionProviderTest.cs @@ -10,9 +10,10 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; using Microsoft.AspNetCore.Razor.Language.Extensions; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; using Microsoft.CodeAnalysis.Testing; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionResolverTest.cs index 246e82d1ad2..10e2091be22 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionResolverTest.cs @@ -7,11 +7,12 @@ using System.Text.Json; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; 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.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Text; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionProviderTest.cs index 0fed08a4409..780c8970958 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionProviderTest.cs @@ -10,11 +10,11 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; using Microsoft.AspNetCore.Razor.Language.Extensions; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.CodeActions; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Razor; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; using Microsoft.CodeAnalysis.Testing; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionResolverTest.NetFx.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionResolverTest.NetFx.cs index 5d4ae0b7b63..5358dbc1ebf 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionResolverTest.NetFx.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionResolverTest.NetFx.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; using Microsoft.AspNetCore.Razor.ProjectSystem; @@ -16,6 +15,7 @@ using Microsoft.AspNetCore.Razor.Test.Common.ProjectSystem; using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Razor.CodeActions.Razor; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Testing; using Microsoft.VisualStudio.LanguageServer.Protocol; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SingleServerDelegatingEndpointTestBase.TestLanguageServer.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SingleServerDelegatingEndpointTestBase.TestLanguageServer.cs index 5561c00bb84..a62bd71e06f 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SingleServerDelegatingEndpointTestBase.TestLanguageServer.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SingleServerDelegatingEndpointTestBase.TestLanguageServer.cs @@ -6,9 +6,9 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; using Microsoft.CodeAnalysis.Razor.Protocol.Diagnostics; From cabeb822258a2071f531277a76f5b31183c4908d Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 24 Oct 2024 18:07:17 +1100 Subject: [PATCH 12/15] Extract code actions functionality to a service --- .../RazorCodeActionsBenchmark.cs | 10 +- .../CodeActions/CodeActionEndpoint.cs | 306 +---------------- .../IServiceCollectionExtensions.cs | 1 + .../CodeActions/CodeActionsService.cs | 313 ++++++++++++++++++ .../CodeActions/ICodeActionsService.cs | 16 + .../CodeActionEndToEndTest.NetFx.cs | 8 +- .../CodeActions/CodeActionEndpointTest.cs | 52 ++- 7 files changed, 384 insertions(+), 322 deletions(-) create mode 100644 src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CodeActionsService.cs create mode 100644 src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionsService.cs diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs index c948cc412b7..ca09dac4979 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.IO; using System.Text; using System.Threading; @@ -14,10 +13,8 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Telemetry; using Microsoft.CodeAnalysis.Razor.CodeActions; -using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; -using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; using Microsoft.CommonLanguageServerProtocol.Framework; using Microsoft.VisualStudio.LanguageServer.Protocol; @@ -50,12 +47,7 @@ public enum FileTypes public async Task SetupAsync() { CodeActionEndpoint = new CodeActionEndpoint( - documentMappingService: RazorLanguageServerHost.GetRequiredService(), - razorCodeActionProviders: RazorLanguageServerHost.GetRequiredService>(), - csharpCodeActionProviders: RazorLanguageServerHost.GetRequiredService>(), - htmlCodeActionProviders: RazorLanguageServerHost.GetRequiredService>(), - delegatedCodeActionsProvider: RazorLanguageServerHost.GetRequiredService(), - languageServerFeatureOptions: RazorLanguageServerHost.GetRequiredService(), + codeActionsService: RazorLanguageServerHost.GetRequiredService(), telemetryReporter: NoOpTelemetryReporter.Instance); var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp"); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs index e69621f7a45..2a2c86bcab2 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs @@ -2,118 +2,31 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using System.Reflection; -using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; -using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Telemetry; -using Microsoft.AspNetCore.Razor.Threading; -using Microsoft.CodeAnalysis.ExternalAccess.Razor; using Microsoft.CodeAnalysis.Razor.CodeActions; -using Microsoft.CodeAnalysis.Razor.CodeActions.Models; -using Microsoft.CodeAnalysis.Razor.DocumentMapping; -using Microsoft.CodeAnalysis.Razor.ProjectSystem; -using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; -using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; [RazorLanguageServerEndpoint(LspEndpointName)] internal sealed class CodeActionEndpoint( - IDocumentMappingService documentMappingService, - IEnumerable razorCodeActionProviders, - IEnumerable csharpCodeActionProviders, - IEnumerable htmlCodeActionProviders, - IDelegatedCodeActionsProvider delegatedCodeActionsProvider, - LanguageServerFeatureOptions languageServerFeatureOptions, + ICodeActionsService codeActionsService, ITelemetryReporter telemetryReporter) : IRazorRequestHandler[]?>, ICapabilitiesProvider { private const string LspEndpointName = Methods.TextDocumentCodeActionName; - private readonly IDocumentMappingService _documentMappingService = documentMappingService; - private readonly IEnumerable _razorCodeActionProviders = razorCodeActionProviders; - private readonly IEnumerable _csharpCodeActionProviders = csharpCodeActionProviders; - private readonly IEnumerable _htmlCodeActionProviders = htmlCodeActionProviders; - private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions; - private readonly IDelegatedCodeActionsProvider _delegatedCodeActionsProvider = delegatedCodeActionsProvider; + private readonly ICodeActionsService _codeActionsService = codeActionsService; private readonly ITelemetryReporter _telemetryReporter = telemetryReporter; internal bool _supportsCodeActionResolve = false; - private readonly ImmutableHashSet _allAvailableCodeActionNames = GetAllAvailableCodeActionNames(); - public bool MutatesSolutionState { get; } = false; - public async Task[]?> HandleRequestAsync(VSCodeActionParams request, RazorRequestContext requestContext, CancellationToken cancellationToken) - { - var documentContext = requestContext.DocumentContext; - if (documentContext is null) - { - return null; - } - - var razorCodeActionContext = await GenerateRazorCodeActionContextAsync(request, documentContext.Snapshot, cancellationToken).ConfigureAwait(false); - if (razorCodeActionContext is null) - { - return null; - } - - cancellationToken.ThrowIfCancellationRequested(); - - var correlationId = Guid.NewGuid(); - using var __ = _telemetryReporter.TrackLspRequest(LspEndpointName, LanguageServerConstants.RazorLanguageServerName, correlationId); - var razorCodeActions = await GetRazorCodeActionsAsync(razorCodeActionContext, cancellationToken).ConfigureAwait(false); - - cancellationToken.ThrowIfCancellationRequested(); - - var delegatedCodeActions = await GetDelegatedCodeActionsAsync(razorCodeActionContext, correlationId, cancellationToken).ConfigureAwait(false); - - cancellationToken.ThrowIfCancellationRequested(); - - using var commandsOrCodeActions = new PooledArrayBuilder>(); - - // Grouping the code actions causes VS to sort them into groups, rather than just alphabetically sorting them - // by title. The latter is bad for us because it can put "Remove
" at the top in some locales, and our fully - // qualify component code action at the bottom, depending on the users namespace. - ConvertCodeActionsToSumType(request.TextDocument, razorCodeActions, "A-Razor"); - ConvertCodeActionsToSumType(request.TextDocument, delegatedCodeActions, "B-Delegated"); - - return commandsOrCodeActions.ToArray(); - - void ConvertCodeActionsToSumType(VSTextDocumentIdentifier textDocument, ImmutableArray codeActions, string groupName) - { - // We must cast the RazorCodeAction into a platform compliant code action - // For VS (SupportsCodeActionResolve = true) this means just encapsulating the RazorCodeAction in the `CommandOrCodeAction` struct - // For VS Code (SupportsCodeActionResolve = false) we must convert it into a CodeAction or Command before encapsulating in the `CommandOrCodeAction` struct. - if (_supportsCodeActionResolve) - { - foreach (var action in codeActions) - { - // Make sure we honour the grouping that a delegated server may have created - action.Group = groupName + (action.Group ?? string.Empty); - commandsOrCodeActions.Add(action); - } - } - else - { - foreach (var action in codeActions) - { - commandsOrCodeActions.Add(action.AsVSCodeCommandOrCodeAction(textDocument)); - } - } - } - } - public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, VSInternalClientCapabilities clientCapabilities) { _supportsCodeActionResolve = clientCapabilities.TextDocument?.CodeAction?.ResolveSupport is not null; @@ -130,220 +43,23 @@ public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, V }; } - // internal for testing - internal async Task GenerateRazorCodeActionContextAsync( - VSCodeActionParams request, - IDocumentSnapshot documentSnapshot, - CancellationToken cancellationToken) - { - var codeDocument = await documentSnapshot.GetGeneratedOutputAsync(cancellationToken).ConfigureAwait(false); - if (codeDocument.IsUnsupported()) - { - return null; - } - - var sourceText = codeDocument.Source.Text; - - // VS Provides `CodeActionParams.Context.SelectionRange` in addition to - // `CodeActionParams.Range`. The `SelectionRange` is relative to where the - // code action was invoked (ex. line 14, char 3) whereas the `Range` is - // always at the start of the line (ex. line 14, char 0). We want to utilize - // the relative positioning to ensure we provide code actions for the appropriate - // context. - // - // Note: VS Code doesn't provide a `SelectionRange`. - var vsCodeActionContext = request.Context; - if (vsCodeActionContext.SelectionRange != null) - { - request.Range = vsCodeActionContext.SelectionRange; - } - - if (!sourceText.TryGetAbsoluteIndex(request.Range.Start, out var startLocation)) - { - return null; - } - - if (!sourceText.TryGetAbsoluteIndex(request.Range.End, out var endLocation)) - { - endLocation = startLocation; - } - - var context = new RazorCodeActionContext( - request, - documentSnapshot, - codeDocument, - startLocation, - endLocation, - sourceText, - _languageServerFeatureOptions.SupportsFileManipulation, - _supportsCodeActionResolve); - - return context; - } - - private async Task> GetDelegatedCodeActionsAsync(RazorCodeActionContext context, Guid correlationId, CancellationToken cancellationToken) - { - var languageKind = context.CodeDocument.GetLanguageKind(context.StartAbsoluteIndex, rightAssociative: false); - - // No point delegating if we're in a Razor context - if (languageKind == RazorLanguageKind.Razor) - { - return []; - } - - var codeActions = await GetCodeActionsFromLanguageServerAsync(languageKind, context, correlationId, cancellationToken).ConfigureAwait(false); - if (codeActions is not [_, ..]) - { - return []; - } - - IEnumerable providers; - if (languageKind == RazorLanguageKind.CSharp) - { - codeActions = ExtractCSharpCodeActionNamesFromData(codeActions); - providers = _csharpCodeActionProviders; - } - else - { - providers = _htmlCodeActionProviders; - } - - return await FilterCodeActionsAsync(context, codeActions.ToImmutableArray(), providers, cancellationToken).ConfigureAwait(false); - } - - private RazorVSInternalCodeAction[] ExtractCSharpCodeActionNamesFromData(RazorVSInternalCodeAction[] codeActions) - { - using var actions = new PooledArrayBuilder(); - - foreach (var codeAction in codeActions) - { - if (codeAction.Data is not JsonElement jsonData || - !jsonData.TryGetProperty("CustomTags", out var value) || - value.Deserialize() is not [..] tags) - { - continue; - } - - foreach (var tag in tags) - { - if (_allAvailableCodeActionNames.Contains(tag)) - { - codeAction.Name = tag; - break; - } - } - - if (string.IsNullOrEmpty(codeAction.Name)) - { - continue; - } - - actions.Add(codeAction); - } - - return actions.ToArray(); - } - - private static async Task> FilterCodeActionsAsync( - RazorCodeActionContext context, - ImmutableArray codeActions, - IEnumerable providers, - CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - - using var tasks = new PooledArrayBuilder>>(); - foreach (var provider in providers) - { - tasks.Add(provider.ProvideAsync(context, codeActions, cancellationToken)); - } - - return await ConsolidateCodeActionsFromProvidersAsync(tasks.ToImmutable(), cancellationToken).ConfigureAwait(false); - } - - // Internal for testing - internal Task GetCodeActionsFromLanguageServerAsync(RazorLanguageKind languageKind, RazorCodeActionContext context, Guid correlationId, CancellationToken cancellationToken) + public TextDocumentIdentifier GetTextDocumentIdentifier(VSCodeActionParams request) { - if (languageKind == RazorLanguageKind.CSharp) - { - // For C# we have to map the ranges to the generated document - if (!_documentMappingService.TryMapToGeneratedDocumentRange(context.CodeDocument.GetCSharpDocument(), context.Request.Range, out var projectedRange)) - { - return SpecializedTasks.EmptyArray(); - } - - var newContext = context.Request.Context; - if (context.Request.Context is VSInternalCodeActionContext { SelectionRange: not null } vsContext && - _documentMappingService.TryMapToGeneratedDocumentRange(context.CodeDocument.GetCSharpDocument(), vsContext.SelectionRange, out var selectionRange)) - { - vsContext.SelectionRange = selectionRange; - newContext = vsContext; - } - - context.Request.Range = projectedRange; - context.Request.Context = newContext; - } - - cancellationToken.ThrowIfCancellationRequested(); - return _delegatedCodeActionsProvider.GetDelegatedCodeActionsAsync(languageKind, context.Request, context.DocumentSnapshot.Version, correlationId, cancellationToken); + return request.TextDocument; } - private async Task> GetRazorCodeActionsAsync(RazorCodeActionContext context, CancellationToken cancellationToken) + public async Task[]?> HandleRequestAsync(VSCodeActionParams request, RazorRequestContext requestContext, CancellationToken cancellationToken) { - cancellationToken.ThrowIfCancellationRequested(); - - using var tasks = new PooledArrayBuilder>>(); - - foreach (var provider in _razorCodeActionProviders) + var documentContext = requestContext.DocumentContext; + if (documentContext is null) { - tasks.Add(provider.ProvideAsync(context, cancellationToken)); + return null; } - return await ConsolidateCodeActionsFromProvidersAsync(tasks.ToImmutable(), cancellationToken).ConfigureAwait(false); - } - - private static async Task> ConsolidateCodeActionsFromProvidersAsync( - ImmutableArray>> tasks, - CancellationToken cancellationToken) - { - var results = await Task.WhenAll(tasks).ConfigureAwait(false); - - using var codeActions = new PooledArrayBuilder(); - + var correlationId = Guid.NewGuid(); + using var __ = _telemetryReporter.TrackLspRequest(LspEndpointName, LanguageServerConstants.RazorLanguageServerName, correlationId); cancellationToken.ThrowIfCancellationRequested(); - foreach (var result in results) - { - codeActions.AddRange(result); - } - - return codeActions.ToImmutable(); - } - - private static ImmutableHashSet GetAllAvailableCodeActionNames() - { - using var _ = ArrayBuilderPool.GetPooledObject(out var availableCodeActionNames); - - var refactoringProviderNames = typeof(RazorPredefinedCodeRefactoringProviderNames) - .GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public) - .Where(property => property.PropertyType == typeof(string)) - .Select(property => property.GetValue(null) as string) - .WhereNotNull(); - var codeFixProviderNames = typeof(RazorPredefinedCodeFixProviderNames) - .GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public) - .Where(property => property.PropertyType == typeof(string)) - .Select(property => property.GetValue(null) as string) - .WhereNotNull(); - - availableCodeActionNames.AddRange(refactoringProviderNames); - availableCodeActionNames.AddRange(codeFixProviderNames); - availableCodeActionNames.Add(LanguageServerConstants.CodeActions.CodeActionFromVSCode); - - return availableCodeActionNames.ToImmutableHashSet(); - } - - public TextDocumentIdentifier GetTextDocumentIdentifier(VSCodeActionParams request) - { - return request.TextDocument; + return await _codeActionsService.GetCodeActionsAsync(request, documentContext, _supportsCodeActionResolve, correlationId, cancellationToken).ConfigureAwait(false); } } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs index e158d34b6f9..22b3d9208ee 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs @@ -138,6 +138,7 @@ public static void AddCodeActionsServices(this IServiceCollection services) services.AddHandlerWithCapabilities(); services.AddHandler(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CodeActionsService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CodeActionsService.cs new file mode 100644 index 00000000000..abdf1be5a17 --- /dev/null +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CodeActionsService.cs @@ -0,0 +1,313 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Reflection; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.PooledObjects; +using Microsoft.AspNetCore.Razor.Threading; +using Microsoft.CodeAnalysis.ExternalAccess.Razor; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.CodeAnalysis.Razor.Protocol; +using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; +using Microsoft.CodeAnalysis.Razor.Workspaces; +using Microsoft.VisualStudio.LanguageServer.Protocol; + +namespace Microsoft.CodeAnalysis.Razor.CodeActions; + +internal sealed class CodeActionsService( + IDocumentMappingService documentMappingService, + IEnumerable razorCodeActionProviders, + IEnumerable csharpCodeActionProviders, + IEnumerable htmlCodeActionProviders, + IDelegatedCodeActionsProvider delegatedCodeActionsProvider, + LanguageServerFeatureOptions languageServerFeatureOptions) : ICodeActionsService +{ + private static readonly ImmutableHashSet s_allAvailableCodeActionNames = GetAllAvailableCodeActionNames(); + + private readonly IDocumentMappingService _documentMappingService = documentMappingService; + private readonly IEnumerable _razorCodeActionProviders = razorCodeActionProviders; + private readonly IEnumerable _csharpCodeActionProviders = csharpCodeActionProviders; + private readonly IEnumerable _htmlCodeActionProviders = htmlCodeActionProviders; + private readonly IDelegatedCodeActionsProvider _delegatedCodeActionsProvider = delegatedCodeActionsProvider; + private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions; + + public async Task[]?> GetCodeActionsAsync(VSCodeActionParams request, DocumentContext documentContext, bool supportsCodeActionResolve, Guid correlationId, CancellationToken cancellationToken) + { + var razorCodeActionContext = await GenerateRazorCodeActionContextAsync(request, documentContext.Snapshot, supportsCodeActionResolve, cancellationToken).ConfigureAwait(false); + if (razorCodeActionContext is null) + { + return null; + } + + var razorCodeActions = await GetRazorCodeActionsAsync(razorCodeActionContext, cancellationToken).ConfigureAwait(false); + + cancellationToken.ThrowIfCancellationRequested(); + + var delegatedCodeActions = await GetDelegatedCodeActionsAsync(razorCodeActionContext, correlationId, cancellationToken).ConfigureAwait(false); + + cancellationToken.ThrowIfCancellationRequested(); + using var commandsOrCodeActions = new PooledArrayBuilder>(); + + // Grouping the code actions causes VS to sort them into groups, rather than just alphabetically sorting them + // by title. The latter is bad for us because it can put "Remove
" at the top in some locales, and our fully + // qualify component code action at the bottom, depending on the users namespace. + ConvertCodeActionsToSumType(request.TextDocument, razorCodeActions, "A-Razor"); + ConvertCodeActionsToSumType(request.TextDocument, delegatedCodeActions, "B-Delegated"); + + return commandsOrCodeActions.ToArray(); + + void ConvertCodeActionsToSumType(VSTextDocumentIdentifier textDocument, ImmutableArray codeActions, string groupName) + { + // We must cast the RazorCodeAction into a platform compliant code action + // For VS (SupportsCodeActionResolve = true) this means just encapsulating the RazorCodeAction in the `CommandOrCodeAction` struct + // For VS Code (SupportsCodeActionResolve = false) we must convert it into a CodeAction or Command before encapsulating in the `CommandOrCodeAction` struct. + if (supportsCodeActionResolve) + { + foreach (var action in codeActions) + { + // Make sure we honour the grouping that a delegated server may have created + action.Group = groupName + (action.Group ?? string.Empty); + commandsOrCodeActions.Add(action); + } + } + else + { + foreach (var action in codeActions) + { + commandsOrCodeActions.Add(action.AsVSCodeCommandOrCodeAction(textDocument)); + } + } + } + } + + private async Task GenerateRazorCodeActionContextAsync( + VSCodeActionParams request, + IDocumentSnapshot documentSnapshot, + bool supportsCodeActionResolve, + CancellationToken cancellationToken) + { + var codeDocument = await documentSnapshot.GetGeneratedOutputAsync(cancellationToken).ConfigureAwait(false); + if (codeDocument.IsUnsupported()) + { + return null; + } + + var sourceText = codeDocument.Source.Text; + + // VS Provides `CodeActionParams.Context.SelectionRange` in addition to + // `CodeActionParams.Range`. The `SelectionRange` is relative to where the + // code action was invoked (ex. line 14, char 3) whereas the `Range` is + // always at the start of the line (ex. line 14, char 0). We want to utilize + // the relative positioning to ensure we provide code actions for the appropriate + // context. + // + // Note: VS Code doesn't provide a `SelectionRange`. + var vsCodeActionContext = request.Context; + if (vsCodeActionContext.SelectionRange != null) + { + request.Range = vsCodeActionContext.SelectionRange; + } + + if (!sourceText.TryGetAbsoluteIndex(request.Range.Start, out var startLocation)) + { + return null; + } + + if (!sourceText.TryGetAbsoluteIndex(request.Range.End, out var endLocation)) + { + endLocation = startLocation; + } + + var context = new RazorCodeActionContext( + request, + documentSnapshot, + codeDocument, + startLocation, + endLocation, + sourceText, + _languageServerFeatureOptions.SupportsFileManipulation, + supportsCodeActionResolve); + + return context; + } + + private async Task> GetDelegatedCodeActionsAsync(RazorCodeActionContext context, Guid correlationId, CancellationToken cancellationToken) + { + var languageKind = context.CodeDocument.GetLanguageKind(context.StartAbsoluteIndex, rightAssociative: false); + + // No point delegating if we're in a Razor context + if (languageKind == RazorLanguageKind.Razor) + { + return []; + } + + var codeActions = await GetCodeActionsFromLanguageServerAsync(languageKind, context, correlationId, cancellationToken).ConfigureAwait(false); + if (codeActions is not [_, ..]) + { + return []; + } + + IEnumerable providers; + if (languageKind == RazorLanguageKind.CSharp) + { + codeActions = ExtractCSharpCodeActionNamesFromData(codeActions); + providers = _csharpCodeActionProviders; + } + else + { + providers = _htmlCodeActionProviders; + } + + return await FilterCodeActionsAsync(context, codeActions.ToImmutableArray(), providers, cancellationToken).ConfigureAwait(false); + } + + private RazorVSInternalCodeAction[] ExtractCSharpCodeActionNamesFromData(RazorVSInternalCodeAction[] codeActions) + { + using var actions = new PooledArrayBuilder(); + + foreach (var codeAction in codeActions) + { + if (codeAction.Data is not JsonElement jsonData || + !jsonData.TryGetProperty("CustomTags", out var value) || + value.Deserialize() is not [..] tags) + { + continue; + } + + foreach (var tag in tags) + { + if (s_allAvailableCodeActionNames.Contains(tag)) + { + codeAction.Name = tag; + break; + } + } + + if (string.IsNullOrEmpty(codeAction.Name)) + { + continue; + } + + actions.Add(codeAction); + } + + return actions.ToArray(); + } + + private static async Task> FilterCodeActionsAsync( + RazorCodeActionContext context, + ImmutableArray codeActions, + IEnumerable providers, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + + using var tasks = new PooledArrayBuilder>>(); + foreach (var provider in providers) + { + tasks.Add(provider.ProvideAsync(context, codeActions, cancellationToken)); + } + + return await ConsolidateCodeActionsFromProvidersAsync(tasks.ToImmutable(), cancellationToken).ConfigureAwait(false); + } + + private Task GetCodeActionsFromLanguageServerAsync(RazorLanguageKind languageKind, RazorCodeActionContext context, Guid correlationId, CancellationToken cancellationToken) + { + if (languageKind == RazorLanguageKind.CSharp) + { + // For C# we have to map the ranges to the generated document + if (!_documentMappingService.TryMapToGeneratedDocumentRange(context.CodeDocument.GetCSharpDocument(), context.Request.Range, out var projectedRange)) + { + return SpecializedTasks.EmptyArray(); + } + + var newContext = context.Request.Context; + if (context.Request.Context is VSInternalCodeActionContext { SelectionRange: not null } vsContext && + _documentMappingService.TryMapToGeneratedDocumentRange(context.CodeDocument.GetCSharpDocument(), vsContext.SelectionRange, out var selectionRange)) + { + vsContext.SelectionRange = selectionRange; + newContext = vsContext; + } + + context.Request.Range = projectedRange; + context.Request.Context = newContext; + } + + cancellationToken.ThrowIfCancellationRequested(); + return _delegatedCodeActionsProvider.GetDelegatedCodeActionsAsync(languageKind, context.Request, context.DocumentSnapshot.Version, correlationId, cancellationToken); + } + + private async Task> GetRazorCodeActionsAsync(RazorCodeActionContext context, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + + using var tasks = new PooledArrayBuilder>>(); + + foreach (var provider in _razorCodeActionProviders) + { + tasks.Add(provider.ProvideAsync(context, cancellationToken)); + } + + return await ConsolidateCodeActionsFromProvidersAsync(tasks.ToImmutable(), cancellationToken).ConfigureAwait(false); + } + + private static async Task> ConsolidateCodeActionsFromProvidersAsync( + ImmutableArray>> tasks, + CancellationToken cancellationToken) + { + var results = await Task.WhenAll(tasks).ConfigureAwait(false); + + using var codeActions = new PooledArrayBuilder(); + + cancellationToken.ThrowIfCancellationRequested(); + + foreach (var result in results) + { + codeActions.AddRange(result); + } + + return codeActions.ToImmutable(); + } + + private static ImmutableHashSet GetAllAvailableCodeActionNames() + { + using var _ = ArrayBuilderPool.GetPooledObject(out var availableCodeActionNames); + + var refactoringProviderNames = typeof(RazorPredefinedCodeRefactoringProviderNames) + .GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public) + .Where(property => property.PropertyType == typeof(string)) + .Select(property => property.GetValue(null) as string) + .WhereNotNull(); + var codeFixProviderNames = typeof(RazorPredefinedCodeFixProviderNames) + .GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public) + .Where(property => property.PropertyType == typeof(string)) + .Select(property => property.GetValue(null) as string) + .WhereNotNull(); + + availableCodeActionNames.AddRange(refactoringProviderNames); + availableCodeActionNames.AddRange(codeFixProviderNames); + availableCodeActionNames.Add(LanguageServerConstants.CodeActions.CodeActionFromVSCode); + + return availableCodeActionNames.ToImmutableHashSet(); + } + + internal TestAccessor GetTestAccessor() => new(this); + + internal readonly struct TestAccessor(CodeActionsService instance) + { + public Task GenerateRazorCodeActionContextAsync(VSCodeActionParams request, IDocumentSnapshot documentSnapshot, bool supportsCodeActionResolve, CancellationToken cancellationToken) + => instance.GenerateRazorCodeActionContextAsync(request, documentSnapshot, supportsCodeActionResolve, cancellationToken); + + public Task GetCodeActionsFromLanguageServerAsync(RazorLanguageKind languageKind, RazorCodeActionContext context, Guid correlationId, CancellationToken cancellationToken) + => instance.GetCodeActionsFromLanguageServerAsync(languageKind, context, correlationId, cancellationToken); + } +} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionsService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionsService.cs new file mode 100644 index 00000000000..7d5dee32e64 --- /dev/null +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionsService.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; +using Microsoft.VisualStudio.LanguageServer.Protocol; + +namespace Microsoft.CodeAnalysis.Razor.CodeActions; + +internal interface ICodeActionsService +{ + Task[]?> GetCodeActionsAsync(VSCodeActionParams request, DocumentContext documentContext, bool supportsCodeActionResolve, Guid correlationId, CancellationToken cancellationToken); +} diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs index e17c4fa449c..92854b07c18 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs @@ -1165,7 +1165,8 @@ internal async Task[]> GetCodeActionsAsync( Diagnostic[]? diagnostics = null) { var delegatedCodeActionsProvider = new DelegatedCodeActionsProvider(clientConnection, NoOpTelemetryReporter.Instance, LoggerFactory); - var endpoint = new CodeActionEndpoint( + + var codeActionsService = new CodeActionsService( DocumentMappingService.AssumeNotNull(), razorCodeActionProviders: razorProviders ?? [], csharpCodeActionProviders: @@ -1175,7 +1176,10 @@ internal async Task[]> GetCodeActionsAsync( ], htmlCodeActionProviders: [], delegatedCodeActionsProvider, - LanguageServerFeatureOptions.AssumeNotNull(), + LanguageServerFeatureOptions.AssumeNotNull()); + + var endpoint = new CodeActionEndpoint( + codeActionsService, NoOpTelemetryReporter.Instance); // Call GetRegistration, so the endpoint knows we support resolve diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs index 623187543a1..37f7f93ad81 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndpointTest.cs @@ -458,7 +458,7 @@ public async Task GenerateRazorCodeActionContextAsync_WithSelectionRange() var documentPath = new Uri("C:/path/to/Page.razor"); var codeDocument = CreateCodeDocument("@code {}"); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var codeActionEndpoint = CreateEndpoint(razorCodeActionProviders: [CreateRazorCodeActionProvider()]); + var codeActionService = CreateService(razorCodeActionProviders: [CreateRazorCodeActionProvider()]); var initialRange = VsLspFactory.CreateZeroWidthRange(0, 1); var selectionRange = VsLspFactory.CreateZeroWidthRange(0, 5); @@ -473,7 +473,7 @@ public async Task GenerateRazorCodeActionContextAsync_WithSelectionRange() }; // Act - var razorCodeActionContext = await codeActionEndpoint.GenerateRazorCodeActionContextAsync(request, documentContext.Snapshot, DisposalToken); + var razorCodeActionContext = await codeActionService.GetTestAccessor().GenerateRazorCodeActionContextAsync(request, documentContext.Snapshot, supportsCodeActionResolve: false, DisposalToken); // Assert Assert.NotNull(razorCodeActionContext); @@ -487,7 +487,7 @@ public async Task GenerateRazorCodeActionContextAsync_WithoutSelectionRange() var documentPath = new Uri("C:/path/to/Page.razor"); var codeDocument = CreateCodeDocument("@code {}"); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var codeActionEndpoint = CreateEndpoint(razorCodeActionProviders: [CreateRazorCodeActionProvider()]); + var codeActionService = CreateService(razorCodeActionProviders: [CreateRazorCodeActionProvider()]); var initialRange = VsLspFactory.CreateZeroWidthRange(0, 1); var request = new VSCodeActionParams() @@ -501,7 +501,7 @@ public async Task GenerateRazorCodeActionContextAsync_WithoutSelectionRange() }; // Act - var razorCodeActionContext = await codeActionEndpoint.GenerateRazorCodeActionContextAsync(request, documentContext.Snapshot, DisposalToken); + var razorCodeActionContext = await codeActionService.GetTestAccessor().GenerateRazorCodeActionContextAsync(request, documentContext.Snapshot, supportsCodeActionResolve: false, DisposalToken); // Assert Assert.NotNull(razorCodeActionContext); @@ -516,7 +516,7 @@ public async Task GetCSharpCodeActionsFromLanguageServerAsync_InvalidRangeMappin var codeDocument = CreateCodeDocument("@code {}"); var documentContext = CreateDocumentContext(documentPath, codeDocument); - var codeActionEndpoint = CreateEndpoint(csharpCodeActionProviders: [CreateCSharpCodeActionProvider()]); + var codeActionService = CreateService(csharpCodeActionProviders: [CreateCSharpCodeActionProvider()]); var initialRange = VsLspFactory.CreateZeroWidthRange(0, 1); var request = new VSCodeActionParams() @@ -526,11 +526,11 @@ public async Task GetCSharpCodeActionsFromLanguageServerAsync_InvalidRangeMappin Context = new VSInternalCodeActionContext() }; - var context = await codeActionEndpoint.GenerateRazorCodeActionContextAsync(request, documentContext.Snapshot, DisposalToken); + var context = await codeActionService.GetTestAccessor().GenerateRazorCodeActionContextAsync(request, documentContext.Snapshot, supportsCodeActionResolve: false, DisposalToken); Assert.NotNull(context); // Act - var results = await codeActionEndpoint.GetCodeActionsFromLanguageServerAsync(RazorLanguageKind.CSharp, context, Guid.Empty, cancellationToken: default); + var results = await codeActionService.GetTestAccessor().GetCodeActionsFromLanguageServerAsync(RazorLanguageKind.CSharp, context, Guid.Empty, cancellationToken: default); // Assert Assert.Empty(results); @@ -546,7 +546,7 @@ public async Task GetCSharpCodeActionsFromLanguageServerAsync_ReturnsCodeActions var documentContext = CreateDocumentContext(documentPath, codeDocument); var projectedRange = VsLspFactory.CreateZeroWidthRange(15, 2); - var codeActionEndpoint = CreateEndpoint( + var codeActionService = CreateService( documentMappingService: CreateDocumentMappingService(projectedRange.ToLinePositionSpan()), csharpCodeActionProviders: [CreateCSharpCodeActionProvider()], clientConnection: TestClientConnection.Instance); @@ -562,11 +562,11 @@ public async Task GetCSharpCodeActionsFromLanguageServerAsync_ReturnsCodeActions } }; - var context = await codeActionEndpoint.GenerateRazorCodeActionContextAsync(request, documentContext.Snapshot, DisposalToken); + var context = await codeActionService.GetTestAccessor().GenerateRazorCodeActionContextAsync(request, documentContext.Snapshot, supportsCodeActionResolve: false, DisposalToken); Assert.NotNull(context); // Act - var results = await codeActionEndpoint.GetCodeActionsFromLanguageServerAsync(RazorLanguageKind.CSharp, context, Guid.Empty, cancellationToken: DisposalToken); + var results = await codeActionService.GetTestAccessor().GetCodeActionsFromLanguageServerAsync(RazorLanguageKind.CSharp, context, Guid.Empty, cancellationToken: DisposalToken); // Assert var result = Assert.Single(results); @@ -592,23 +592,43 @@ private CodeActionEndpoint CreateEndpoint( IClientConnection? clientConnection = null, LanguageServerFeatureOptions? languageServerFeatureOptions = null, bool supportsCodeActionResolve = false) + { + var codeActionsService = CreateService( + documentMappingService, + razorCodeActionProviders, + csharpCodeActionProviders, + htmlCodeActionProviders, + clientConnection, + languageServerFeatureOptions); + + return new CodeActionEndpoint( + codeActionsService, + NoOpTelemetryReporter.Instance) + { + _supportsCodeActionResolve = supportsCodeActionResolve + }; + } + + private CodeActionsService CreateService( + IDocumentMappingService? documentMappingService = null, + ImmutableArray razorCodeActionProviders = default, + ImmutableArray csharpCodeActionProviders = default, + ImmutableArray htmlCodeActionProviders = default, + IClientConnection? clientConnection = null, + LanguageServerFeatureOptions? languageServerFeatureOptions = null) { var delegatedCodeActionsProvider = new DelegatedCodeActionsProvider( clientConnection ?? StrictMock.Of(), NoOpTelemetryReporter.Instance, LoggerFactory); - return new CodeActionEndpoint( + return new CodeActionsService( documentMappingService ?? CreateDocumentMappingService(), razorCodeActionProviders.NullToEmpty(), csharpCodeActionProviders.NullToEmpty(), htmlCodeActionProviders.NullToEmpty(), delegatedCodeActionsProvider, - languageServerFeatureOptions ?? StrictMock.Of(x => x.SupportsFileManipulation == true), - NoOpTelemetryReporter.Instance) - { - _supportsCodeActionResolve = supportsCodeActionResolve - }; + languageServerFeatureOptions ?? StrictMock.Of(x => x.SupportsFileManipulation == true)); } private static IDocumentMappingService CreateDocumentMappingService(LinePositionSpan? projectedRange = null) From 1476b71fe7a51d759ece2408ba34d2a217476f3f Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 24 Oct 2024 18:19:45 +1100 Subject: [PATCH 13/15] Extract code action resolve to a service --- .../CodeActions/CodeActionResolveEndpoint.cs | 178 +---------------- .../IServiceCollectionExtensions.cs | 1 + .../CodeActions/CodeActionResolveService.cs | 188 ++++++++++++++++++ .../CodeActions/ICodeActionResolveService.cs | 17 ++ .../CodeActionEndToEndTest.NetFx.cs | 3 +- .../CodeActionResolutionEndpointTest.cs | 73 ++++--- 6 files changed, 256 insertions(+), 204 deletions(-) create mode 100644 src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CodeActionResolveService.cs create mode 100644 src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionResolveService.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs index 0a8f414b5cd..a1eeccbdc2c 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs @@ -1,205 +1,39 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using System; -using System.Collections.Frozen; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; -using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.CodeAnalysis.Razor.CodeActions; -using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Formatting; -using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.CodeAnalysis.Razor.ProjectSystem; -using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; [RazorLanguageServerEndpoint(Methods.CodeActionResolveName)] internal sealed class CodeActionResolveEndpoint( - IEnumerable razorCodeActionResolvers, - IEnumerable csharpCodeActionResolvers, - IEnumerable htmlCodeActionResolvers, - RazorLSPOptionsMonitor razorLSPOptionsMonitor, - ILoggerFactory loggerFactory) : IRazorRequestHandler + ICodeActionResolveService codeActionResolveService, + RazorLSPOptionsMonitor razorLSPOptionsMonitor) : IRazorRequestHandler { - private readonly FrozenDictionary _razorCodeActionResolvers = CreateResolverMap(razorCodeActionResolvers); - private readonly FrozenDictionary _csharpCodeActionResolvers = CreateResolverMap(csharpCodeActionResolvers); - private readonly FrozenDictionary _htmlCodeActionResolvers = CreateResolverMap(htmlCodeActionResolvers); + private readonly ICodeActionResolveService _codeActionResolveService = codeActionResolveService; private readonly RazorLSPOptionsMonitor _razorLSPOptionsMonitor = razorLSPOptionsMonitor; - private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public bool MutatesSolutionState => false; public TextDocumentIdentifier GetTextDocumentIdentifier(CodeAction request) - => GetRazorCodeActionResolutionParams(request).TextDocument; + => _codeActionResolveService.GetRazorCodeActionResolutionParams(request).TextDocument; public async Task HandleRequestAsync(CodeAction request, RazorRequestContext requestContext, CancellationToken cancellationToken) { - var resolutionParams = GetRazorCodeActionResolutionParams(request); - var documentContext = requestContext.DocumentContext.AssumeNotNull(); - - var codeActionId = GetCodeActionId(resolutionParams); - _logger.LogDebug($"Resolving workspace edit for action {codeActionId}."); - - // If it's a special "edit based code action" then the edit has been pre-computed and we - // can extract the edit details and return to the client. This is only required for VSCode - // as it does not support Command.Edit based code actions anymore. - if (resolutionParams.Action == LanguageServerConstants.CodeActions.EditBasedCodeActionCommand) - { - request.Edit = (resolutionParams.Data as JsonElement?)?.Deserialize(); - return request; - } - var options = new RazorFormattingOptions { TabSize = _razorLSPOptionsMonitor.CurrentValue.TabSize, InsertSpaces = _razorLSPOptionsMonitor.CurrentValue.InsertSpaces, CodeBlockBraceOnNextLine = _razorLSPOptionsMonitor.CurrentValue.CodeBlockBraceOnNextLine }; + var documentContext = requestContext.DocumentContext.AssumeNotNull(); - request.Data = resolutionParams.Data; - - switch (resolutionParams.Language) - { - case RazorLanguageKind.Razor: - return await ResolveRazorCodeActionAsync( - documentContext, - request, - resolutionParams, - options, - cancellationToken).ConfigureAwait(false); - case RazorLanguageKind.CSharp: - return await ResolveCSharpCodeActionAsync( - documentContext, - request, - resolutionParams, - cancellationToken).ConfigureAwait(false); - case RazorLanguageKind.Html: - return await ResolveHtmlCodeActionAsync( - documentContext, - request, - resolutionParams, - cancellationToken).ConfigureAwait(false); - default: - _logger.LogError($"Invalid CodeAction.Data.Language. Received {codeActionId}."); - return request; - } - } - - private static RazorCodeActionResolutionParams GetRazorCodeActionResolutionParams(CodeAction request) - { - if (request.Data is not JsonElement paramsObj) - { - throw new InvalidOperationException($"Invalid CodeAction Received '{request.Title}'."); - } - - var resolutionParams = paramsObj.Deserialize(); - if (resolutionParams is null) - { - throw new InvalidOperationException($"request.Data should be convertible to {nameof(RazorCodeActionResolutionParams)}"); - } - - return resolutionParams; - } - - private async Task ResolveRazorCodeActionAsync( - DocumentContext documentContext, - CodeAction codeAction, - RazorCodeActionResolutionParams resolutionParams, - RazorFormattingOptions options, - CancellationToken cancellationToken) - { - if (!_razorCodeActionResolvers.TryGetValue(resolutionParams.Action, out var resolver)) - { - var codeActionId = GetCodeActionId(resolutionParams); - _logger.LogWarning($"No resolver registered for {codeActionId}"); - Debug.Fail($"No resolver registered for {codeActionId}."); - return codeAction; - } - - if (resolutionParams.Data is not JsonElement data) - { - return codeAction; - } - - var edit = await resolver.ResolveAsync(documentContext, data, options, cancellationToken).ConfigureAwait(false); - codeAction.Edit = edit; - return codeAction; - } - - private async Task ResolveCSharpCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) - { - if (TryGetResolver(resolutionParams, _csharpCodeActionResolvers, out var resolver)) - { - return await resolver.ResolveAsync(documentContext, codeAction, cancellationToken).ConfigureAwait(false); - } - - return codeAction; - } - - private async Task ResolveHtmlCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) - { - if (TryGetResolver(resolutionParams, _htmlCodeActionResolvers, out var resolver)) - { - return await resolver.ResolveAsync(documentContext, codeAction, cancellationToken).ConfigureAwait(false); - } - - return codeAction; - } - - private bool TryGetResolver(RazorCodeActionResolutionParams resolutionParams, FrozenDictionary resolvers, [NotNullWhen(true)] out TResolver? resolver) - where TResolver : ICodeActionResolver - { - if (!resolvers.TryGetValue(resolutionParams.Action, out resolver)) - { - var codeActionId = GetCodeActionId(resolutionParams); - _logger.LogWarning($"No resolver registered for {codeActionId}"); - Debug.Fail($"No resolver registered for {codeActionId}."); - return false; - } - - return resolver is not null; - } - - private static FrozenDictionary CreateResolverMap(IEnumerable codeActionResolvers) - where T : ICodeActionResolver - { - using var _ = StringDictionaryPool.GetPooledObject(out var resolverMap); - - foreach (var resolver in codeActionResolvers) - { - if (resolverMap.ContainsKey(resolver.Action)) - { - Debug.Fail($"Duplicate resolver action for {resolver.Action} of type {typeof(T)}."); - } - - resolverMap[resolver.Action] = resolver; - } - - return resolverMap.ToFrozenDictionary(); - } - - private static string GetCodeActionId(RazorCodeActionResolutionParams resolutionParams) => - $"`{resolutionParams.Language}.{resolutionParams.Action}`"; - - internal TestAccessor GetTestAccessor() => new(this); - - internal readonly struct TestAccessor(CodeActionResolveEndpoint instance) - { - public Task ResolveRazorCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, RazorFormattingOptions options, CancellationToken cancellationToken) - => instance.ResolveRazorCodeActionAsync(documentContext, codeAction, resolutionParams, options, cancellationToken); - - public Task ResolveCSharpCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) - => instance.ResolveCSharpCodeActionAsync(documentContext, codeAction, resolutionParams, cancellationToken); + return await _codeActionResolveService.ResolveCodeActionAsync(documentContext, request, options, cancellationToken).ConfigureAwait(false); - public Task ResolveHtmlCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) - => instance.ResolveCSharpCodeActionAsync(documentContext, codeAction, resolutionParams, cancellationToken); } } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs index 22b3d9208ee..eaef4b100ea 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs @@ -139,6 +139,7 @@ public static void AddCodeActionsServices(this IServiceCollection services) services.AddHandler(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CodeActionResolveService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CodeActionResolveService.cs new file mode 100644 index 00000000000..21de66c58a3 --- /dev/null +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CodeActionResolveService.cs @@ -0,0 +1,188 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Collections.Frozen; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.PooledObjects; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.Formatting; +using Microsoft.CodeAnalysis.Razor.Logging; +using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.CodeAnalysis.Razor.Protocol; +using Microsoft.VisualStudio.LanguageServer.Protocol; + +namespace Microsoft.CodeAnalysis.Razor.CodeActions; + +internal sealed class CodeActionResolveService( + IEnumerable razorCodeActionResolvers, + IEnumerable csharpCodeActionResolvers, + IEnumerable htmlCodeActionResolvers, + ILoggerFactory loggerFactory) : ICodeActionResolveService + +{ + private readonly FrozenDictionary _razorCodeActionResolvers = CreateResolverMap(razorCodeActionResolvers); + private readonly FrozenDictionary _csharpCodeActionResolvers = CreateResolverMap(csharpCodeActionResolvers); + private readonly FrozenDictionary _htmlCodeActionResolvers = CreateResolverMap(htmlCodeActionResolvers); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); + + public async Task ResolveCodeActionAsync(DocumentContext documentContext, CodeAction request, RazorFormattingOptions options, CancellationToken cancellationToken) + { + var resolutionParams = GetRazorCodeActionResolutionParams(request); + + var codeActionId = GetCodeActionId(resolutionParams); + _logger.LogDebug($"Resolving workspace edit for action {codeActionId}."); + + // If it's a special "edit based code action" then the edit has been pre-computed and we + // can extract the edit details and return to the client. This is only required for VSCode + // as it does not support Command.Edit based code actions anymore. + if (resolutionParams.Action == LanguageServerConstants.CodeActions.EditBasedCodeActionCommand) + { + request.Edit = (resolutionParams.Data as JsonElement?)?.Deserialize(); + return request; + } + + request.Data = resolutionParams.Data; + + switch (resolutionParams.Language) + { + case RazorLanguageKind.Razor: + return await ResolveRazorCodeActionAsync( + documentContext, + request, + resolutionParams, + options, + cancellationToken).ConfigureAwait(false); + case RazorLanguageKind.CSharp: + return await ResolveCSharpCodeActionAsync( + documentContext, + request, + resolutionParams, + cancellationToken).ConfigureAwait(false); + case RazorLanguageKind.Html: + return await ResolveHtmlCodeActionAsync( + documentContext, + request, + resolutionParams, + cancellationToken).ConfigureAwait(false); + default: + _logger.LogError($"Invalid CodeAction.Data.Language. Received {codeActionId}."); + return request; + } + } + + public RazorCodeActionResolutionParams GetRazorCodeActionResolutionParams(CodeAction request) + { + if (request.Data is not JsonElement paramsObj) + { + throw new InvalidOperationException($"Invalid CodeAction Received '{request.Title}'."); + } + + var resolutionParams = paramsObj.Deserialize(); + if (resolutionParams is null) + { + throw new InvalidOperationException($"request.Data should be convertible to {nameof(RazorCodeActionResolutionParams)}"); + } + + return resolutionParams; + } + + private async Task ResolveRazorCodeActionAsync( + DocumentContext documentContext, + CodeAction codeAction, + RazorCodeActionResolutionParams resolutionParams, + RazorFormattingOptions options, + CancellationToken cancellationToken) + { + if (!_razorCodeActionResolvers.TryGetValue(resolutionParams.Action, out var resolver)) + { + var codeActionId = GetCodeActionId(resolutionParams); + _logger.LogWarning($"No resolver registered for {codeActionId}"); + Debug.Fail($"No resolver registered for {codeActionId}."); + return codeAction; + } + + if (resolutionParams.Data is not JsonElement data) + { + return codeAction; + } + + var edit = await resolver.ResolveAsync(documentContext, data, options, cancellationToken).ConfigureAwait(false); + codeAction.Edit = edit; + return codeAction; + } + + private async Task ResolveCSharpCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) + { + if (TryGetResolver(resolutionParams, _csharpCodeActionResolvers, out var resolver)) + { + return await resolver.ResolveAsync(documentContext, codeAction, cancellationToken).ConfigureAwait(false); + } + + return codeAction; + } + + private async Task ResolveHtmlCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) + { + if (TryGetResolver(resolutionParams, _htmlCodeActionResolvers, out var resolver)) + { + return await resolver.ResolveAsync(documentContext, codeAction, cancellationToken).ConfigureAwait(false); + } + + return codeAction; + } + + private bool TryGetResolver(RazorCodeActionResolutionParams resolutionParams, FrozenDictionary resolvers, [NotNullWhen(true)] out TResolver? resolver) + where TResolver : ICodeActionResolver + { + if (!resolvers.TryGetValue(resolutionParams.Action, out resolver)) + { + var codeActionId = GetCodeActionId(resolutionParams); + _logger.LogWarning($"No resolver registered for {codeActionId}"); + Debug.Fail($"No resolver registered for {codeActionId}."); + return false; + } + + return resolver is not null; + } + + private static FrozenDictionary CreateResolverMap(IEnumerable codeActionResolvers) + where T : ICodeActionResolver + { + using var _ = StringDictionaryPool.GetPooledObject(out var resolverMap); + + foreach (var resolver in codeActionResolvers) + { + if (resolverMap.ContainsKey(resolver.Action)) + { + Debug.Fail($"Duplicate resolver action for {resolver.Action} of type {typeof(T)}."); + } + + resolverMap[resolver.Action] = resolver; + } + + return resolverMap.ToFrozenDictionary(); + } + + private static string GetCodeActionId(RazorCodeActionResolutionParams resolutionParams) => + $"`{resolutionParams.Language}.{resolutionParams.Action}`"; + + internal TestAccessor GetTestAccessor() => new(this); + + internal readonly struct TestAccessor(CodeActionResolveService instance) + { + public Task ResolveRazorCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, RazorFormattingOptions options, CancellationToken cancellationToken) + => instance.ResolveRazorCodeActionAsync(documentContext, codeAction, resolutionParams, options, cancellationToken); + + public Task ResolveCSharpCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) + => instance.ResolveCSharpCodeActionAsync(documentContext, codeAction, resolutionParams, cancellationToken); + + public Task ResolveHtmlCodeActionAsync(DocumentContext documentContext, CodeAction codeAction, RazorCodeActionResolutionParams resolutionParams, CancellationToken cancellationToken) + => instance.ResolveCSharpCodeActionAsync(documentContext, codeAction, resolutionParams, cancellationToken); + } +} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionResolveService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionResolveService.cs new file mode 100644 index 00000000000..3256a459fce --- /dev/null +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/ICodeActionResolveService.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.Formatting; +using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.VisualStudio.LanguageServer.Protocol; + +namespace Microsoft.CodeAnalysis.Razor.CodeActions; + +internal interface ICodeActionResolveService +{ + RazorCodeActionResolutionParams GetRazorCodeActionResolutionParams(CodeAction request); + Task ResolveCodeActionAsync(DocumentContext documentContext, CodeAction request, RazorFormattingOptions options, CancellationToken cancellationToken); +} diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs index 92854b07c18..4641336ec1f 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs @@ -1224,7 +1224,8 @@ internal async Task GetEditsAsync( var htmlResolvers = Array.Empty(); optionsMonitor ??= TestRazorLSPOptionsMonitor.Create(); - var resolveEndpoint = new CodeActionResolveEndpoint(razorResolvers, csharpResolvers, htmlResolvers, optionsMonitor, LoggerFactory); + var codeActionResolveService = new CodeActionResolveService(razorResolvers, csharpResolvers, htmlResolvers, LoggerFactory); + var resolveEndpoint = new CodeActionResolveEndpoint(codeActionResolveService, optionsMonitor); var resolveResult = await resolveEndpoint.HandleRequestAsync(codeActionToRun, requestContext, DisposalToken); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs index 0d6c0754c93..c0036046eac 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionResolutionEndpointTest.cs @@ -25,12 +25,14 @@ public async Task Handle_Valid_RazorCodeAction_WithResolver() { // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); - var codeActionEndpoint = new CodeActionResolveEndpoint( + var codeActionResolveService = new CodeActionResolveService( razorCodeActionResolvers: [new MockRazorCodeActionResolver("Test")], csharpCodeActionResolvers: [], htmlCodeActionResolvers: [], - TestRazorLSPOptionsMonitor.Create(), LoggerFactory); + var codeActionEndpoint = new CodeActionResolveEndpoint( + codeActionResolveService, + TestRazorLSPOptionsMonitor.Create()); var requestParams = new RazorCodeActionResolutionParams() { TextDocument = (VSTextDocumentIdentifier)documentContext.GetTextDocumentIdentifier(), @@ -60,12 +62,14 @@ public async Task Handle_Valid_CSharpCodeAction_WithResolver() { // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); - var codeActionEndpoint = new CodeActionResolveEndpoint( + var codeActionResolveService = new CodeActionResolveService( razorCodeActionResolvers: [], [new MockCSharpCodeActionResolver("Test")], htmlCodeActionResolvers: [], - TestRazorLSPOptionsMonitor.Create(), LoggerFactory); + var codeActionEndpoint = new CodeActionResolveEndpoint( + codeActionResolveService, + TestRazorLSPOptionsMonitor.Create()); var requestParams = new RazorCodeActionResolutionParams() { TextDocument = (VSTextDocumentIdentifier)documentContext.GetTextDocumentIdentifier(), @@ -91,12 +95,14 @@ public async Task Handle_Valid_CSharpCodeAction_WithMultipleLanguageResolvers() { // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); - var codeActionEndpoint = new CodeActionResolveEndpoint( + var codeActionResolveService = new CodeActionResolveService( razorCodeActionResolvers: [new MockRazorCodeActionResolver("TestRazor")], csharpCodeActionResolvers: [new MockCSharpCodeActionResolver("TestCSharp")], htmlCodeActionResolvers: [], - TestRazorLSPOptionsMonitor.Create(), LoggerFactory); + var codeActionEndpoint = new CodeActionResolveEndpoint( + codeActionResolveService, + TestRazorLSPOptionsMonitor.Create()); var requestParams = new RazorCodeActionResolutionParams() { TextDocument = (VSTextDocumentIdentifier)documentContext.GetTextDocumentIdentifier(), @@ -122,12 +128,14 @@ public async Task Handle_Valid_RazorCodeAction_WithoutResolver() { // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); - var codeActionEndpoint = new CodeActionResolveEndpoint( + var codeActionResolveService = new CodeActionResolveService( razorCodeActionResolvers: [], csharpCodeActionResolvers: [], htmlCodeActionResolvers: [], - TestRazorLSPOptionsMonitor.Create(), LoggerFactory); + var codeActionEndpoint = new CodeActionResolveEndpoint( + codeActionResolveService, + TestRazorLSPOptionsMonitor.Create()); var requestParams = new RazorCodeActionResolutionParams() { TextDocument = (VSTextDocumentIdentifier)documentContext.GetTextDocumentIdentifier(), @@ -162,12 +170,14 @@ public async Task Handle_Valid_CSharpCodeAction_WithoutResolver() { // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); - var codeActionEndpoint = new CodeActionResolveEndpoint( + var codeActionResolveService = new CodeActionResolveService( razorCodeActionResolvers: [], csharpCodeActionResolvers: [], htmlCodeActionResolvers: [], - TestRazorLSPOptionsMonitor.Create(), LoggerFactory); + var codeActionEndpoint = new CodeActionResolveEndpoint( + codeActionResolveService, + TestRazorLSPOptionsMonitor.Create()); var requestParams = new RazorCodeActionResolutionParams() { TextDocument = (VSTextDocumentIdentifier)documentContext.GetTextDocumentIdentifier(), @@ -198,12 +208,14 @@ public async Task Handle_Valid_RazorCodeAction_WithCSharpResolver_ResolvesNull() { // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); - var codeActionEndpoint = new CodeActionResolveEndpoint( + var codeActionResolveService = new CodeActionResolveService( razorCodeActionResolvers: [], csharpCodeActionResolvers: [new MockCSharpCodeActionResolver("Test")], htmlCodeActionResolvers: [], - TestRazorLSPOptionsMonitor.Create(), LoggerFactory); + var codeActionEndpoint = new CodeActionResolveEndpoint( + codeActionResolveService, + TestRazorLSPOptionsMonitor.Create()); var requestParams = new RazorCodeActionResolutionParams() { TextDocument = (VSTextDocumentIdentifier)documentContext.GetTextDocumentIdentifier(), @@ -238,12 +250,14 @@ public async Task Handle_Valid_CSharpCodeAction_WithRazorResolver_ResolvesNull() { // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); - var codeActionEndpoint = new CodeActionResolveEndpoint( + var codeActionResolveService = new CodeActionResolveService( razorCodeActionResolvers: [new MockRazorCodeActionResolver("Test")], csharpCodeActionResolvers: [], htmlCodeActionResolvers: [], - TestRazorLSPOptionsMonitor.Create(), LoggerFactory); + var codeActionEndpoint = new CodeActionResolveEndpoint( + codeActionResolveService, + TestRazorLSPOptionsMonitor.Create()); var requestParams = new RazorCodeActionResolutionParams() { TextDocument = (VSTextDocumentIdentifier)documentContext.GetTextDocumentIdentifier(), @@ -274,14 +288,13 @@ public async Task ResolveRazorCodeAction_ResolveMultipleRazorProviders_FirstMatc { // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); - var codeActionEndpoint = new CodeActionResolveEndpoint( + var service = new CodeActionResolveService( razorCodeActionResolvers: [ new MockRazorCodeActionResolver("A"), new MockRazorNullCodeActionResolver("B"), ], csharpCodeActionResolvers: [], htmlCodeActionResolvers: [], - TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -296,7 +309,7 @@ public async Task ResolveRazorCodeAction_ResolveMultipleRazorProviders_FirstMatc }; // Act - var resolvedCodeAction = await codeActionEndpoint.GetTestAccessor().ResolveRazorCodeActionAsync(documentContext, codeAction, request, new RazorFormattingOptions(), DisposalToken); + var resolvedCodeAction = await service.GetTestAccessor().ResolveRazorCodeActionAsync(documentContext, codeAction, request, new RazorFormattingOptions(), DisposalToken); // Assert Assert.NotNull(resolvedCodeAction.Edit); @@ -307,14 +320,13 @@ public async Task ResolveRazorCodeAction_ResolveMultipleRazorProviders_SecondMat { // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); - var codeActionEndpoint = new CodeActionResolveEndpoint( + var service = new CodeActionResolveService( razorCodeActionResolvers: [ new MockRazorNullCodeActionResolver("A"), new MockRazorCodeActionResolver("B"), ], csharpCodeActionResolvers: [], htmlCodeActionResolvers: [], - TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -329,7 +341,7 @@ public async Task ResolveRazorCodeAction_ResolveMultipleRazorProviders_SecondMat }; // Act - var resolvedCodeAction = await codeActionEndpoint.GetTestAccessor().ResolveRazorCodeActionAsync(documentContext, codeAction, request, new RazorFormattingOptions(), DisposalToken); + var resolvedCodeAction = await service.GetTestAccessor().ResolveRazorCodeActionAsync(documentContext, codeAction, request, new RazorFormattingOptions(), DisposalToken); // Assert Assert.NotNull(resolvedCodeAction.Edit); @@ -340,14 +352,13 @@ public async Task ResolveCSharpCodeAction_ResolveMultipleCSharpProviders_FirstMa { // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); - var codeActionEndpoint = new CodeActionResolveEndpoint( + var service = new CodeActionResolveService( razorCodeActionResolvers: [], csharpCodeActionResolvers: [ new MockCSharpCodeActionResolver("A"), new MockCSharpNullCodeActionResolver("B"), ], htmlCodeActionResolvers: [], - TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -358,7 +369,7 @@ public async Task ResolveCSharpCodeAction_ResolveMultipleCSharpProviders_FirstMa }; // Act - var resolvedCodeAction = await codeActionEndpoint.GetTestAccessor().ResolveCSharpCodeActionAsync(documentContext, codeAction, request, DisposalToken); + var resolvedCodeAction = await service.GetTestAccessor().ResolveCSharpCodeActionAsync(documentContext, codeAction, request, DisposalToken); // Assert Assert.NotNull(resolvedCodeAction.Edit); @@ -369,14 +380,13 @@ public async Task ResolveCSharpCodeAction_ResolveMultipleCSharpProviders_SecondM { // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); - var codeActionEndpoint = new CodeActionResolveEndpoint( + var service = new CodeActionResolveService( razorCodeActionResolvers: [], csharpCodeActionResolvers: [ new MockCSharpNullCodeActionResolver("A"), new MockCSharpCodeActionResolver("B"), ], htmlCodeActionResolvers: [], - TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -387,7 +397,7 @@ public async Task ResolveCSharpCodeAction_ResolveMultipleCSharpProviders_SecondM }; // Act - var resolvedCodeAction = await codeActionEndpoint.GetTestAccessor().ResolveCSharpCodeActionAsync(documentContext, codeAction, request, DisposalToken); + var resolvedCodeAction = await service.GetTestAccessor().ResolveCSharpCodeActionAsync(documentContext, codeAction, request, DisposalToken); // Assert Assert.NotNull(resolvedCodeAction.Edit); @@ -398,7 +408,7 @@ public async Task ResolveCSharpCodeAction_ResolveMultipleLanguageProviders() { // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); - var codeActionEndpoint = new CodeActionResolveEndpoint( + var service = new CodeActionResolveService( razorCodeActionResolvers: [ new MockRazorNullCodeActionResolver("A"), new MockRazorCodeActionResolver("B"), @@ -408,7 +418,6 @@ public async Task ResolveCSharpCodeAction_ResolveMultipleLanguageProviders() new MockCSharpCodeActionResolver("D"), ], htmlCodeActionResolvers: [], - TestRazorLSPOptionsMonitor.Create(), LoggerFactory); var codeAction = new CodeAction(); var request = new RazorCodeActionResolutionParams() @@ -419,7 +428,7 @@ public async Task ResolveCSharpCodeAction_ResolveMultipleLanguageProviders() }; // Act - var resolvedCodeAction = await codeActionEndpoint.GetTestAccessor().ResolveCSharpCodeActionAsync(documentContext, codeAction, request, DisposalToken); + var resolvedCodeAction = await service.GetTestAccessor().ResolveCSharpCodeActionAsync(documentContext, codeAction, request, DisposalToken); // Assert Assert.NotNull(resolvedCodeAction.Edit); @@ -430,12 +439,14 @@ public async Task Handle_ResolveEditBasedCodeActionCommand() { // Arrange var documentContext = TestDocumentContext.Create(new Uri("C:/path/to/Page.razor")); - var codeActionEndpoint = new CodeActionResolveEndpoint( + var codeActionResolveService = new CodeActionResolveService( razorCodeActionResolvers: [], csharpCodeActionResolvers: [new MockCSharpCodeActionResolver("Test")], htmlCodeActionResolvers: [], - TestRazorLSPOptionsMonitor.Create(), LoggerFactory); + var codeActionEndpoint = new CodeActionResolveEndpoint( + codeActionResolveService, + TestRazorLSPOptionsMonitor.Create()); var requestParams = new RazorCodeActionResolutionParams() { TextDocument = (VSTextDocumentIdentifier)documentContext.GetTextDocumentIdentifier(), From 52c3c4f05c6ca3cd23330e399e20c472bba837b5 Mon Sep 17 00:00:00 2001 From: David Wengier Date: Fri, 25 Oct 2024 09:59:25 +1100 Subject: [PATCH 14/15] PR Feedback, and a few sneaky using directives that weren't sorted --- .../CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs | 2 +- .../CSharp/TypeAccessibilityCodeActionProvider.cs | 4 ++-- .../CodeActions/Html/DefaultHtmlCodeActionProvider.cs | 2 +- .../CodeActions/Razor/CreateComponentCodeActionResolver.cs | 2 +- .../Razor/ExtractToCodeBehindCodeActionProvider.cs | 4 ++-- .../Formatting/FormattingUtilities.cs | 1 - .../CSharp/DefaultCSharpCodeActionProviderTest.cs | 4 ++-- .../CSharp/TypeAccessibilityCodeActionProviderTest.cs | 4 ++-- .../CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs | 4 ++-- .../Razor/ComponentAccessibilityCodeActionProviderTest.cs | 4 ++-- .../Razor/ExtractToCodeBehindCodeActionProviderTest.cs | 6 +++--- 11 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs index 6c71c730de8..06639726674 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs @@ -9,10 +9,10 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Threading; using Microsoft.CodeAnalysis.ExternalAccess.Razor; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Workspaces; namespace Microsoft.CodeAnalysis.Razor.CodeActions; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs index 1b192552084..dde537f6a73 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/TypeAccessibilityCodeActionProvider.cs @@ -11,11 +11,11 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.CodeAnalysis.Razor.CodeActions.Models; -using Microsoft.CodeAnalysis.Razor.CodeActions.Razor; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.AspNetCore.Razor.Threading; using Microsoft.CodeAnalysis.ExternalAccess.Razor; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Razor; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Text; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionProvider.cs index 28c1ed3af29..15f1293ee69 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionProvider.cs @@ -5,8 +5,8 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.AspNetCore.Razor.PooledObjects; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CreateComponentCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CreateComponentCodeActionResolver.cs index f04b2cf4e82..fa398c9662d 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CreateComponentCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/CreateComponentCodeActionResolver.cs @@ -10,8 +10,8 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.AspNetCore.Razor.PooledObjects; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs index 54730e8cabd..9fd9cd646d8 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs @@ -11,10 +11,10 @@ using Microsoft.AspNetCore.Razor.Language.Components; using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.CodeAnalysis.Razor.CodeActions.Models; -using Microsoft.CodeAnalysis.Razor.CodeActions.Razor; using Microsoft.AspNetCore.Razor.Threading; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Razor.CodeActions.Models; +using Microsoft.CodeAnalysis.Razor.CodeActions.Razor; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingUtilities.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingUtilities.cs index fb2315899e2..f264edece41 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingUtilities.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingUtilities.cs @@ -268,7 +268,6 @@ static bool IsWhitespace(char c) /// document we send them has lots of tildes. In those cases, we need to do some extra work to compute the /// minimal text edits ///
- // Internal for testing public static TextEdit[] FixHtmlTextEdits(SourceText htmlSourceText, TextEdit[] edits) { // Avoid computing a minimal diff if we don't need to diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs index ecf383b9de7..0d338f1dbb5 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs @@ -340,8 +340,8 @@ private static RazorCodeActionContext CreateRazorCodeActionContext( request, documentSnapshotMock.Object, codeDocument, - absoluteIndex, - absoluteIndex, + StartAbsoluteIndex: absoluteIndex, + EndAbsoluteIndex: absoluteIndex, codeDocument.Source.Text, supportsFileCreation, supportsCodeActionResolve); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/TypeAccessibilityCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/TypeAccessibilityCodeActionProviderTest.cs index 62a825f53cd..df59192651e 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/TypeAccessibilityCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/TypeAccessibilityCodeActionProviderTest.cs @@ -471,8 +471,8 @@ private static RazorCodeActionContext CreateRazorCodeActionContext( request, documentSnapshotMock.Object, codeDocument, - absoluteIndex, - absoluteIndex, + StartAbsoluteIndex: absoluteIndex, + EndAbsoluteIndex: absoluteIndex, codeDocument.Source.Text, supportsFileCreation, supportsCodeActionResolve); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs index fa0f3fcbd95..922b25f4046 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs @@ -165,8 +165,8 @@ private static RazorCodeActionContext CreateRazorCodeActionContext( request, documentSnapshotMock.Object, codeDocument, - absoluteIndex, - absoluteIndex, + StartAbsoluteIndex: absoluteIndex, + EndAbsoluteIndex: absoluteIndex, codeDocument.Source.Text, supportsFileCreation, supportsCodeActionResolve); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs index ead2575f81f..9252b4e9df3 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ComponentAccessibilityCodeActionProviderTest.cs @@ -468,8 +468,8 @@ private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionP request, documentSnapshotMock.Object, codeDocument, - absoluteIndex, - absoluteIndex, + StartAbsoluteIndex: absoluteIndex, + EndAbsoluteIndex: absoluteIndex, codeDocument.Source.Text, supportsFileCreation, SupportsCodeActionResolve: true); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionProviderTest.cs index 55249ff1040..43118a4a944 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToCodeBehindCodeActionProviderTest.cs @@ -370,7 +370,7 @@ public async Task Handle_NullRelativePath_ReturnsNull() private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionParams request, int absoluteIndex, string filePath, string text, bool supportsFileCreation = true) => CreateRazorCodeActionContext(request, absoluteIndex, filePath, text, relativePath: filePath, supportsFileCreation: supportsFileCreation); - private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionParams request, int aboluteIndex, string filePath, string text, string? relativePath, bool supportsFileCreation = true) + private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionParams request, int absoluteIndex, string filePath, string text, string? relativePath, bool supportsFileCreation = true) { var sourceDocument = RazorSourceDocument.Create(text, RazorSourceDocumentProperties.Create(filePath, relativePath)); var options = RazorParserOptions.Create(o => @@ -400,8 +400,8 @@ private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionP request, documentSnapshotMock.Object, codeDocument, - aboluteIndex, - aboluteIndex, + StartAbsoluteIndex: absoluteIndex, + EndAbsoluteIndex: absoluteIndex, codeDocument.Source.Text, supportsFileCreation, SupportsCodeActionResolve: true); From 8ebdce8d422c08e3569bd046d630096aa895066d Mon Sep 17 00:00:00 2001 From: David Wengier Date: Fri, 25 Oct 2024 10:14:14 +1100 Subject: [PATCH 15/15] Rename files to remove Default from the name --- .../IServiceCollectionExtensions.cs | 8 +++---- ...rovider.cs => CSharpCodeActionProvider.cs} | 2 +- ...esolver.cs => CSharpCodeActionResolver.cs} | 2 +- ...nProvider.cs => HtmlCodeActionProvider.cs} | 2 +- ...nResolver.cs => HtmlCodeActionResolver.cs} | 4 ++-- ...est.cs => CSharpCodeActionProviderTest.cs} | 24 +++++++++---------- ...est.cs => CSharpCodeActionResolverTest.cs} | 6 ++--- .../CodeActionEndToEndTest.NetFx.cs | 4 ++-- ...rTest.cs => HtmlCodeActionProviderTest.cs} | 6 ++--- ...rTest.cs => HtmlCodeActionResolverTest.cs} | 4 ++-- 10 files changed, 31 insertions(+), 31 deletions(-) rename src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/{DefaultCSharpCodeActionProvider.cs => CSharpCodeActionProvider.cs} (97%) rename src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/{DefaultCSharpCodeActionResolver.cs => CSharpCodeActionResolver.cs} (98%) rename src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/{DefaultHtmlCodeActionProvider.cs => HtmlCodeActionProvider.cs} (95%) rename src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/{DefaultHtmlCodeActionResolver.cs => HtmlCodeActionResolver.cs} (86%) rename src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/{DefaultCSharpCodeActionProviderTest.cs => CSharpCodeActionProviderTest.cs} (92%) rename src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/{DefaultCSharpCodeActionResolverTest.cs => CSharpCodeActionResolverTest.cs} (97%) rename src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/{DefaultHtmlCodeActionProviderTest.cs => HtmlCodeActionProviderTest.cs} (95%) rename src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/{DefaultHtmlCodeActionResolverTest.cs => HtmlCodeActionResolverTest.cs} (94%) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs index eaef4b100ea..85a9650062a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs @@ -146,8 +146,8 @@ public static void AddCodeActionsServices(this IServiceCollection services) // CSharp Code actions services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); // Razor Code actions @@ -162,8 +162,8 @@ public static void AddCodeActionsServices(this IServiceCollection services) services.AddSingleton(); // Html Code actions - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); } public static void AddTextDocumentServices(this IServiceCollection services, LanguageServerFeatureOptions featureOptions) diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/CSharpCodeActionProvider.cs similarity index 97% rename from src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/CSharpCodeActionProvider.cs index 06639726674..5f893c6e624 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/CSharpCodeActionProvider.cs @@ -17,7 +17,7 @@ namespace Microsoft.CodeAnalysis.Razor.CodeActions; -internal sealed class DefaultCSharpCodeActionProvider(LanguageServerFeatureOptions languageServerFeatureOptions) : ICSharpCodeActionProvider +internal sealed class CSharpCodeActionProvider(LanguageServerFeatureOptions languageServerFeatureOptions) : ICSharpCodeActionProvider { // Internal for testing internal static readonly HashSet SupportedDefaultCodeActionNames = diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/CSharpCodeActionResolver.cs similarity index 98% rename from src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/CSharpCodeActionResolver.cs index c53682f87f9..274b5f544f2 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/CSharp/CSharpCodeActionResolver.cs @@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.Razor.CodeActions; -internal sealed class DefaultCSharpCodeActionResolver( +internal sealed class CSharpCodeActionResolver( IDelegatedCodeActionResolver delegatedCodeActionResolver, IRazorFormattingService razorFormattingService) : ICSharpCodeActionResolver { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/HtmlCodeActionProvider.cs similarity index 95% rename from src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/HtmlCodeActionProvider.cs index 15f1293ee69..a29cbd0083c 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/HtmlCodeActionProvider.cs @@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.Razor.CodeActions; -internal sealed class DefaultHtmlCodeActionProvider(IEditMappingService editMappingService) : IHtmlCodeActionProvider +internal sealed class HtmlCodeActionProvider(IEditMappingService editMappingService) : IHtmlCodeActionProvider { private readonly IEditMappingService _editMappingService = editMappingService; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionResolver.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/HtmlCodeActionResolver.cs similarity index 86% rename from src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionResolver.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/HtmlCodeActionResolver.cs index bc5e3c8834a..075a598e15f 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/DefaultHtmlCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/Html/HtmlCodeActionResolver.cs @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Razor.CodeActions; -internal sealed class DefaultHtmlCodeActionResolver( +internal sealed class HtmlCodeActionResolver( IDelegatedCodeActionResolver delegatedCodeActionResolver, IEditMappingService editMappingService) : IHtmlCodeActionResolver { @@ -31,7 +31,7 @@ public async Task ResolveAsync( return codeAction; } - await DefaultHtmlCodeActionProvider.RemapAndFixHtmlCodeActionEditAsync(_editMappingService, documentContext.Snapshot, resolvedCodeAction, cancellationToken).ConfigureAwait(false); + await HtmlCodeActionProvider.RemapAndFixHtmlCodeActionEditAsync(_editMappingService, documentContext.Snapshot, resolvedCodeAction, cancellationToken).ConfigureAwait(false); return resolvedCodeAction; } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/CSharpCodeActionProviderTest.cs similarity index 92% rename from src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs rename to src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/CSharpCodeActionProviderTest.cs index 0d338f1dbb5..dad2006ec51 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/CSharpCodeActionProviderTest.cs @@ -23,20 +23,20 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; -public class DefaultCSharpCodeActionProviderTest : LanguageServerTestBase +public class CSharpCodeActionProviderTest : LanguageServerTestBase { private readonly ImmutableArray _supportedCodeActions; private readonly ImmutableArray _supportedImplicitExpressionCodeActions; - public DefaultCSharpCodeActionProviderTest(ITestOutputHelper testOutput) + public CSharpCodeActionProviderTest(ITestOutputHelper testOutput) : base(testOutput) { - _supportedCodeActions = DefaultCSharpCodeActionProvider + _supportedCodeActions = CSharpCodeActionProvider .SupportedDefaultCodeActionNames .Select(name => new RazorVSInternalCodeAction { Name = name }) .ToImmutableArray(); - _supportedImplicitExpressionCodeActions = DefaultCSharpCodeActionProvider + _supportedImplicitExpressionCodeActions = CSharpCodeActionProvider .SupportedImplicitExpressionCodeActionNames .Select(name => new RazorVSInternalCodeAction { Name = name }) .ToImmutableArray(); @@ -60,7 +60,7 @@ public async Task ProvideAsync_ValidCodeActions_ReturnsProvidedCodeAction() var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(8, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); - var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); + var provider = new CSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); // Act var providedCodeActions = await provider.ProvideAsync(context, _supportedCodeActions, default); @@ -90,7 +90,7 @@ public async Task ProvideAsync_SupportsCodeActionResolveFalse_ValidCodeActions_R var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(8, 4), supportsCodeActionResolve: false); context.CodeDocument.SetFileKind(FileKinds.Legacy); - var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); + var provider = new CSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); // Act var providedCodeActions = await provider.ProvideAsync(context, _supportedCodeActions, default); @@ -117,7 +117,7 @@ public async Task ProvideAsync_FunctionsBlock_SingleLine_ValidCodeActions_Return var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(13, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); - var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); + var provider = new CSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); // Act var providedCodeActions = await provider.ProvideAsync(context, _supportedCodeActions, default); @@ -149,7 +149,7 @@ public async Task ProvideAsync_FunctionsBlock_OpenBraceSameLine_ValidCodeActions var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(13, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); - var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); + var provider = new CSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); // Act var providedCodeActions = await provider.ProvideAsync(context, _supportedCodeActions, default); @@ -182,7 +182,7 @@ public async Task ProvideAsync_FunctionsBlock_OpenBraceNextLine_ValidCodeActions var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(13, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); - var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); + var provider = new CSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); // Act var providedCodeActions = await provider.ProvideAsync(context, _supportedCodeActions, default); @@ -212,7 +212,7 @@ public async Task ProvideAsync_InvalidCodeActions_ReturnsNoCodeActions() var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(8, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); - var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); + var provider = new CSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); ImmutableArray codeActions = [ @@ -249,7 +249,7 @@ public async Task ProvideAsync_InvalidCodeActions_ShowAllFeatureFlagOn_ReturnsCo context.CodeDocument.SetFileKind(FileKinds.Legacy); var options = new ConfigurableLanguageServerFeatureOptions(new[] { $"--{nameof(ConfigurableLanguageServerFeatureOptions.ShowAllCSharpCodeActions)}" }); - var provider = new DefaultCSharpCodeActionProvider(options); + var provider = new CSharpCodeActionProvider(options); ImmutableArray codeActions = [ @@ -293,7 +293,7 @@ public async Task ProvideAsync_ImplicitExpression_ReturnsProvidedCodeAction() var context = CreateRazorCodeActionContext(request, cursorPosition, documentPath, contents, new SourceSpan(8, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); - var provider = new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); + var provider = new CSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance); // Act var providedCodeActions = await provider.ProvideAsync(context, _supportedCodeActions, default); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/CSharpCodeActionResolverTest.cs similarity index 97% rename from src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs rename to src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/CSharpCodeActionResolverTest.cs index 19c09c6cfd7..2e013afa8e2 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/CSharpCodeActionResolverTest.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; -public class DefaultCSharpCodeActionResolverTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput) +public class CSharpCodeActionResolverTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput) { private static readonly CodeAction s_defaultResolvedCodeAction = new() { @@ -161,7 +161,7 @@ public async Task ResolveAsync_NonTextDocumentEdit_ReturnsOriginalCodeAction() } private static void CreateCodeActionResolver( - out DefaultCSharpCodeActionResolver csharpCodeActionResolver, + out CSharpCodeActionResolver csharpCodeActionResolver, out DocumentContext documentContext, IClientConnection? clientConnection = null, IRazorFormattingService? razorFormattingService = null) @@ -175,7 +175,7 @@ private static void CreateCodeActionResolver( razorFormattingService ??= CreateRazorFormattingService(documentUri); var delegatedCodeActionResolver = new DelegatedCodeActionResolver(clientConnection); - csharpCodeActionResolver = new DefaultCSharpCodeActionResolver( + csharpCodeActionResolver = new CSharpCodeActionResolver( delegatedCodeActionResolver, razorFormattingService); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs index 4641336ec1f..4d879291058 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CodeActionEndToEndTest.NetFx.cs @@ -1171,7 +1171,7 @@ internal async Task[]> GetCodeActionsAsync( razorCodeActionProviders: razorProviders ?? [], csharpCodeActionProviders: [ - new DefaultCSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance), + new CSharpCodeActionProvider(TestLanguageServerFeatureOptions.Instance), new TypeAccessibilityCodeActionProvider() ], htmlCodeActionProviders: [], @@ -1218,7 +1218,7 @@ internal async Task GetEditsAsync( var delegatedCodeActionResolver = new DelegatedCodeActionResolver(clientConnection); var csharpResolvers = new ICSharpCodeActionResolver[] { - new DefaultCSharpCodeActionResolver(delegatedCodeActionResolver, formattingService) + new CSharpCodeActionResolver(delegatedCodeActionResolver, formattingService) }; var htmlResolvers = Array.Empty(); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/HtmlCodeActionProviderTest.cs similarity index 95% rename from src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs rename to src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/HtmlCodeActionProviderTest.cs index 922b25f4046..7d0dead6f73 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/HtmlCodeActionProviderTest.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; -public class DefaultHtmlCodeActionProviderTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput) +public class HtmlCodeActionProviderTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput) { [Fact] public async Task ProvideAsync_WrapsResolvableCodeActions() @@ -44,7 +44,7 @@ public async Task ProvideAsync_WrapsResolvableCodeActions() context.CodeDocument.SetFileKind(FileKinds.Legacy); var documentMappingService = StrictMock.Of(); - var provider = new DefaultHtmlCodeActionProvider(documentMappingService); + var provider = new HtmlCodeActionProvider(documentMappingService); ImmutableArray codeActions = [new RazorVSInternalCodeAction() { Name = "Test" }]; @@ -94,7 +94,7 @@ public async Task ProvideAsync_RemapsAndFixesEdits() .Setup(x => x.RemapWorkspaceEditAsync(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(remappedEdit); - var provider = new DefaultHtmlCodeActionProvider(editMappingServiceMock.Object); + var provider = new HtmlCodeActionProvider(editMappingServiceMock.Object); ImmutableArray codeActions = [ diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/HtmlCodeActionResolverTest.cs similarity index 94% rename from src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionResolverTest.cs rename to src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/HtmlCodeActionResolverTest.cs index 9c7a979f2b4..e0bfaa4b922 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/DefaultHtmlCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Html/HtmlCodeActionResolverTest.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; -public class DefaultHtmlCodeActionResolverTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput) +public class HtmlCodeActionResolverTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput) { [Fact] public async Task ResolveAsync_RemapsAndFixesEdits() @@ -60,7 +60,7 @@ public async Task ResolveAsync_RemapsAndFixesEdits() .ReturnsAsync(remappedEdit); var delegatedCodeActionResolver = new DelegatedCodeActionResolver(CreateLanguageServer(resolvedCodeAction)); - var resolver = new DefaultHtmlCodeActionResolver(delegatedCodeActionResolver, editMappingServiceMock.Object); + var resolver = new HtmlCodeActionResolver(delegatedCodeActionResolver, editMappingServiceMock.Object); var codeAction = new RazorVSInternalCodeAction() {