Skip to content

Commit 0f547f3

Browse files
committed
Removed unnecessary usings and separated end to end tests
1 parent 96221e5 commit 0f547f3

File tree

4 files changed

+464
-474
lines changed

4 files changed

+464
-474
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ private static bool IsValidContext(RazorCodeActionContext context)
8080
context.CodeDocument.GetSyntaxTree()?.Root is not null;
8181
}
8282

83-
private static bool IsSelectionValid(RazorCodeActionContext context, RazorSyntaxTree syntaxTree)
83+
private bool IsSelectionValid(RazorCodeActionContext context, RazorSyntaxTree syntaxTree)
8484
{
8585
var owner = syntaxTree.Root.FindInnermostNode(context.Location.AbsoluteIndex, includeWhitespace: true);
8686
if (owner is null)
8787
{
88+
_logger.LogWarning($"Owner should never be null.");
8889
return false;
8990
}
9091

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;
4646

4747
internal sealed class ExtractToComponentCodeActionResolver(
4848
IDocumentContextFactory documentContextFactory,
49-
RazorLSPOptionsMonitor razorLSPOptionsMonitor,
5049
LanguageServerFeatureOptions languageServerFeatureOptions,
5150
IClientConnection clientConnection,
52-
IRazorFormattingService razorFormattingService,
5351
IDocumentVersionCache documentVersionCache) : IRazorCodeActionResolver
5452
{
55-
private static readonly Workspace s_workspace = new AdhocWorkspace();
56-
5753
private readonly IDocumentContextFactory _documentContextFactory = documentContextFactory;
58-
private readonly RazorLSPOptionsMonitor _razorLSPOptionsMonitor = razorLSPOptionsMonitor;
5954
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions;
6055
private readonly IClientConnection _clientConnection = clientConnection;
61-
private readonly IRazorFormattingService _razorFormattingService = razorFormattingService;
6256
private readonly IDocumentVersionCache _documentVersionCache = documentVersionCache;
6357

6458
public string Action => LanguageServerConstants.CodeActions.ExtractToComponentAction;
@@ -95,7 +89,7 @@ internal sealed class ExtractToComponentCodeActionResolver(
9589

9690
// For the purposes of determining the indentation of the extracted code, get the whitespace before the start of the selection.
9791
var whitespaceReferenceOwner = codeDocument.GetSyntaxTree().Root.FindInnermostNode(selectionAnalysis.ExtractStart, includeWhitespace: true).AssumeNotNull();
98-
var whitespaceReferenceNode = whitespaceReferenceOwner.FirstAncestorOrSelf<MarkupSyntaxNode>(node => node is MarkupElementSyntax or MarkupTagHelperElementSyntax);
92+
var whitespaceReferenceNode = whitespaceReferenceOwner.FirstAncestorOrSelf<MarkupSyntaxNode>(node => node is MarkupElementSyntax or MarkupTagHelperElementSyntax).AssumeNotNull();
9993
var whitespace = string.Empty;
10094
if (whitespaceReferenceNode.TryGetPreviousSibling(out var startPreviousSibling) && startPreviousSibling.ContainsOnlyWhitespace())
10195
{
@@ -130,7 +124,7 @@ internal sealed class ExtractToComponentCodeActionResolver(
130124
}.Uri;
131125

132126
var componentName = Path.GetFileNameWithoutExtension(componentPath);
133-
var newComponentResult = await GenerateNewComponentAsync(selectionAnalysis, codeDocument, actionParams.Uri, documentContext, removeRange, newComponentUri, whitespace, cancellationToken).ConfigureAwait(false);
127+
var newComponentResult = await GenerateNewComponentAsync(selectionAnalysis, codeDocument, actionParams.Uri, documentContext, removeRange, whitespace, cancellationToken).ConfigureAwait(false);
134128

135129
if (newComponentResult is null)
136130
{
@@ -510,7 +504,6 @@ private static void AddUsingFromTagHelperInfo(TagHelperInfo tagHelperInfo, HashS
510504
Uri componentUri,
511505
DocumentContext documentContext,
512506
Range relevantRange,
513-
Uri newComponentUri,
514507
string whitespace,
515508
CancellationToken cancellationToken)
516509
{
@@ -547,7 +540,7 @@ private static void AddUsingFromTagHelperInfo(TagHelperInfo tagHelperInfo, HashS
547540
var line = extractedLines[i];
548541
if (line.StartsWith(whitespace, StringComparison.Ordinal))
549542
{
550-
extractedLines[i] = line.Substring(whitespace.Length);
543+
extractedLines[i] = line[whitespace.Length..];
551544
}
552545
}
553546

@@ -593,13 +586,12 @@ private static void AddUsingFromTagHelperInfo(TagHelperInfo tagHelperInfo, HashS
593586

594587
// I'm not sure why, but for some reason the endCharacterIndex is lower than the CharacterIndex so they must be swapped.
595588
var intersectingGeneratedRanges = intersectingGeneratedSpans.Select(m =>
596-
(
597589
new Range
598590
{
599591
Start = new Position(m.LineIndex, m.EndCharacterIndex),
600592
End = new Position(m.LineIndex, m.CharacterIndex)
601593
}
602-
)).ToArray();
594+
).ToArray();
603595

604596
var parameters = new GetSymbolicInfoParams()
605597
{
@@ -784,7 +776,7 @@ private static string GeneratePromotedMethods(HashSet<MethodSymbolicInfo> method
784776
// If delegate type is Action, only add generic parameters if needed.
785777
if (method.ParameterTypes.Length > 0 || method.ReturnType != "void")
786778
{
787-
builder.Append("<");
779+
builder.Append('<');
788780
builder.Append(string.Join(", ", method.ParameterTypes));
789781

790782
if (method.ReturnType != "void")
@@ -794,6 +786,7 @@ private static string GeneratePromotedMethods(HashSet<MethodSymbolicInfo> method
794786
// Add one last comma in the list of generic parameters for the result: "<..., TResult>"
795787
builder.Append(", ");
796788
}
789+
797790
builder.Append(method.ReturnType);
798791
}
799792

0 commit comments

Comments
 (0)