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