Skip to content

Commit 3506612

Browse files
committed
Corrected naming and nits
1 parent 02e4e99 commit 3506612

File tree

19 files changed

+39
-35
lines changed

19 files changed

+39
-35
lines changed
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
2-
// Licensed under the MIT license. See License.txt in the project divNode for license information.
2+
// Licensed under the MIT license. See License.txt in the project root for license information.
33

44
using System;
55
using System.Collections.Generic;
@@ -25,9 +25,9 @@
2525

2626
namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor;
2727

28-
internal sealed class ExtractToNewComponentCodeActionProvider(ILoggerFactory loggerFactory) : IRazorCodeActionProvider
28+
internal sealed class ExtractToComponentCodeActionProvider(ILoggerFactory loggerFactory) : IRazorCodeActionProvider
2929
{
30-
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<ExtractToNewComponentCodeActionProvider>();
30+
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<ExtractToComponentCodeActionProvider>();
3131

3232
public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeActionContext context, CancellationToken cancellationToken)
3333
{
@@ -90,7 +90,7 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeAct
9090
Data = actionParams,
9191
};
9292

93-
var codeAction = RazorCodeActionFactory.CreateExtractToNewComponent(resolutionParams);
93+
var codeAction = RazorCodeActionFactory.CreateExtractToComponent(resolutionParams);
9494
return Task.FromResult<ImmutableArray<RazorVSInternalCodeAction>>([codeAction]);
9595
}
9696

@@ -352,20 +352,25 @@ private static void GetUsedIdentifiers(SyntaxNode divNode, SyntaxNode documentRo
352352
HashSet<string> identifiersInScope = [];
353353
HashSet<string> identifiersInBlock = [];
354354

355+
HashSet<SyntaxNode> nodesInScope = [];
356+
HashSet<SyntaxNode> nodesInBlock = [];
355357

356358
foreach (var node in divNode.DescendantNodes().Where(static node => node.Kind is SyntaxKind.Identifier))
357359
{
358360
identifiersInScope.Add(node.GetContent());
361+
nodesInScope.Add(node);
359362
}
360363

361364
foreach (var codeBlock in documentRoot.DescendantNodes().Where(static node => node.Kind is SyntaxKind.RazorDirective))
362365
{
363366
foreach (var node in codeBlock.DescendantNodes().Where(static node => node.Kind is SyntaxKind.Identifier))
364367
{
365368
identifiersInBlock.Add(node.GetContent());
369+
nodesInBlock.Add(node);
366370
}
367371
}
368372

373+
nodesInBlock.IntersectWith(nodesInScope);
369374
identifiersInBlock.IntersectWith(identifiersInScope);
370375
actionParams.UsedIdentifiers = identifiersInBlock;
371376
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor;
2828

29-
internal sealed class ExtractToNewComponentCodeActionResolver(
29+
internal sealed class ExtractToComponentCodeActionResolver
30+
(
3031
IDocumentContextFactory documentContextFactory,
3132
LanguageServerFeatureOptions languageServerFeatureOptions) : IRazorCodeActionResolver
3233
{
@@ -107,9 +108,7 @@ internal sealed class ExtractToNewComponentCodeActionResolver(
107108
End = new Position(end.Line, end.Character)
108109
};
109110

110-
111-
112-
var componentDocumentIdentifier = new OptionalVersionedTextDocumentIdentifier { Uri = actionParams.Uri };
111+
var componentDocumentIdentifier = new OptionalVersionedTextDocumentIdentifier { Uri = actionParams.Uri };
113112
var newComponentDocumentIdentifier = new OptionalVersionedTextDocumentIdentifier { Uri = newComponentUri };
114113

115114
var documentChanges = new SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>[]

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/RazorCodeActionFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal static class RazorCodeActionFactory
1414
private readonly static Guid s_fullyQualifyComponentTelemetryId = new("3d9abe36-7d10-4e08-8c18-ad88baa9a923");
1515
private readonly static Guid s_createComponentFromTagTelemetryId = new("a28e0baa-a4d5-4953-a817-1db586035841");
1616
private readonly static Guid s_createExtractToCodeBehindTelemetryId = new("f63167f7-fdc6-450f-8b7b-b240892f4a27");
17-
private readonly static Guid s_createExtractToNewComponentTelemetryId = new("af67b0a3-f84b-4808-97a7-b53e85b22c64");
17+
private readonly static Guid s_createExtractToComponentTelemetryId = new("af67b0a3-f84b-4808-97a7-b53e85b22c64");
1818
private readonly static Guid s_generateMethodTelemetryId = new("c14fa003-c752-45fc-bb29-3a123ae5ecef");
1919
private readonly static Guid s_generateAsyncMethodTelemetryId = new("9058ca47-98e2-4f11-bf7c-a16a444dd939");
2020

@@ -68,15 +68,15 @@ public static RazorVSInternalCodeAction CreateExtractToCodeBehind(RazorCodeActio
6868
return codeAction;
6969
}
7070

71-
public static RazorVSInternalCodeAction CreateExtractToNewComponent(RazorCodeActionResolutionParams resolutionParams)
71+
public static RazorVSInternalCodeAction CreateExtractToComponent(RazorCodeActionResolutionParams resolutionParams)
7272
{
73-
var title = SR.ExtractTo_NewComponent_Title;
73+
var title = SR.ExtractTo_Component_Title;
7474
var data = JsonSerializer.SerializeToElement(resolutionParams);
7575
var codeAction = new RazorVSInternalCodeAction()
7676
{
7777
Title = title,
7878
Data = data,
79-
TelemetryId = s_createExtractToNewComponentTelemetryId,
79+
TelemetryId = s_createExtractToComponentTelemetryId,
8080
};
8181
return codeAction;
8282
}

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ public static void AddCodeActionsServices(this IServiceCollection services)
146146
// Razor Code actions
147147
services.AddSingleton<IRazorCodeActionProvider, ExtractToCodeBehindCodeActionProvider>();
148148
services.AddSingleton<IRazorCodeActionResolver, ExtractToCodeBehindCodeActionResolver>();
149-
services.AddSingleton<IRazorCodeActionProvider, ExtractToNewComponentCodeActionProvider>();
150-
services.AddSingleton<IRazorCodeActionResolver ,ExtractToNewComponentCodeActionResolver>();
149+
services.AddSingleton<IRazorCodeActionProvider, ExtractToComponentCodeActionProvider>();
150+
services.AddSingleton<IRazorCodeActionResolver ,ExtractToComponentCodeActionResolver>();
151151
services.AddSingleton<IRazorCodeActionProvider, ComponentAccessibilityCodeActionProvider>();
152152
services.AddSingleton<IRazorCodeActionResolver, CreateComponentCodeActionResolver>();
153153
services.AddSingleton<IRazorCodeActionResolver, AddUsingsCodeActionResolver>();

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/SR.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
<data name="Statement" xml:space="preserve">
184184
<value>statement</value>
185185
</data>
186-
<data name="ExtractTo_NewComponent_Title" xml:space="preserve">
186+
<data name="ExtractTo_Component_Title" xml:space="preserve">
187187
<value>Extract element to new component</value>
188188
</data>
189189
</root>

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.cs.xlf

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.de.xlf

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.es.xlf

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.fr.xlf

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.it.xlf

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ja.xlf

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ko.xlf

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pl.xlf

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.pt-BR.xlf

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.ru.xlf

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.tr.xlf

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hans.xlf

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Resources/xlf/SR.zh-Hant.xlf

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions.Razor;
2525

26-
public class ExtractToNewComponentCodeActionProviderTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput)
26+
public class ExtractToComponentCodeActionProviderTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput)
2727
{
2828
[Fact]
2929
public async Task Handle_InvalidFileKind()
@@ -63,7 +63,7 @@ public async Task Handle_InvalidFileKind()
6363
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);
6464
context.CodeDocument.SetFileKind(FileKinds.Legacy);
6565

66-
var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory);
66+
var provider = new ExtractToComponentCodeActionProvider(LoggerFactory);
6767

