-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1945 from mholo65/feature/quick-info
Adds QuickInfo support for Cake
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/OmniSharp.Cake/Services/RequestHandlers/QuickInfoHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |