Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds QuickInfo support for Cake #1945

Merged
merged 3 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}