Skip to content

Commit

Permalink
Merge pull request #1945 from mholo65/feature/quick-info
Browse files Browse the repository at this point in the history
Adds QuickInfo support for Cake
  • Loading branch information
JoeRobich authored Sep 15, 2020
2 parents 8f10a7f + 5d23a6a commit a9d2244
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/OmniSharp.Cake/Services/RequestHandlers/QuickInfoHandler.cs
Original file line number Diff line number Diff line change
@@ -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<QuickInfoRequest, QuickInfoResponse>
{
[ImportingConstructor]
public QuickInfoHandler(OmniSharpWorkspace workspace) : base(workspace)
{
}
}
}
81 changes: 81 additions & 0 deletions tests/OmniSharp.Cake.Tests/QuickInfoFacts.cs
Original file line number Diff line number Diff line change
@@ -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<QuickInfoHandler>
{
private readonly ILogger _logger;

public QuickInfoFacts(ITestOutputHelper testOutput) : base(testOutput)
{
_logger = LoggerFactory.CreateLogger<AutoCompleteFacts>();
}

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<QuickInfoResponse> 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);
}
}
}

0 comments on commit a9d2244

Please # to comment.