Skip to content
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

Multi line markup location is not found when parsing source code #624

Open
Mrnikbobjeff opened this issue Sep 14, 2020 · 1 comment
Open
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing enhancement

Comments

@Mrnikbobjeff
Copy link

Mrnikbobjeff commented Sep 14, 2020

For the posted source code no markup location is found. Instead I get a stacktrace and an Exception message:

Message: 
    System.InvalidOperationException : The markup location '#0' was not found in the input.
  Stack Trace: 
    DiagnosticResult.WithAppliedMarkupLocations(ImmutableDictionary`2 markupLocations) line 357
    SolutionState.WithProcessedMarkup(MarkupOptions markupOptions, DiagnosticDescriptor defaultDiagnostic, ImmutableArray`1 supportedDiagnostics, ImmutableArray`1 fixableDiagnostics, String defaultPath) line 276
    CodeFixTest`1.RunAsync(CancellationToken cancellationToken) line 232
    CSharpCodeFixVerifier`2.VerifyCodeFixAsync(String source, DiagnosticResult[] expected, String fixedSource) line 52
    CSharpCodeFixVerifier`2.VerifyCodeFixAsync(String source, DiagnosticResult expected, String fixedSource) line 41
    UseThrowIfCancellationRequestedTests.SingleFix_IfBlock() line 117
    --- End of stack trace from previous location where exception was thrown ---
[Fact]
        public async Task SingleFix_IfBlock()
        {
            await VerifyCS.VerifyCodeFixAsync(@"
    using System;
    using System.Threading.Tasks;
    using System.Threading;
    namespace ConsoleApplication1
    {
        class TypeName
        {   
            public async Task Test(CancellationToken ct)
            {
                {|#0:if(ct.IsCancellationRequested)
                {
                    throw new Exception();
                }|}
            }
        }
    }", VerifyCS.Diagnostic(UseThrowIfCancellationRequestedAnalyzer.DefaultRule).WithLocation(0),
            @"using System;
using System.Threading.Tasks;
using System.Threading;
namespace ConsoleApplication1
{
    class TypeName
    {
        public async Task Test(CancellationToken ct)
        {
            ct.ThrowIfCancellationRequested();
        }
    }
}");
        }
@sharwell sharwell added the Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing label Oct 15, 2020
@sharwell
Copy link
Member

My guess on the cause of this is the code fix provider specified in the alias for VerifyCS does not report UseThrowIfCancellationRequestedAnalyzer.DefaultRule as a supported diagnostic. This scenario would cause VerifyCodeFixAsync to expect the diagnostic in both the test code and the fixed code, but only the test code provides location 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing enhancement
Projects
None yet
Development

No branches or pull requests

2 participants