Skip to content

Commit

Permalink
Corrected naming and nits
Browse files Browse the repository at this point in the history
  • Loading branch information
marcarro committed Aug 5, 2024
1 parent 02e4e99 commit 3506612
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ExtractToNewComponentCodeActionProvider>();
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<ExtractToComponentCodeActionProvider>();

public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeActionContext context, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -90,7 +90,7 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeAct
Data = actionParams,
};

var codeAction = RazorCodeActionFactory.CreateExtractToNewComponent(resolutionParams);
var codeAction = RazorCodeActionFactory.CreateExtractToComponent(resolutionParams);
return Task.FromResult<ImmutableArray<RazorVSInternalCodeAction>>([codeAction]);
}

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

HashSet<SyntaxNode> nodesInScope = [];
HashSet<SyntaxNode> 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))
{
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

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

internal sealed class ExtractToNewComponentCodeActionResolver(
internal sealed class ExtractToComponentCodeActionResolver
(
IDocumentContextFactory documentContextFactory,
LanguageServerFeatureOptions languageServerFeatureOptions) : IRazorCodeActionResolver
{
Expand Down Expand Up @@ -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<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public static void AddCodeActionsServices(this IServiceCollection services)
// Razor Code actions
services.AddSingleton<IRazorCodeActionProvider, ExtractToCodeBehindCodeActionProvider>();
services.AddSingleton<IRazorCodeActionResolver, ExtractToCodeBehindCodeActionResolver>();
services.AddSingleton<IRazorCodeActionProvider, ExtractToNewComponentCodeActionProvider>();
services.AddSingleton<IRazorCodeActionResolver ,ExtractToNewComponentCodeActionResolver>();
services.AddSingleton<IRazorCodeActionProvider, ExtractToComponentCodeActionProvider>();
services.AddSingleton<IRazorCodeActionResolver ,ExtractToComponentCodeActionResolver>();
services.AddSingleton<IRazorCodeActionProvider, ComponentAccessibilityCodeActionProvider>();
services.AddSingleton<IRazorCodeActionResolver, CreateComponentCodeActionResolver>();
services.AddSingleton<IRazorCodeActionResolver, AddUsingsCodeActionResolver>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
<data name="Statement" xml:space="preserve">
<value>statement</value>
</data>
<data name="ExtractTo_NewComponent_Title" xml:space="preserve">
<data name="ExtractTo_Component_Title" xml:space="preserve">
<value>Extract element to new component</value>
</data>
</root>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3506612

Please sign in to comment.