-
-
Notifications
You must be signed in to change notification settings - Fork 567
Simplify access to the SemanticModel in analyzers #1167
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
Simplify access to the SemanticModel in analyzers #1167
Conversation
#pragma warning disable RS1030 // Do not invoke Compilation.GetSemanticModel() method within a diagnostic analyzer | ||
var model = context.Compilation.GetSemanticModel(context.Operation.Syntax.SyntaxTree); | ||
#pragma warning restore RS1030 // Do not invoke Compilation.GetSemanticModel() method within a diagnostic analyzer | ||
var model = context.Operation.SemanticModel!; |
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.
According to the doc it is safe to consider the SemanticModel to be non-null
Optional semantic model that was used to generate this operation. Non-null for operations generated from source with GetOperation(SyntaxNode, CancellationToken) API and operation callbacks made to analyzers. Null for operations inside a ControlFlowGraph.
@phil-scott-78 Do you have time to look at this? |
If @meziantou submitted it, then I'll probably learn something cool - so, of course! I'll carve out time tonight |
I don't think there is a lot to learn from this PR, but I hope you'll like the next one #1169 😉 |
@phil-scott-78 Have you got time to review this PR? (and others small PRs I've opened) |
absolutely. thanks for the nudge, would have missed them otherwise. |
I think we got them all! Thanks @meziantou! |
That was fast 🚀 |
No description provided.