6868
// Act
6969
var commandOrCodeActionContainer = await provider.ProvideAsync(context, default);
@@ -109,7 +109,7 @@ public async Task Handle_SinglePointSelection_ReturnsNotEmpty()
109109
var location = new SourceLocation(cursorPosition, -1, -1);
110110
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);
111111

112-
var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory);
112+
var provider = new ExtractToComponentCodeActionProvider(LoggerFactory);
113113

114114
// Act
115115
var commandOrCodeActionContainer = await provider.ProvideAsync(context, default);
@@ -165,7 +165,7 @@ public string someFunc(int num) {
165165
var location = new SourceLocation(cursorPosition, -1, -1);
166166
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);
167167

168-
var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory);
168+
var provider = new ExtractToComponentCodeActionProvider(LoggerFactory);
169169

170170
// Act
171171
var commandOrCodeActionContainer = await provider.ProvideAsync(context, default);
@@ -217,7 +217,7 @@ public async Task Handle_MultiPointSelection_ReturnsNotEmpty()
217217
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);
218218
AddMultiPointSelectionToContext(ref context, selectionSpan);
219219

220-
var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory);
220+
var provider = new ExtractToComponentCodeActionProvider(LoggerFactory);
221221

222222
// Act
223223
var commandOrCodeActionContainer = await provider.ProvideAsync(context, default);
@@ -273,7 +273,7 @@ namespace MarketApp.Pages.Product.Home
273273

274274
AddMultiPointSelectionToContext(ref context, selectionSpan);
275275

276-
var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory);
276+
var provider = new ExtractToComponentCodeActionProvider(LoggerFactory);
277277

278278
// Act
279279
var commandOrCodeActionContainer = await provider.ProvideAsync(context, default);
@@ -324,7 +324,7 @@ public async Task Handle_InProperMarkup_ReturnsEmpty()
324324
var location = new SourceLocation(cursorPosition, -1, -1);
325325
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);
326326

327-
var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory);
327+
var provider = new ExtractToComponentCodeActionProvider(LoggerFactory);
328328

329329
// Act
330330
var commandOrCodeActionContainer = await provider.ProvideAsync(context, default);

0 commit comments

Comments
 (0)