Skip to content

Commit

Permalink
Merge pull request #1107 from rchande/fixDuplicateDiagnostics
Browse files Browse the repository at this point in the history
Disable cake diagnostics endpoint for requests that don't specify a file
  • Loading branch information
Ravi Chande authored Feb 12, 2018
2 parents 775d58d + d5a1f00 commit 11e72a5
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Changelog
All changes to the project will be documented in this file.

## [1.29.1] - Not Yet Released
* Fixed duplicate diagnostics in C# ([omnisharp-vscode#1830](https://github.com/OmniSharp/omnisharp-vscode/issues/1830), PR: [#1107](https://github.com/OmniSharp/omnisharp-roslyn/pull/1107))

## [1.29.0] - 2018-1-29
* Updated to Roslyn 2.6.1 packages - C# 7.2 support, (PR: [#1055](https://github.com/OmniSharp/omnisharp-roslyn/pull/1055))
* Updated to Roslyn 2.6.1 packages - C# 7.2 support (PR: [#1055](https://github.com/OmniSharp/omnisharp-roslyn/pull/1055))
* Shipped Language Server Protocol support in box. (PR: [#969](https://github.com/OmniSharp/omnisharp-roslyn/pull/969))
- Additional information and features tracked at [#968](https://github.com/OmniSharp/omnisharp-roslyn/issues/968)
* Fixed locating Visual Studio with more than one installation (PR: [#1063](https://github.com/OmniSharp/omnisharp-roslyn/pull/1063))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ public virtual async Task<TResponse> Handle(TRequest request)

request = await TranslateRequestAsync(request);

var response = await service.Handle(request);
var response = IsValid(request)
? await service.Handle(request)
: default(TResponse);

return await TranslateResponse(response, request);
}

public virtual bool IsValid(TRequest request) => true;

protected virtual async Task<TRequest> TranslateRequestAsync(TRequest req)
{
var request = req as Request;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Composition;
using System.Threading.Tasks;
using OmniSharp.Mef;
using OmniSharp.Models;
using OmniSharp.Models.CodeCheck;
Expand All @@ -14,5 +15,8 @@ public CodeCheckHandler(
: base(workspace)
{
}

public override bool IsValid(CodeCheckRequest request) =>
!string.IsNullOrEmpty(request.FileName);
}
}
72 changes: 72 additions & 0 deletions tests/OmniSharp.Cake.Tests/CodeCheckFacts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using OmniSharp.Cake.Services.RequestHandlers.Diagnostics;
using OmniSharp.Models;
using OmniSharp.Models.CodeCheck;
using OmniSharp.Models.UpdateBuffer;
using TestUtility;
using Xunit;
using Xunit.Abstractions;

namespace OmniSharp.Cake.Tests
{
public class CodeCheckFacts : CakeSingleRequestHandlerTestFixture<CodeCheckHandler>
{
private readonly ILogger _logger;

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

protected override string EndpointName => OmniSharpEndpoints.CodeCheck;

[Fact]
public async Task ShouldProvideDiagnosticsIfRequestContainsCakeFileName()
{
const string input = @"zzz";

var diagnostics = await FindDiagnostics(input, includeFileName: true);
Assert.NotEmpty(diagnostics.QuickFixes);
}

[Fact]
public async Task ShouldNotCallCodeCheckServiceIfRequestDoesNotSpecifyFileName()
{
const string input = @"zzz$$";

var diagnostics = await FindDiagnostics(input, includeFileName: false);
Assert.Null(diagnostics);
}

private async Task<QuickFixResponse> FindDiagnostics(string contents, bool includeFileName)
{
using (var testProject = await TestAssets.Instance.GetTestProjectAsync("CakeProject", shadowCopy : false))
using (var host = CreateOmniSharpHost(testProject.Directory))
{
var testFile = new TestFile(Path.Combine(testProject.Directory, "build.cake"), contents);

var request = new CodeCheckRequest
{
FileName = includeFileName ? testFile.FileName : string.Empty,
};

var updateBufferRequest = new UpdateBufferRequest
{
Buffer = testFile.Content.Code,
Column = request.Column,
FileName = testFile.FileName,
Line = request.Line,
FromDisk = false
};

await GetUpdateBufferHandler(host).Handle(updateBufferRequest);

var requestHandler = GetRequestHandler(host);

return await requestHandler.Handle(request);
}
}
}
}

0 comments on commit 11e72a5

Please sign in to comment.