Skip to content

Commit b170f2a

Browse files
committed
More PR Feedback
1 parent 33c66f4 commit b170f2a

File tree

3 files changed

+6
-43
lines changed

3 files changed

+6
-43
lines changed

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/ExtractToComponentCodeActionParams.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ internal sealed class ExtractToComponentCodeActionParams
2323
[JsonPropertyName("namespace")]
2424
public required string Namespace { get; set; }
2525

26-
[JsonPropertyName("dependencies")]
27-
public required List<string> Dependencies { get; set; }
28-
29-
[JsonPropertyName("usedIdentifiers")]
30-
public required HashSet<string> UsedIdentifiers { get; set; }
31-
32-
[JsonPropertyName("usedMembers")]
33-
public required HashSet<string> UsedMembers { get; set; }
26+
[JsonPropertyName("usingDirectives")]
27+
public required List<string> usingDirectives { get; set; }
3428
}

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

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeAct
7878
actionParams.ExtractStart,
7979
actionParams.ExtractEnd,
8080
actionParams);
81-
GetUsedIdentifiers(utilityScanRoot, syntaxTree.Root, actionParams);
8281

8382
var resolutionParams = new RazorCodeActionResolutionParams()
8483
{
@@ -156,9 +155,7 @@ private static ExtractToComponentCodeActionParams CreateInitialActionParams(Razo
156155
ExtractStart = startElementNode.Span.Start,
157156
ExtractEnd = startElementNode.Span.End,
158157
Namespace = @namespace,
159-
Dependencies = [],
160-
UsedIdentifiers = [],
161-
UsedMembers = [],
158+
usingDirectives = []
162159
};
163160
}
164161

@@ -303,36 +300,8 @@ private static void AddDependenciesFromTagHelperInfo(TagHelperInfo tagHelperInfo
303300
var typeNamespace = descriptor.GetTypeNamespace();
304301
if (components.Add(typeNamespace))
305302
{
306-
actionParams.Dependencies.Add($"@using {typeNamespace}");
303+
actionParams.usingDirectives.Add($"@using {typeNamespace}");
307304
}
308305
}
309306
}
310-
311-
private static void GetUsedIdentifiers(SyntaxNode divNode, SyntaxNode documentRoot, ExtractToComponentCodeActionParams actionParams)
312-
{
313-
HashSet<string> identifiersInScope = [];
314-
HashSet<string> identifiersInBlock = [];
315-
316-
HashSet<SyntaxNode> nodesInScope = [];
317-
HashSet<SyntaxNode> nodesInBlock = [];
318-
319-
foreach (var node in divNode.DescendantNodes().Where(static node => node.Kind is SyntaxKind.Identifier))
320-
{
321-
identifiersInScope.Add(node.GetContent());
322-
nodesInScope.Add(node);
323-
}
324-
325-
foreach (var codeBlock in documentRoot.DescendantNodes().Where(static node => node.Kind is SyntaxKind.RazorDirective))
326-
{
327-
foreach (var node in codeBlock.DescendantNodes().Where(static node => node.Kind is SyntaxKind.Identifier))
328-
{
329-
identifiersInBlock.Add(node.GetContent());
330-
nodesInBlock.Add(node);
331-
}
332-
}
333-
334-
nodesInBlock.IntersectWith(nodesInScope);
335-
identifiersInBlock.IntersectWith(identifiersInScope);
336-
actionParams.UsedIdentifiers = identifiersInBlock;
337-
}
338307
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ internal sealed class ExtractToComponentCodeActionResolver
9393
var componentName = Path.GetFileNameWithoutExtension(componentPath);
9494
var newComponentContent = string.Empty;
9595

96-
newComponentContent += string.Join(Environment.NewLine, actionParams.Dependencies);
97-
if (actionParams.Dependencies.Count > 0)
96+
newComponentContent += string.Join(Environment.NewLine, actionParams.usingDirectives);
97+
if (actionParams.usingDirectives.Count > 0)
9898
{
9999
newComponentContent += Environment.NewLine + Environment.NewLine; // Ensure there's a newline after the dependencies if any exist.
100100
}

0 commit comments

Comments
 (0)