Skip to content

Commit

Permalink
Only return diagnostics for the requested file.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorkstromm committed May 30, 2018
1 parent c3510b9 commit 417ac96
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System.Composition;
using System;
using System.Composition;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using OmniSharp.Mef;
using OmniSharp.Models;
using OmniSharp.Models.CodeCheck;
using OmniSharp.Utilities;

namespace OmniSharp.Cake.Services.RequestHandlers.Diagnostics
{
Expand All @@ -18,5 +22,33 @@ public CodeCheckHandler(

public override bool IsValid(CodeCheckRequest request) =>
!string.IsNullOrEmpty(request.FileName);

protected override Task<QuickFixResponse> TranslateResponse(QuickFixResponse response, CodeCheckRequest request)
{
if (response?.QuickFixes == null)
{
return Task.FromResult(response);
}

var quickFixes = response.QuickFixes.Where(x => PathsAreEqual(x.FileName, request.FileName));
response.QuickFixes = quickFixes;
return Task.FromResult(response);

bool PathsAreEqual(string x, string y)
{
if (x == null && y == null)
{
return true;
}
if (x == null || y == null)
{
return false;
}

var comparer = PlatformHelper.IsWindows ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;

return Path.GetFullPath(x).Equals(Path.GetFullPath(y), comparer);
}
}
}
}
2 changes: 1 addition & 1 deletion tests/OmniSharp.Cake.Tests/CodeCheckFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task ShouldNotIncludeDiagnosticsFromLoadedFilesIfFileNameIsSpecifie
var target = Argument(""target"", ""Default"");";

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

private async Task<QuickFixResponse> FindDiagnostics(string contents, bool includeFileName)
Expand Down

0 comments on commit 417ac96

Please sign in to comment.