From a87dfc6d92cdd27d8ca9712e82324c9f9323735b Mon Sep 17 00:00:00 2001 From: Noah Kim Date: Thu, 2 Jul 2020 14:40:18 -0400 Subject: [PATCH] Fix issue with filekind from failed tests --- .../ExtractToCodeBehindCodeActionResolver.cs | 9 ++++----- .../ExtractToCodeBehindCodeActionResolverTest.cs | 12 ++++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs index 3a27fb73f40..c5f514e5a33 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/ExtractToCodeBehindCodeActionResolver.cs @@ -56,16 +56,15 @@ public override async Task ResolveAsync(JObject data, Cancellatio if (document is null) { return null; - } + } - var documentFileKind = document.FileKind; - if (!FileKinds.IsComponent(documentFileKind)) + var codeDocument = await document.GetGeneratedOutputAsync().ConfigureAwait(false); + if (codeDocument.IsUnsupported()) { return null; } - var codeDocument = await document.GetGeneratedOutputAsync().ConfigureAwait(false); - if (codeDocument.IsUnsupported()) + if (!FileKinds.IsComponent(codeDocument.GetFileKind())) { return null; } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/ExtractToCodeBehindCodeActionResolverTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/ExtractToCodeBehindCodeActionResolverTest.cs index 7ca7ae7c016..09dc56b865a 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/ExtractToCodeBehindCodeActionResolverTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/ExtractToCodeBehindCodeActionResolverTest.cs @@ -26,7 +26,7 @@ public class ExtractToCodeBehindCodeActionResolverTest : LanguageServerTestBase public async Task Handle_MissingFile() { // Arrange - var resolver = new ExtractToCodeBehindCodeActionResolver(new DefaultForegroundDispatcher(), EmptyDocumentResolver, FilePathNormalizer, LoggerFactory); + var resolver = new ExtractToCodeBehindCodeActionResolver(new DefaultForegroundDispatcher(), EmptyDocumentResolver, FilePathNormalizer); var data = JObject.FromObject(new ExtractToCodeBehindParams() { Uri = new Uri("c:/Test.razor"), @@ -52,7 +52,7 @@ public async Task Handle_Unsupported() var codeDocument = CreateCodeDocument(contents); codeDocument.SetUnsupported(); - var resolver = new ExtractToCodeBehindCodeActionResolver(new DefaultForegroundDispatcher(), CreateDocumentResolver(documentPath, codeDocument), FilePathNormalizer, LoggerFactory); + var resolver = new ExtractToCodeBehindCodeActionResolver(new DefaultForegroundDispatcher(), CreateDocumentResolver(documentPath, codeDocument), FilePathNormalizer); var data = JObject.FromObject(new ExtractToCodeBehindParams() { Uri = new Uri("c:/Test.razor"), @@ -78,7 +78,7 @@ public async Task Handle_InvalidFileKind() var codeDocument = CreateCodeDocument(contents); codeDocument.SetFileKind(FileKinds.Legacy); - var resolver = new ExtractToCodeBehindCodeActionResolver(new DefaultForegroundDispatcher(), CreateDocumentResolver(documentPath, codeDocument), FilePathNormalizer, LoggerFactory); + var resolver = new ExtractToCodeBehindCodeActionResolver(new DefaultForegroundDispatcher(), CreateDocumentResolver(documentPath, codeDocument), FilePathNormalizer); var data = JObject.FromObject(new ExtractToCodeBehindParams() { Uri = new Uri("c:/Test.razor"), @@ -104,7 +104,7 @@ public async Task Handle_ExtractCodeBlock() var contents = $"@page \"/test\"{Environment.NewLine}@code {{ private var x = 1; }}"; var codeDocument = CreateCodeDocument(contents); - var resolver = new ExtractToCodeBehindCodeActionResolver(new DefaultForegroundDispatcher(), CreateDocumentResolver(documentPath, codeDocument), FilePathNormalizer, LoggerFactory); + var resolver = new ExtractToCodeBehindCodeActionResolver(new DefaultForegroundDispatcher(), CreateDocumentResolver(documentPath, codeDocument), FilePathNormalizer); var actionParams = new ExtractToCodeBehindParams { Uri = documentUri, @@ -148,7 +148,7 @@ public async Task Handle_ExtractFunctionsBlock() var contents = $"@page \"/test\"{Environment.NewLine}@functions {{ private var x = 1; }}"; var codeDocument = CreateCodeDocument(contents); - var resolver = new ExtractToCodeBehindCodeActionResolver(new DefaultForegroundDispatcher(), CreateDocumentResolver(documentPath, codeDocument), FilePathNormalizer, LoggerFactory); + var resolver = new ExtractToCodeBehindCodeActionResolver(new DefaultForegroundDispatcher(), CreateDocumentResolver(documentPath, codeDocument), FilePathNormalizer); var actionParams = new ExtractToCodeBehindParams { Uri = documentUri, @@ -192,7 +192,7 @@ public async Task Handle_ExtractCodeBlockWithUsing() var contents = $"@page \"/test\"\n@using System.Diagnostics{Environment.NewLine}@code {{ private var x = 1; }}"; var codeDocument = CreateCodeDocument(contents); - var resolver = new ExtractToCodeBehindCodeActionResolver(new DefaultForegroundDispatcher(), CreateDocumentResolver(documentPath, codeDocument), FilePathNormalizer, LoggerFactory); + var resolver = new ExtractToCodeBehindCodeActionResolver(new DefaultForegroundDispatcher(), CreateDocumentResolver(documentPath, codeDocument), FilePathNormalizer); var actionParams = new ExtractToCodeBehindParams { Uri = documentUri,