diff --git a/CHANGELOG.md b/CHANGELOG.md index c1f405b077..a058024c9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All changes to the project will be documented in this file. * Updated ILSpy to 7.2.1.6856 (PR: [#2447](https://github.com/OmniSharp/omnisharp-roslyn/pull/2447)) * Include OmniSharp.Cake in .NET 6 builds (PR: [#2455](https://github.com/OmniSharp/omnisharp-roslyn/pull/2455)) * Implement /v2/highlight for Cake (PR: [#2456](https://github.com/OmniSharp/omnisharp-roslyn/pull/2456)) - +* Implement /open for Cake (PR: [#2457](https://github.com/OmniSharp/omnisharp-roslyn/pull/2457)) ## [1.39.1] - 2022-07-25 * Update Roslyn to 4.4.0 1.22369.1 (PR: [#2420](https://github.com/OmniSharp/omnisharp-roslyn/pull/2420)) diff --git a/src/OmniSharp.Cake/Extensions/ResponseExtensions.cs b/src/OmniSharp.Cake/Extensions/ResponseExtensions.cs index 40ba66c03a..3244d71a43 100644 --- a/src/OmniSharp.Cake/Extensions/ResponseExtensions.cs +++ b/src/OmniSharp.Cake/Extensions/ResponseExtensions.cs @@ -41,7 +41,7 @@ public static async Task TranslateAsync(this QuickFixResponse { var quickFixes = new List(); - foreach (var quickFix in response.QuickFixes) + foreach (var quickFix in response.QuickFixes ?? Enumerable.Empty()) { await quickFix.TranslateAsync(workspace, request); diff --git a/src/OmniSharp.Cake/Services/RequestHandlers/Files/FileOpenHandler.cs b/src/OmniSharp.Cake/Services/RequestHandlers/Files/FileOpenHandler.cs new file mode 100644 index 0000000000..384d49a31e --- /dev/null +++ b/src/OmniSharp.Cake/Services/RequestHandlers/Files/FileOpenHandler.cs @@ -0,0 +1,14 @@ +using System.Composition; +using OmniSharp.Mef; +using OmniSharp.Models.FileOpen; + +namespace OmniSharp.Cake.Services.RequestHandlers.Files; + +[OmniSharpHandler(OmniSharpEndpoints.Open, Constants.LanguageNames.Cake), Shared] +public class FileOpenHandler : CakeRequestHandler +{ + [ImportingConstructor] + public FileOpenHandler(OmniSharpWorkspace workspace) : base(workspace) + { + } +} diff --git a/tests/OmniSharp.Cake.Tests/FileOpenFacts.cs b/tests/OmniSharp.Cake.Tests/FileOpenFacts.cs new file mode 100644 index 0000000000..d3490fd6eb --- /dev/null +++ b/tests/OmniSharp.Cake.Tests/FileOpenFacts.cs @@ -0,0 +1,49 @@ +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using OmniSharp.Cake.Services.RequestHandlers.Files; +using OmniSharp.Models; +using OmniSharp.Models.CodeCheck; +using OmniSharp.Models.FileOpen; +using OmniSharp.Models.UpdateBuffer; +using TestUtility; +using Xunit; +using Xunit.Abstractions; +using Xunit.Sdk; + +namespace OmniSharp.Cake.Tests +{ + public class FileOpenFacts : CakeSingleRequestHandlerTestFixture + { + public FileOpenFacts(ITestOutputHelper testOutput) : base(testOutput) + { + } + + protected override string EndpointName => OmniSharpEndpoints.Open; + + [Fact] + public async Task AddsOpenFile() + { + using (var testProject = await TestAssets.Instance.GetTestProjectAsync("CakeProject", shadowCopy : false)) + using (var host = CreateOmniSharpHost(testProject.Directory)) + { + var filename = Path.Combine(testProject.Directory, "build.cake"); + var documentId = host.Workspace.GetDocumentId(filename); + + Assert.False(host.Workspace.IsDocumentOpen(documentId)); + + var request = new FileOpenRequest + { + FileName = filename + }; + + var requestHandler = GetRequestHandler(host); + + _ = await requestHandler.Handle(request); + + Assert.True(host.Workspace.IsDocumentOpen(documentId)); + } + } + } +}