-
Notifications
You must be signed in to change notification settings - Fork 418
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
Disable cake diagnostics endpoint for requests that don't specify a file #1107
Changes from 1 commit
31b847a
582c8ef
9616062
b5718ae
842cac4
d5a1f00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Cake's diagnostics engine calls the generic CodeCheckService, which generates all diagnostics for the solution if called without a specific file path. This results in duplicate errors in C# projects when VS Code requests project level diagnostics. The solution is to only compute diagnostics for specified files. Fixes dotnet/vscode-csharp#1830
- v1.39.13
- v1.39.13-beta.32
- v1.39.13-beta.31
- v1.39.13-beta.30
- v1.39.13-beta.28
- v1.39.13-beta.9
- v1.39.12
- v1.39.11
- v1.39.10
- v1.39.9
- v1.39.8
- v1.39.7
- v1.39.6
- v1.39.5
- v1.39.4
- v1.39.3
- v1.39.2
- v1.39.1
- v1.39.0
- v1.38.2
- v1.38.1
- v1.38.0
- v1.37.17
- v1.37.16
- v1.37.15
- v1.37.14
- v1.37.13
- v1.37.12
- v1.37.11
- v1.37.10
- v1.37.9
- v1.37.8
- v1.37.7
- v1.37.6
- v1.37.5
- v1.37.4
- v1.37.3
- v1.37.2
- v1.37.1
- v1.37.0
- v1.36.1
- v1.36.0
- v1.35.4
- v1.35.3
- v1.35.2
- v1.35.1
- v1.35.0
- v1.34.15
- v1.34.14
- v1.34.13
- v1.34.12
- v1.34.11
- v1.34.10
- v1.34.9
- v1.34.8
- v1.34.7
- v1.34.6
- v1.34.5
- v1.34.4
- v1.34.3
- v1.34.2
- v1.34.1
- v1.34.0
- v1.33.0
- v1.32.20
- v.1.32.19
- v1.32.19
- v1.32.18
- v1.32.17
- v1.32.16
- v1.32.15
- v1.32.14
- v1.32.13
- v1.32.12
- v1.32.11
- v1.32.10
- v1.32.9
- v1.32.8
- v1.32.7
- v1.32.6
- v1.32.5
- v1.32.4
- v1.32.3
- v1.32.2
- v1.32.1
- v1.32.0
- v1.31.1
- v1.31.0
- v1.30.1
- v1.30.0
- v1.29.1
- ca-2.9.2
- ca-2.9.1
- ca-2.9
- 1.34.5
- 1.34.2
There are no files selected for viewing
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; | ||
|
@@ -14,5 +15,15 @@ public CodeCheckHandler( | |
: base(workspace) | ||
{ | ||
} | ||
|
||
public override Task<QuickFixResponse> HandleCore(CodeCheckRequest request, IRequestHandler<CodeCheckRequest, QuickFixResponse> service) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Override |
||
{ | ||
if (string.IsNullOrEmpty(request.FileName)) | ||
{ | ||
return Task.FromResult(new QuickFixResponse()); | ||
} | ||
|
||
return service.Handle(request); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Override Task Handle(TRequest request) and call |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using OmniSharp.Cake.Services.RequestHandlers.Diagnostics; | ||
using OmniSharp.Models; | ||
using OmniSharp.Models.AutoComplete; | ||
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.QuickFixes); | ||
} | ||
|
||
|
||
private async Task<QuickFixResponse> FindDiagnostics(string contents, bool includeFileName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line above |
||
{ | ||
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); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to introduce this?
Task<TResponse> Handle(TRequest request)
is alreadyvirtual
.