Skip to content

Commit fb61c9c

Browse files
committed
Nits
1 parent 24b70db commit fb61c9c

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeAct
5151
return SpecializedTasks.EmptyImmutableArray<RazorVSInternalCodeAction>();
5252
}
5353

54-
var (startElementNode, endElementNode) = GetStartAndEndElements(context, syntaxTree, _logger);
55-
5654
// Make sure the selection starts on an element tag
55+
var (startElementNode, endElementNode) = GetStartAndEndElements(context, syntaxTree, _logger);
5756
if (startElementNode is null)
5857
{
5958
return SpecializedTasks.EmptyImmutableArray<RazorVSInternalCodeAction>();
@@ -71,7 +70,7 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeAct
7170
AddComponentDependenciesInRange(dependencyScanRoot,
7271
actionParams.ExtractStart,
7372
actionParams.ExtractEnd,
74-
ref actionParams);
73+
actionParams);
7574

7675
if (IsMultiPointSelection(context.Request.Range))
7776
{
@@ -288,7 +287,7 @@ private static (SyntaxNode? Start, SyntaxNode? End) FindContainingSiblingPair(Sy
288287
return null;
289288
}
290289

291-
private static void AddComponentDependenciesInRange(SyntaxNode root, int extractStart, int extractEnd, ref ExtractToNewComponentCodeActionParams actionParams)
290+
private static void AddComponentDependenciesInRange(SyntaxNode root, int extractStart, int extractEnd, ExtractToNewComponentCodeActionParams actionParams)
292291
{
293292
var components = new HashSet<string>();
294293
var extractSpan = new TextSpan(extractStart, extractEnd - extractStart);
@@ -300,7 +299,7 @@ private static void AddComponentDependenciesInRange(SyntaxNode root, int extract
300299
var tagHelperInfo = GetTagHelperInfo(node);
301300
if (tagHelperInfo != null)
302301
{
303-
AddDependenciesFromTagHelperInfo(tagHelperInfo, components, ref actionParams);
302+
AddDependenciesFromTagHelperInfo(tagHelperInfo, components, actionParams);
304303
}
305304
}
306305
}
@@ -322,7 +321,7 @@ private static bool IsMarkupTagHelperElement(SyntaxNode node, TextSpan extractSp
322321
return null;
323322
}
324323

325-
private static void AddDependenciesFromTagHelperInfo(TagHelperInfo tagHelperInfo, HashSet<string> components, ref ExtractToNewComponentCodeActionParams actionParams)
324+
private static void AddDependenciesFromTagHelperInfo(TagHelperInfo tagHelperInfo, HashSet<string> components, ExtractToNewComponentCodeActionParams actionParams)
326325
{
327326
foreach (var descriptor in tagHelperInfo.BindingResult.Descriptors)
328327
{

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToNewComponentCodeActionProviderTest.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public async Task Handle_InProperMarkup_ReturnsEmpty()
232232
// Arrange
233233
var documentPath = "c:/Test.razor";
234234
var contents = """
235-
page "/"
235+
@page "/"
236236
237237
<PageTitle>Home</PageTitle>
238238
@@ -289,7 +289,7 @@ private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionP
289289
codeDocument.SetFileKind(FileKinds.Component);
290290
codeDocument.SetCodeGenerationOptions(RazorCodeGenerationOptions.Create(o =>
291291
{
292-
o.RootNamespace = "ExtractToCodeBehindTest";
292+
o.RootNamespace = "ExtractToNewComponentTest";
293293
}));
294294
codeDocument.SetSyntaxTree(syntaxTree);
295295

@@ -304,6 +304,34 @@ private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionP
304304
return context;
305305
}
306306

307+
//private static IDocumentSnapshot CreateSupplementaryRazorFile(string filePath, string text, bool supportsFileCreation = true)
308+
// => CreateSupplementaryRazorFile(filePath, text, relativePath: filePath, supportsFileCreation: supportsFileCreation);
309+
310+
//private static IDocumentSnapshot CreateSupplementaryRazorFile(string filePath, string text, string? relativePath, bool supportsFileCreation = true)
311+
//{
312+
// var sourceDocument = RazorSourceDocument.Create(text, RazorSourceDocumentProperties.Create(filePath, relativePath));
313+
// var options = RazorParserOptions.Create(o =>
314+
// {
315+
// o.Directives.Add(ComponentCodeDirective.Directive);
316+
// o.Directives.Add(FunctionsDirective.Directive);
317+
// });
318+
// var syntaxTree = RazorSyntaxTree.Parse(sourceDocument, options);
319+
320+
// var codeDocument = TestRazorCodeDocument.Create(sourceDocument, imports: default);
321+
// codeDocument.SetFileKind(FileKinds.Component);
322+
// codeDocument.SetCodeGenerationOptions(RazorCodeGenerationOptions.Create(o =>
323+
// {
324+
// o.RootNamespace = "ExtractToNewComponentTest";
325+
// }));
326+
// codeDocument.SetSyntaxTree(syntaxTree);
327+
328+
// var documentSnapshot = Mock.Of<IDocumentSnapshot>(document =>
329+
// document.GetGeneratedOutputAsync() == Task.FromResult(codeDocument) &&
330+
// document.GetTextAsync() == Task.FromResult(codeDocument.GetSourceText()), MockBehavior.Strict);
331+
332+
// return documentSnapshot;
333+
//}
334+
307335
private static void AddMultiPointSelectionToContext(ref RazorCodeActionContext context, TextSpan selectionSpan)
308336
{
309337
var sourceText = context.CodeDocument.GetSourceText();

0 commit comments

Comments
 (0)