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