diff --git a/CHANGELOG.md b/CHANGELOG.md index 184f703870..175c78ecbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/OmniSharp.Cake/Services/RequestHandlers/CakeRequestHandler.cs b/src/OmniSharp.Cake/Services/RequestHandlers/CakeRequestHandler.cs index 3bfd8b5a62..848afae35a 100644 --- a/src/OmniSharp.Cake/Services/RequestHandlers/CakeRequestHandler.cs +++ b/src/OmniSharp.Cake/Services/RequestHandlers/CakeRequestHandler.cs @@ -54,11 +54,15 @@ public virtual async Task 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 TranslateRequestAsync(TRequest req) { var request = req as Request; diff --git a/src/OmniSharp.Cake/Services/RequestHandlers/Diagnostics/CodeCheckHandler.cs b/src/OmniSharp.Cake/Services/RequestHandlers/Diagnostics/CodeCheckHandler.cs index 8a857b9422..930f36a6e3 100644 --- a/src/OmniSharp.Cake/Services/RequestHandlers/Diagnostics/CodeCheckHandler.cs +++ b/src/OmniSharp.Cake/Services/RequestHandlers/Diagnostics/CodeCheckHandler.cs @@ -1,4 +1,5 @@ using System.Composition; +using System.Threading.Tasks; using OmniSharp.Mef; using OmniSharp.Models; using OmniSharp.Models.CodeCheck; @@ -14,5 +15,8 @@ public CodeCheckHandler( : base(workspace) { } + + public override bool IsValid(CodeCheckRequest request) => + !string.IsNullOrEmpty(request.FileName); } } diff --git a/tests/OmniSharp.Cake.Tests/CodeCheckFacts.cs b/tests/OmniSharp.Cake.Tests/CodeCheckFacts.cs new file mode 100644 index 0000000000..79d28d7b66 --- /dev/null +++ b/tests/OmniSharp.Cake.Tests/CodeCheckFacts.cs @@ -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 + { + private readonly ILogger _logger; + + public CodeCheckFacts(ITestOutputHelper testOutput) : base(testOutput) + { + _logger = LoggerFactory.CreateLogger(); + } + + 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 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); + } + } + } +}