Skip to content

Commit 1c239a1

Browse files
committed
Use syntaxTree instead of sourceText
1 parent d83031b commit 1c239a1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeAct
8080
var utilityScanRoot = FindNearestCommonAncestor(startElementNode, endElementNode) ?? startElementNode;
8181

8282
// The new component usings are going to be a subset of the usings in the source razor file
83-
var usingsInFile = context.SourceText.ToString()
84-
.Split('\n')
85-
.Where(line => line.TrimStart().StartsWith("@using"))
83+
var usingsInFile = syntaxTree.Root.DescendantNodes()
84+
.OfType<CSharpStatementLiteralSyntax>()
85+
.Where(literal => literal.SerializedValue.Contains("using"))
86+
.Select(literal => literal.SerializedValue)
8687
.Aggregate(new StringBuilder(), (sb, line) => sb.AppendLine(line))
8788
.ToString();
8889

0 commit comments

Comments
 (0)