@@ -38,7 +38,7 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeAct
38
38
}
39
39
40
40
var syntaxTree = context . CodeDocument . GetSyntaxTree ( ) ;
41
- if ( ! IsSelectionValid ( context , syntaxTree ) )
41
+ if ( ! IsValidSelection ( context , syntaxTree ) )
42
42
{
43
43
return SpecializedTasks . EmptyImmutableArray < RazorVSInternalCodeAction > ( ) ;
44
44
}
@@ -80,7 +80,7 @@ private static bool IsValidContext(RazorCodeActionContext context)
80
80
context . CodeDocument . GetSyntaxTree ( ) ? . Root is not null ;
81
81
}
82
82
83
- private bool IsSelectionValid ( RazorCodeActionContext context , RazorSyntaxTree syntaxTree )
83
+ private bool IsValidSelection ( RazorCodeActionContext context , RazorSyntaxTree syntaxTree )
84
84
{
85
85
var owner = syntaxTree . Root . FindInnermostNode ( context . Location . AbsoluteIndex , includeWhitespace : true ) ;
86
86
if ( owner is null )
@@ -90,33 +90,33 @@ private bool IsSelectionValid(RazorCodeActionContext context, RazorSyntaxTree sy
90
90
}
91
91
92
92
var startElementNode = owner . FirstAncestorOrSelf < MarkupSyntaxNode > ( node => node is MarkupElementSyntax or MarkupTagHelperElementSyntax ) ;
93
- return startElementNode is not null && ! HasDiagnosticErrors ( startElementNode ) && ! IsInsideProperHtmlContent ( context , owner ) ;
93
+ return startElementNode is not null && HasNoDiagnosticErrors ( startElementNode ) && IsInsideMarkupTag ( context , owner ) ;
94
94
}
95
95
96
- private static bool IsInsideProperHtmlContent ( RazorCodeActionContext context , SyntaxNode owner )
96
+ private static bool IsInsideMarkupTag ( RazorCodeActionContext context , SyntaxNode owner )
97
97
{
98
98
// The selection could start either in a MarkupElement or MarkupTagHelperElement.
99
- // Both of these have the necessary properties to do this check, but not the base MarkupSyntaxNode.
100
- // The workaround for this is to try to cast to the specific types and then do the check.
99
+ // Both of these have the necessary properties to do this check, but the base class MarkupSyntaxNode does not .
100
+ // The workaround for this is to try to find the specific types as ancestors and then do the check.
101
101
102
102
var tryMakeMarkupElement = owner . FirstAncestorOrSelf < MarkupElementSyntax > ( ) ;
103
103
var tryMakeMarkupTagHelperElement = owner . FirstAncestorOrSelf < MarkupTagHelperElementSyntax > ( ) ;
104
104
105
- var isLocationInProperMarkupElement = tryMakeMarkupElement is not null &&
106
- context . Location . AbsoluteIndex > tryMakeMarkupElement . StartTag . Span . End &&
107
- context . Location . AbsoluteIndex < tryMakeMarkupElement . EndTag . SpanStart ;
105
+ var isLocationInElementTag = tryMakeMarkupElement is not null &&
106
+ ( tryMakeMarkupElement . StartTag . Span . Contains ( context . Location . AbsoluteIndex ) ||
107
+ tryMakeMarkupElement . EndTag . Span . Contains ( context . Location . AbsoluteIndex ) ) ;
108
108
109
- var isLocationInProperMarkupTagHelper = tryMakeMarkupTagHelperElement is not null &&
110
- context . Location . AbsoluteIndex > tryMakeMarkupTagHelperElement . StartTag . Span . End &&
111
- context . Location . AbsoluteIndex < tryMakeMarkupTagHelperElement . EndTag . SpanStart ;
109
+ var isLocationInTagHelperTag = tryMakeMarkupTagHelperElement is not null &&
110
+ ( tryMakeMarkupTagHelperElement . StartTag . Span . Contains ( context . Location . AbsoluteIndex ) ||
111
+ tryMakeMarkupTagHelperElement . EndTag . Span . Contains ( context . Location . AbsoluteIndex ) ) ;
112
112
113
- return isLocationInProperMarkupElement || isLocationInProperMarkupTagHelper ;
113
+ return isLocationInElementTag || isLocationInTagHelperTag ;
114
114
}
115
115
116
- private static bool HasDiagnosticErrors ( MarkupSyntaxNode markupElement )
116
+ private static bool HasNoDiagnosticErrors ( MarkupSyntaxNode markupElement )
117
117
{
118
118
var diagnostics = markupElement . GetDiagnostics ( ) ;
119
- return diagnostics . Any ( d => d . Severity == RazorDiagnosticSeverity . Error ) ;
119
+ return ! diagnostics . Any ( d => d . Severity == RazorDiagnosticSeverity . Error ) ;
120
120
}
121
121
122
122
private static bool TryGetNamespace ( RazorCodeDocument codeDocument , [ NotNullWhen ( returnValue : true ) ] out string ? @namespace )
0 commit comments