Skip to content

Commit

Permalink
[GH-73] - higlighting proper member when repoting NS1001 (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpodolak authored and dtchepak committed Feb 24, 2019
1 parent 97d84a0 commit d388035
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void AnalyzeInvocation(SyntaxNodeAnalysisContext syntaxNodeContext)
{
var diagnostic = Diagnostic.Create(
DiagnosticDescriptorsProvider.NonVirtualReceivedSetupSpecification,
invocationExpression.GetLocation(),
GetSymbolLocation(parentNode, symbolInfo.Symbol),
symbolInfo.Symbol.Name);

syntaxNodeContext.ReportDiagnostic(diagnostic);
Expand All @@ -86,7 +86,7 @@ private void AnalyzeInvocation(SyntaxNodeAnalysisContext syntaxNodeContext)
{
var diagnostic = Diagnostic.Create(
DiagnosticDescriptorsProvider.InternalSetupSpecification,
invocationExpression.GetLocation(),
GetSymbolLocation(parentNode, symbolInfo.Symbol),
symbolInfo.Symbol.Name);

syntaxNodeContext.ReportDiagnostic(diagnostic);
Expand Down Expand Up @@ -117,5 +117,12 @@ private SyntaxNode GetKnownParent(SyntaxNode receivedSyntaxNode)

return null;
}

private Location GetSymbolLocation(SyntaxNode syntaxNode, ISymbol symbol)
{
var actualNode = symbol is IMethodSymbol _ ? syntaxNode.Parent : syntaxNode;

return actualNode.GetLocation();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class FooTests
public void Test()
{{
var substitute = NSubstitute.Substitute.For<Foo>();
[|substitute.{method}()|].Bar();
[|substitute.{method}().Bar()|];
}}
}}
}}";
Expand Down Expand Up @@ -138,7 +138,7 @@ public class FooTests
public void Test()
{{
var substitute = NSubstitute.Substitute.For<Foo>();
[|substitute.{method}()|].Bar();
[|substitute.{method}().Bar()|];
}}
}}
}}";
Expand Down Expand Up @@ -327,7 +327,7 @@ public class FooTests
public void Test()
{{
var substitute = NSubstitute.Substitute.For<Foo>();
var x = [|substitute.{method}()|].Bar;
var x = [|substitute.{method}().Bar|];
}}
}}
}}";
Expand Down Expand Up @@ -374,7 +374,7 @@ public class FooTests
public void Test()
{{
var substitute = NSubstitute.Substitute.For<Foo>();
var x = [|substitute.{method}()|][1];
var x = [|substitute.{method}()[1]|];
}}
}}
}}";
Expand Down Expand Up @@ -457,7 +457,7 @@ public class FooTests
public void Test()
{{
var substitute = NSubstitute.Substitute.For<Foo>();
var x = [|substitute.{method}()|]{call};
var x = [|substitute.{method}(){call}|];
}}
}}
}}";
Expand Down Expand Up @@ -531,7 +531,7 @@ public class FooTests
public void Test()
{{
var substitute = NSubstitute.Substitute.For<Foo>();
var x = [|substitute.{method}()|]{call};
var x = [|substitute.{method}(){call}|];
}}
}}
}}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class FooTests
public void Test()
{{
var substitute = NSubstitute.Substitute.For<Foo>();
[|{method}(substitute)|].Bar();
[|{method}(substitute).Bar()|];
}}
}}
}}";
Expand Down Expand Up @@ -154,7 +154,7 @@ public class FooTests
public void Test()
{{
var substitute = NSubstitute.Substitute.For<Foo>();
[|{method}(substitute)|].Bar();
[|{method}(substitute).Bar()|];
}}
}}
}}";
Expand Down Expand Up @@ -351,7 +351,7 @@ public class FooTests
public void Test()
{{
var substitute = NSubstitute.Substitute.For<Foo>();
var x = [|{method}(substitute)|].Bar;
var x = [|{method}(substitute).Bar|];
}}
}}
}}";
Expand Down Expand Up @@ -398,7 +398,7 @@ public class FooTests
public void Test()
{{
var substitute = NSubstitute.Substitute.For<Foo>();
var x = [|{method}(substitute)|][1];
var x = [|{method}(substitute)[1]|];
}}
}}
}}";
Expand Down Expand Up @@ -481,7 +481,7 @@ public class FooTests
public void Test()
{{
var substitute = NSubstitute.Substitute.For<Foo>();
var x = [|{method}(substitute)|]{call};
var x = [|{method}(substitute){call}|];
}}
}}
}}";
Expand Down Expand Up @@ -555,7 +555,7 @@ public class FooTests
public void Test()
{{
var substitute = NSubstitute.Substitute.For<Foo>();
var x = [|{method}(substitute)|]{call};
var x = [|{method}(substitute){call}|];
}}
}}
}}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ End Class
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of Foo)()
[|substitute.{method}()|].Bar()
[|substitute.{method}().Bar()|]
End Sub
End Class
End Namespace
Expand Down Expand Up @@ -133,7 +133,7 @@ End Class
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of Foo2)()
[|substitute.{method}()|].Bar()
[|substitute.{method}().Bar()|]
End Sub
End Class
End Namespace
Expand Down Expand Up @@ -324,7 +324,7 @@ End Class
Public Sub Test()
Dim substitute = NSubstitute.Substitute.For(Of Foo)
Dim x As Integer = [|substitute.{method}()|].Bar
Dim x As Integer = [|substitute.{method}().Bar|]
End Sub
End Class
End Namespace";
Expand Down Expand Up @@ -383,7 +383,7 @@ End Class
Public Sub Test()
Dim substitute = NSubstitute.Substitute.For(Of Foo)
Dim x As Integer = [|substitute.{method}()|](1)
Dim x As Integer = [|substitute.{method}()(1)|]
End Sub
End Class
End Namespace";
Expand Down Expand Up @@ -457,7 +457,7 @@ End Class
Public Class FooTests
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of Foo)()
Dim x = [|substitute.{method}()|]{call}
Dim x = [|substitute.{method}(){call}|]
End Sub
End Class
End Namespace";
Expand Down Expand Up @@ -523,7 +523,7 @@ End Class
Public Class FooTests
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of Foo)()
Dim x = [|substitute.{method}()|]{call}
Dim x = [|substitute.{method}(){call}|]
End Sub
End Class
End Namespace";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ End Class
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of Foo)()
[|{method}(substitute)|].Bar()
[|{method}(substitute).Bar()|]
End Sub
End Class
End Namespace
Expand Down Expand Up @@ -153,7 +153,7 @@ End Class
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of Foo)()
[|{method}(substitute)|].Bar()
[|{method}(substitute).Bar()|]
End Sub
End Class
End Namespace
Expand Down Expand Up @@ -353,7 +353,7 @@ End Class
Public Sub Test()
Dim substitute = NSubstitute.Substitute.For(Of Foo)
Dim x As Integer = [|{method}(substitute)|].Bar
Dim x As Integer = [|{method}(substitute).Bar|]
End Sub
End Class
End Namespace";
Expand Down Expand Up @@ -412,7 +412,7 @@ End Class
Public Sub Test()
Dim substitute = NSubstitute.Substitute.For(Of Foo)
Dim x As Integer = [|{method}(substitute)|](1)
Dim x As Integer = [|{method}(substitute)(1)|]
End Sub
End Class
End Namespace";
Expand Down Expand Up @@ -486,7 +486,7 @@ End Class
Public Class FooTests
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of Foo)()
Dim x = [|{method}(substitute)|]{call}
Dim x = [|{method}(substitute){call}|]
End Sub
End Class
End Namespace";
Expand Down Expand Up @@ -552,7 +552,7 @@ End Class
Public Class FooTests
Public Sub Test()
Dim substitute = NSubstitute.Substitute.[For](Of Foo)()
Dim x = [|{method}(substitute)|]{call}
Dim x = [|{method}(substitute){call}|]
End Sub
End Class
End Namespace";
Expand Down

0 comments on commit d388035

Please sign in to comment.