Skip to content

Commit

Permalink
Also remap diagnostic length
Browse files Browse the repository at this point in the history
  • Loading branch information
Suchiman committed Jun 4, 2016
1 parent d0002cc commit 689fb24
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 27 additions & 0 deletions SerilogAnalyzer/SerilogAnalyzer.Test/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,33 @@ public static void Test()
VerifyCSharpDiagnostic(src, expected);
}

[TestMethod]
public void TestDiagnosticLengthWithEscapes()
{
string src = @"
using Serilog;
class TypeName
{
public static void Test()
{
Log.Information(@""Hello {Name to """"the"""" World"");
}
}";

var expected = new DiagnosticResult
{
Id = "Serilog002",
Message = String.Format("Error while parsing MessageTemplate: {0}", "Encountered end of messageTemplate while parsing property"),
Severity = DiagnosticSeverity.Error,
Locations = new[]
{
new DiagnosticResultLocation("Test0.cs", 8, 37, 22)
}
};
VerifyCSharpDiagnostic(src, expected);
}

[TestMethod]
public void TestExactMappingInVerbatimLiteralWithEscapes()
{
Expand Down
4 changes: 3 additions & 1 deletion SerilogAnalyzer/SerilogAnalyzer/DiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ private static void ReportDiagnostic(ref SyntaxNodeAnalysisContext context, ref
}
else
{
textSpan = new TextSpan(literalSpan.Start + GetPositionInLiteral(stringText, diagnostic.StartIndex), diagnostic.Length);
int remappedStart = GetPositionInLiteral(stringText, diagnostic.StartIndex);
int remappedEnd = GetPositionInLiteral(stringText, diagnostic.StartIndex + diagnostic.Length);
textSpan = new TextSpan(literalSpan.Start + remappedStart, remappedEnd - remappedStart);
}
}
else
Expand Down

0 comments on commit 689fb24

Please sign in to comment.