Skip to content

Commit de3aefe

Browse files
committed
Removed unnecessary usings and separated end to end tests
1 parent 26301c4 commit de3aefe

File tree

4 files changed

+464
-442
lines changed

4 files changed

+464
-442
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ private static bool IsValidContext(RazorCodeActionContext context)
7979
context.CodeDocument.GetSyntaxTree()?.Root is not null;
8080
}
8181

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

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

+6-14
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,18 @@
4040
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
4141
using System.Reflection.Metadata.Ecma335;
4242
using Microsoft.VisualStudio.Utilities;
43-
using System.Text.RegularExpressions;
4443

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

4746
internal sealed class ExtractToComponentCodeActionResolver(
4847
IDocumentContextFactory documentContextFactory,
49-
RazorLSPOptionsMonitor razorLSPOptionsMonitor,
5048
LanguageServerFeatureOptions languageServerFeatureOptions,
5149
IClientConnection clientConnection,
52-
IRazorFormattingService razorFormattingService,
5350
IDocumentVersionCache documentVersionCache) : IRazorCodeActionResolver
5451
{
55-
private static readonly Workspace s_workspace = new AdhocWorkspace();
56-
5752
private readonly IDocumentContextFactory _documentContextFactory = documentContextFactory;
58-
private readonly RazorLSPOptionsMonitor _razorLSPOptionsMonitor = razorLSPOptionsMonitor;
5953
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions;
6054
private readonly IClientConnection _clientConnection = clientConnection;
61-
private readonly IRazorFormattingService _razorFormattingService = razorFormattingService;
6255
private readonly IDocumentVersionCache _documentVersionCache = documentVersionCache;
6356

6457
public string Action => LanguageServerConstants.CodeActions.ExtractToComponentAction;
@@ -95,7 +88,7 @@ internal sealed class ExtractToComponentCodeActionResolver(
9588

9689
// For the purposes of determining the indentation of the extracted code, get the whitespace before the start of the selection.
9790
var whitespaceReferenceOwner = codeDocument.GetSyntaxTree().Root.FindInnermostNode(selectionAnalysis.ExtractStart, includeWhitespace: true).AssumeNotNull();
98-
var whitespaceReferenceNode = whitespaceReferenceOwner.FirstAncestorOrSelf<MarkupSyntaxNode>(node => node is MarkupElementSyntax or MarkupTagHelperElementSyntax);
91+
var whitespaceReferenceNode = whitespaceReferenceOwner.FirstAncestorOrSelf<MarkupSyntaxNode>(node => node is MarkupElementSyntax or MarkupTagHelperElementSyntax).AssumeNotNull();
9992
var whitespace = string.Empty;
10093
if (whitespaceReferenceNode.TryGetPreviousSibling(out var startPreviousSibling) && startPreviousSibling.ContainsOnlyWhitespace())
10194
{
@@ -130,7 +123,7 @@ internal sealed class ExtractToComponentCodeActionResolver(
130123
}.Uri;
131124

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

135128
if (newComponentResult is null)
136129
{
@@ -510,7 +503,6 @@ private static void AddUsingFromTagHelperInfo(TagHelperInfo tagHelperInfo, HashS
510503
Uri componentUri,
511504
DocumentContext documentContext,
512505
Range relevantRange,
513-
Uri newComponentUri,
514506
string whitespace,
515507
CancellationToken cancellationToken)
516508
{
@@ -547,7 +539,7 @@ private static void AddUsingFromTagHelperInfo(TagHelperInfo tagHelperInfo, HashS
547539
var line = extractedLines[i];
548540
if (line.StartsWith(whitespace, StringComparison.Ordinal))
549541
{
550-
extractedLines[i] = line.Substring(whitespace.Length);
542+
extractedLines[i] = line[whitespace.Length..];
551543
}
552544
}
553545

@@ -593,13 +585,12 @@ private static void AddUsingFromTagHelperInfo(TagHelperInfo tagHelperInfo, HashS
593585

594586
// I'm not sure why, but for some reason the endCharacterIndex is lower than the CharacterIndex so they must be swapped.
595587
var intersectingGeneratedRanges = intersectingGeneratedSpans.Select(m =>
596-
(
597588
new Range
598589
{
599590
Start = new Position(m.LineIndex, m.EndCharacterIndex),
600591
End = new Position(m.LineIndex, m.CharacterIndex)
601592
}
602-
)).ToArray();
593+
).ToArray();
603594

604595
var parameters = new GetSymbolicInfoParams()
605596
{
@@ -784,7 +775,7 @@ private static string GeneratePromotedMethods(HashSet<MethodSymbolicInfo> method
784775
// If delegate type is Action, only add generic parameters if needed.
785776
if (method.ParameterTypes.Length > 0 || method.ReturnType != "void")
786777
{
787-
builder.Append("<");
778+
builder.Append('<');
788779
builder.Append(string.Join(", ", method.ParameterTypes));
789780

790781
if (method.ReturnType != "void")
@@ -794,6 +785,7 @@ private static string GeneratePromotedMethods(HashSet<MethodSymbolicInfo> method
794785
// Add one last comma in the list of generic parameters for the result: "<..., TResult>"
795786
builder.Append(", ");
796787
}
788+
797789
builder.Append(method.ReturnType);
798790
}
799791

0 commit comments

Comments
 (0)