From 35066124122f5ce13d8bc501c962263e72cf0799 Mon Sep 17 00:00:00 2001 From: marcarro Date: Mon, 5 Aug 2024 09:39:38 -0700 Subject: [PATCH] Corrected naming and nits --- ....cs => ExtractToComponentCodeActionProvider.cs} | 13 +++++++++---- ....cs => ExtractToComponentCodeActionResolver.cs} | 7 +++---- .../CodeActions/Razor/RazorCodeActionFactory.cs | 8 ++++---- .../Extensions/IServiceCollectionExtensions.cs | 4 ++-- .../Resources/SR.resx | 2 +- .../Resources/xlf/SR.cs.xlf | 2 +- .../Resources/xlf/SR.de.xlf | 2 +- .../Resources/xlf/SR.es.xlf | 2 +- .../Resources/xlf/SR.fr.xlf | 2 +- .../Resources/xlf/SR.it.xlf | 2 +- .../Resources/xlf/SR.ja.xlf | 2 +- .../Resources/xlf/SR.ko.xlf | 2 +- .../Resources/xlf/SR.pl.xlf | 2 +- .../Resources/xlf/SR.pt-BR.xlf | 2 +- .../Resources/xlf/SR.ru.xlf | 2 +- .../Resources/xlf/SR.tr.xlf | 2 +- .../Resources/xlf/SR.zh-Hans.xlf | 2 +- .../Resources/xlf/SR.zh-Hant.xlf | 2 +- ...=> ExtractToComponentCodeActionProviderTest.cs} | 14 +++++++------- 19 files changed, 39 insertions(+), 35 deletions(-) rename src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/{ExtractToNewComponentCodeActionProvider.cs => ExtractToComponentCodeActionProvider.cs} (96%) rename src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/{ExtractToNewComponentCodeActionResolver.cs => ExtractToComponentCodeActionResolver.cs} (96%) rename src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/{ExtractToNewComponentCodeActionProviderTest.cs => ExtractToComponentCodeActionProviderTest.cs} (95%) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToNewComponentCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs similarity index 96% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToNewComponentCodeActionProvider.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs index caad5e33452..411e141d9f1 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToNewComponentCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionProvider.cs @@ -1,5 +1,5 @@ // Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT license. See License.txt in the project divNode for license information. +// Licensed under the MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -25,9 +25,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; -internal sealed class ExtractToNewComponentCodeActionProvider(ILoggerFactory loggerFactory) : IRazorCodeActionProvider +internal sealed class ExtractToComponentCodeActionProvider(ILoggerFactory loggerFactory) : IRazorCodeActionProvider { - private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public Task> ProvideAsync(RazorCodeActionContext context, CancellationToken cancellationToken) { @@ -90,7 +90,7 @@ public Task> ProvideAsync(RazorCodeAct Data = actionParams, }; - var codeAction = RazorCodeActionFactory.CreateExtractToNewComponent(resolutionParams); + var codeAction = RazorCodeActionFactory.CreateExtractToComponent(resolutionParams); return Task.FromResult>([codeAction]); } @@ -352,10 +352,13 @@ private static void GetUsedIdentifiers(SyntaxNode divNode, SyntaxNode documentRo HashSet identifiersInScope = []; HashSet identifiersInBlock = []; + HashSet nodesInScope = []; + HashSet nodesInBlock = []; foreach (var node in divNode.DescendantNodes().Where(static node => node.Kind is SyntaxKind.Identifier)) { identifiersInScope.Add(node.GetContent()); + nodesInScope.Add(node); } foreach (var codeBlock in documentRoot.DescendantNodes().Where(static node => node.Kind is SyntaxKind.RazorDirective)) @@ -363,9 +366,11 @@ private static void GetUsedIdentifiers(SyntaxNode divNode, SyntaxNode documentRo foreach (var node in codeBlock.DescendantNodes().Where(static node => node.Kind is SyntaxKind.Identifier)) { identifiersInBlock.Add(node.GetContent()); + nodesInBlock.Add(node); } } + nodesInBlock.IntersectWith(nodesInScope); identifiersInBlock.IntersectWith(identifiersInScope); actionParams.UsedIdentifiers = identifiersInBlock; } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToNewComponentCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs similarity index 96% rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToNewComponentCodeActionResolver.cs rename to src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs index 460619bc3cd..08dc291761a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToNewComponentCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToComponentCodeActionResolver.cs @@ -26,7 +26,8 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor; -internal sealed class ExtractToNewComponentCodeActionResolver( +internal sealed class ExtractToComponentCodeActionResolver + ( IDocumentContextFactory documentContextFactory, LanguageServerFeatureOptions languageServerFeatureOptions) : IRazorCodeActionResolver { @@ -107,9 +108,7 @@ internal sealed class ExtractToNewComponentCodeActionResolver( End = new Position(end.Line, end.Character) }; - - - var componentDocumentIdentifier = new OptionalVersionedTextDocumentIdentifier { Uri = actionParams.Uri }; + var componentDocumentIdentifier = new OptionalVersionedTextDocumentIdentifier { Uri = actionParams.Uri }; var newComponentDocumentIdentifier = new OptionalVersionedTextDocumentIdentifier { Uri = newComponentUri }; var documentChanges = new SumType[] diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/RazorCodeActionFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/RazorCodeActionFactory.cs index 6a7d697c1ca..f9f4a94cd27 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/RazorCodeActionFactory.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/RazorCodeActionFactory.cs @@ -14,7 +14,7 @@ internal static class RazorCodeActionFactory private readonly static Guid s_fullyQualifyComponentTelemetryId = new("3d9abe36-7d10-4e08-8c18-ad88baa9a923"); private readonly static Guid s_createComponentFromTagTelemetryId = new("a28e0baa-a4d5-4953-a817-1db586035841"); private readonly static Guid s_createExtractToCodeBehindTelemetryId = new("f63167f7-fdc6-450f-8b7b-b240892f4a27"); - private readonly static Guid s_createExtractToNewComponentTelemetryId = new("af67b0a3-f84b-4808-97a7-b53e85b22c64"); + private readonly static Guid s_createExtractToComponentTelemetryId = new("af67b0a3-f84b-4808-97a7-b53e85b22c64"); private readonly static Guid s_generateMethodTelemetryId = new("c14fa003-c752-45fc-bb29-3a123ae5ecef"); private readonly static Guid s_generateAsyncMethodTelemetryId = new("9058ca47-98e2-4f11-bf7c-a16a444dd939"); @@ -68,15 +68,15 @@ public static RazorVSInternalCodeAction CreateExtractToCodeBehind(RazorCodeActio return codeAction; } - public static RazorVSInternalCodeAction CreateExtractToNewComponent(RazorCodeActionResolutionParams resolutionParams) + public static RazorVSInternalCodeAction CreateExtractToComponent(RazorCodeActionResolutionParams resolutionParams) { - var title = SR.ExtractTo_NewComponent_Title; + var title = SR.ExtractTo_Component_Title; var data = JsonSerializer.SerializeToElement(resolutionParams); var codeAction = new RazorVSInternalCodeAction() { Title = title, Data = data, - TelemetryId = s_createExtractToNewComponentTelemetryId, + TelemetryId = s_createExtractToComponentTelemetryId, }; return codeAction; } 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 59707cbcd56..b832b54216e 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) // Razor Code actions services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); 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 b94c06607a4..cd69afc13d3 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/SR.resx +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/SR.resx @@ -183,7 +183,7 @@ 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 e9bd2e979f3..de1af9b86ea 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 @@ -47,7 +47,7 @@ Extrahovat blok do kódu na pozadí - + Extract element to new component Extract element to new component 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 94402ecb4de..7da645a36d2 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 @@ -47,7 +47,7 @@ Block auf CodeBehind extrahieren - + Extract element to new component Extract element to new component 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 3e5b8b11c1e..72e2980b035 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 @@ -47,7 +47,7 @@ Extraer el bloque al código subyacente - + Extract element to new component Extract element to new component 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 4808f1c26a4..0c3ee61e8de 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 @@ -47,7 +47,7 @@ Extraire le bloc vers le code-behind - + Extract element to new component Extract element to new component 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 33470714554..20333e772ac 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 @@ -47,7 +47,7 @@ Estrai il blocco in code-behind - + Extract element to new component Extract element to new component 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 fd8f4765763..6016bbea305 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 @@ -47,7 +47,7 @@ ブロック抽出から分離コード - + Extract element to new component Extract element to new component 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 62d14e8d091..4579e5803b2 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 @@ -47,7 +47,7 @@ 코드 숨김에 블록 추출 - + Extract element to new component Extract element to new component 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 b5ca44e0fb3..765d2f018bc 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 @@ -47,7 +47,7 @@ Wyodrębnij blok do kodu znajdującego się poza - + Extract element to new component Extract element to new component 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 023270c89c0..62ad6fd0364 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 @@ -47,7 +47,7 @@ Extrair o bloco para codificar atrás - + Extract element to new component Extract element to new component 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 9b4b541b350..df1d6913ba1 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 @@ -47,7 +47,7 @@ Извлечь блок в код программной части - + Extract element to new component Extract element to new component 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 211840b046c..002635c7ab8 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 @@ -47,7 +47,7 @@ Bloğu arkadaki koda ayıkla - + Extract element to new component Extract element to new component 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 c746d3ecc08..c75b40f673c 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 @@ -47,7 +47,7 @@ 将块提取到代码隐藏中 - + Extract element to new component Extract element to new component 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 ddd96b48565..588a1945b6c 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 @@ -47,7 +47,7 @@ 擷取區塊以在後方編碼 - + Extract element to new component Extract element to new component diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToNewComponentCodeActionProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionProviderTest.cs similarity index 95% rename from src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToNewComponentCodeActionProviderTest.cs rename to src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionProviderTest.cs index f2d6ebe666b..caaf2f20eb3 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToNewComponentCodeActionProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToComponentCodeActionProviderTest.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions.Razor; -public class ExtractToNewComponentCodeActionProviderTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput) +public class ExtractToComponentCodeActionProviderTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput) { [Fact] public async Task Handle_InvalidFileKind() @@ -63,7 +63,7 @@ public async Task Handle_InvalidFileKind() var context = CreateRazorCodeActionContext(request, location, documentPath, contents); context.CodeDocument.SetFileKind(FileKinds.Legacy); - var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory); + var provider = new ExtractToComponentCodeActionProvider(LoggerFactory); // Act var commandOrCodeActionContainer = await provider.ProvideAsync(context, default); @@ -109,7 +109,7 @@ public async Task Handle_SinglePointSelection_ReturnsNotEmpty() var location = new SourceLocation(cursorPosition, -1, -1); var context = CreateRazorCodeActionContext(request, location, documentPath, contents); - var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory); + var provider = new ExtractToComponentCodeActionProvider(LoggerFactory); // Act var commandOrCodeActionContainer = await provider.ProvideAsync(context, default); @@ -165,7 +165,7 @@ public string someFunc(int num) { var location = new SourceLocation(cursorPosition, -1, -1); var context = CreateRazorCodeActionContext(request, location, documentPath, contents); - var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory); + var provider = new ExtractToComponentCodeActionProvider(LoggerFactory); // Act var commandOrCodeActionContainer = await provider.ProvideAsync(context, default); @@ -217,7 +217,7 @@ public async Task Handle_MultiPointSelection_ReturnsNotEmpty() var context = CreateRazorCodeActionContext(request, location, documentPath, contents); AddMultiPointSelectionToContext(ref context, selectionSpan); - var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory); + var provider = new ExtractToComponentCodeActionProvider(LoggerFactory); // Act var commandOrCodeActionContainer = await provider.ProvideAsync(context, default); @@ -273,7 +273,7 @@ namespace MarketApp.Pages.Product.Home AddMultiPointSelectionToContext(ref context, selectionSpan); - var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory); + var provider = new ExtractToComponentCodeActionProvider(LoggerFactory); // Act var commandOrCodeActionContainer = await provider.ProvideAsync(context, default); @@ -324,7 +324,7 @@ public async Task Handle_InProperMarkup_ReturnsEmpty() var location = new SourceLocation(cursorPosition, -1, -1); var context = CreateRazorCodeActionContext(request, location, documentPath, contents); - var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory); + var provider = new ExtractToComponentCodeActionProvider(LoggerFactory); // Act var commandOrCodeActionContainer = await provider.ProvideAsync(context, default);