Skip to content

Commit edbb1b4

Browse files
committed
Updated functionality to match Roslyn endpoint response, finished attribute promotion functionality, Resolver now handles event handlers and data binding
1 parent de3aefe commit edbb1b4

File tree

5 files changed

+221
-312
lines changed

5 files changed

+221
-312
lines changed

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeAct
4646
}
4747

4848
var syntaxTree = context.CodeDocument.GetSyntaxTree();
49-
if (!IsSelectionValid(context, syntaxTree))
49+
if (!IsValidSelection(context, syntaxTree))
5050
{
5151
return SpecializedTasks.EmptyImmutableArray<RazorVSInternalCodeAction>();
5252
}
@@ -79,7 +79,7 @@ private static bool IsValidContext(RazorCodeActionContext context)
7979
context.CodeDocument.GetSyntaxTree()?.Root is not null;
8080
}
8181

82-
private bool IsSelectionValid(RazorCodeActionContext context, RazorSyntaxTree syntaxTree)
82+
private bool IsValidSelection(RazorCodeActionContext context, RazorSyntaxTree syntaxTree)
8383
{
8484
var owner = syntaxTree.Root.FindInnermostNode(context.Location.AbsoluteIndex, includeWhitespace: true);
8585
if (owner is null)
@@ -89,33 +89,33 @@ private bool IsSelectionValid(RazorCodeActionContext context, RazorSyntaxTree sy
8989
}
9090

9191
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);
9393
}
9494

95-
private static bool IsInsideProperHtmlContent(RazorCodeActionContext context, SyntaxNode owner)
95+
private static bool IsInsideMarkupTag(RazorCodeActionContext context, SyntaxNode owner)
9696
{
9797
// 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.
100100

101101
var tryMakeMarkupElement = owner.FirstAncestorOrSelf<MarkupElementSyntax>();
102102
var tryMakeMarkupTagHelperElement = owner.FirstAncestorOrSelf<MarkupTagHelperElementSyntax>();
103103

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));
107107

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));
111111

112-
return isLocationInProperMarkupElement || isLocationInProperMarkupTagHelper;
112+
return isLocationInElementTag || isLocationInTagHelperTag;
113113
}
114114

115-
private static bool HasDiagnosticErrors(MarkupSyntaxNode markupElement)
115+
private static bool HasNoDiagnosticErrors(MarkupSyntaxNode markupElement)
116116
{
117117
var diagnostics = markupElement.GetDiagnostics();
118-
return diagnostics.Any(d => d.Severity == RazorDiagnosticSeverity.Error);
118+
return !diagnostics.Any(d => d.Severity == RazorDiagnosticSeverity.Error);
119119
}
120120

121121
private static bool TryGetNamespace(RazorCodeDocument codeDocument, [NotNullWhen(returnValue: true)] out string? @namespace)

0 commit comments

Comments
 (0)