diff --git a/CHANGELOG.md b/CHANGELOG.md index 841a42afac..c7f035d54f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All changes to the project will be documented in this file. ## [1.37.2] - Not Yet Released +* Add support for new quick info endpoint when working with Cake (PR: [#1945](https://github.com/OmniSharp/omnisharp-roslyn/pull/1945)) * Add support for new completion endpoints when working with Cake ([#1939](https://github.com/OmniSharp/omnisharp-roslyn/issues/1939), PR: [#1944](https://github.com/OmniSharp/omnisharp-roslyn/pull/1944)) ## [1.37.1] - 2020-09-01 diff --git a/src/OmniSharp.Cake/Services/RequestHandlers/QuickInfoHandler.cs b/src/OmniSharp.Cake/Services/RequestHandlers/QuickInfoHandler.cs new file mode 100644 index 0000000000..b3aa32f193 --- /dev/null +++ b/src/OmniSharp.Cake/Services/RequestHandlers/QuickInfoHandler.cs @@ -0,0 +1,16 @@ +using System.Composition; +using OmniSharp.Mef; +using OmniSharp.Models; + +namespace OmniSharp.Cake.Services.RequestHandlers +{ + [Shared] + [OmniSharpHandler(OmniSharpEndpoints.QuickInfo, Constants.LanguageNames.Cake)] + public class QuickInfoHandler : CakeRequestHandler + { + [ImportingConstructor] + public QuickInfoHandler(OmniSharpWorkspace workspace) : base(workspace) + { + } + } +} diff --git a/tests/OmniSharp.Cake.Tests/QuickInfoFacts.cs b/tests/OmniSharp.Cake.Tests/QuickInfoFacts.cs new file mode 100644 index 0000000000..0c5ac6040a --- /dev/null +++ b/tests/OmniSharp.Cake.Tests/QuickInfoFacts.cs @@ -0,0 +1,81 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using OmniSharp.Cake.Services.RequestHandlers; +using OmniSharp.Cake.Services.RequestHandlers.Completion; +using OmniSharp.Models; +using OmniSharp.Models.UpdateBuffer; +using OmniSharp.Models.v1.Completion; +using TestUtility; +using Xunit; +using Xunit.Abstractions; + +namespace OmniSharp.Cake.Tests +{ + public class QuickInfoFacts : CakeSingleRequestHandlerTestFixture + { + private readonly ILogger _logger; + + public QuickInfoFacts(ITestOutputHelper testOutput) : base(testOutput) + { + _logger = LoggerFactory.CreateLogger(); + } + + protected override string EndpointName => OmniSharpEndpoints.QuickInfo; + + [Fact] + public async Task ShouldGetQuickInfo() + { + const string input = "Informa$$tion(\"Hello\");"; + + 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 quickInfo = await GetQuickInfo(fileName, input, host); + + Assert.StartsWith("```csharp\nvoid Information(string value)", quickInfo.Markdown); + } + } + + private async Task GetQuickInfo(string filename, string source, OmniSharpTestHost host, char? triggerChar = null, TestFile[] additionalFiles = null) + { + var testFile = new TestFile(filename, source); + + var files = new[] { testFile }; + if (additionalFiles is object) + { + files = files.Concat(additionalFiles).ToArray(); + } + + host.AddFilesToWorkspace(files); + var point = testFile.Content.GetPointFromPosition(); + + var request = new QuickInfoRequest + { + Line = point.Line, + Column = point.Offset, + FileName = testFile.FileName, + Buffer = testFile.Content.Code + }; + + var updateBufferRequest = new UpdateBufferRequest + { + Buffer = request.Buffer, + Column = request.Column, + FileName = request.FileName, + Line = request.Line, + FromDisk = false + }; + + await GetUpdateBufferHandler(host).Handle(updateBufferRequest); + + var requestHandler = GetRequestHandler(host); + + return await requestHandler.Handle(request); + } + } +}