@@ -46,19 +46,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;
46
46
47
47
internal sealed class ExtractToComponentCodeActionResolver (
48
48
IDocumentContextFactory documentContextFactory ,
49
- RazorLSPOptionsMonitor razorLSPOptionsMonitor ,
50
49
LanguageServerFeatureOptions languageServerFeatureOptions ,
51
50
IClientConnection clientConnection ,
52
- IRazorFormattingService razorFormattingService ,
53
51
IDocumentVersionCache documentVersionCache ) : IRazorCodeActionResolver
54
52
{
55
- private static readonly Workspace s_workspace = new AdhocWorkspace ( ) ;
56
-
57
53
private readonly IDocumentContextFactory _documentContextFactory = documentContextFactory ;
58
- private readonly RazorLSPOptionsMonitor _razorLSPOptionsMonitor = razorLSPOptionsMonitor ;
59
54
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions ;
60
55
private readonly IClientConnection _clientConnection = clientConnection ;
61
- private readonly IRazorFormattingService _razorFormattingService = razorFormattingService ;
62
56
private readonly IDocumentVersionCache _documentVersionCache = documentVersionCache ;
63
57
64
58
public string Action => LanguageServerConstants . CodeActions . ExtractToComponentAction ;
@@ -95,7 +89,7 @@ internal sealed class ExtractToComponentCodeActionResolver(
95
89
96
90
// For the purposes of determining the indentation of the extracted code, get the whitespace before the start of the selection.
97
91
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 ( ) ;
99
93
var whitespace = string . Empty ;
100
94
if ( whitespaceReferenceNode . TryGetPreviousSibling ( out var startPreviousSibling ) && startPreviousSibling . ContainsOnlyWhitespace ( ) )
101
95
{
@@ -130,7 +124,7 @@ internal sealed class ExtractToComponentCodeActionResolver(
130
124
} . Uri ;
131
125
132
126
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 ) ;
134
128
135
129
if ( newComponentResult is null )
136
130
{
@@ -510,7 +504,6 @@ private static void AddUsingFromTagHelperInfo(TagHelperInfo tagHelperInfo, HashS
510
504
Uri componentUri ,
511
505
DocumentContext documentContext ,
512
506
Range relevantRange ,
513
- Uri newComponentUri ,
514
507
string whitespace ,
515
508
CancellationToken cancellationToken )
516
509
{
@@ -547,7 +540,7 @@ private static void AddUsingFromTagHelperInfo(TagHelperInfo tagHelperInfo, HashS
547
540
var line = extractedLines [ i ] ;
548
541
if ( line . StartsWith ( whitespace , StringComparison . Ordinal ) )
549
542
{
550
- extractedLines [ i ] = line . Substring ( whitespace . Length ) ;
543
+ extractedLines [ i ] = line [ whitespace . Length .. ] ;
551
544
}
552
545
}
553
546
@@ -593,13 +586,12 @@ private static void AddUsingFromTagHelperInfo(TagHelperInfo tagHelperInfo, HashS
593
586
594
587
// I'm not sure why, but for some reason the endCharacterIndex is lower than the CharacterIndex so they must be swapped.
595
588
var intersectingGeneratedRanges = intersectingGeneratedSpans . Select ( m =>
596
- (
597
589
new Range
598
590
{
599
591
Start = new Position ( m . LineIndex , m . EndCharacterIndex ) ,
600
592
End = new Position ( m . LineIndex , m . CharacterIndex )
601
593
}
602
- ) ) . ToArray ( ) ;
594
+ ) . ToArray ( ) ;
603
595
604
596
var parameters = new GetSymbolicInfoParams ( )
605
597
{
@@ -784,7 +776,7 @@ private static string GeneratePromotedMethods(HashSet<MethodSymbolicInfo> method
784
776
// If delegate type is Action, only add generic parameters if needed.
785
777
if ( method . ParameterTypes . Length > 0 || method . ReturnType != "void" )
786
778
{
787
- builder . Append ( "<" ) ;
779
+ builder . Append ( '<' ) ;
788
780
builder . Append ( string . Join ( ", " , method . ParameterTypes ) ) ;
789
781
790
782
if ( method . ReturnType != "void" )
@@ -794,6 +786,7 @@ private static string GeneratePromotedMethods(HashSet<MethodSymbolicInfo> method
794
786
// Add one last comma in the list of generic parameters for the result: "<..., TResult>"
795
787
builder . Append ( ", " ) ;
796
788
}
789
+
797
790
builder . Append ( method . ReturnType ) ;
798
791
}
799
792
0 commit comments