-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
IOperation Analyzers and Fields #18915
Comments
@Hosch250 It sounds like what you want is a symbol analyzer, not an operation analyzer. These are easy to write for your described scenario. |
Oh sure, I know how to write those. I'm a bit confused on what all is what--better break out the search engine again. It's somewhat confusing, though, because there is |
@Hosch250 IOperation is currently only a prototype. We're working on actually producing a full, real supported API for it. We'll keep your use case in mind as we go through our list of work items. Tagging @jinujoseph for visibility. Note that I think is simply 'by design'. your "bool _foo;" is simply a field. A field initializer would be something like "bool _foo = code;" IOperation attempts to give you a rich semantic tree to represent the code that actually executes, not really the symbols that may be initialized from the code that executes. |
OK, thanks for the explanation. So, I should typically not write an analyzer off a syntax node, but should work with |
@Hosch250 It really depends on what you're doing. :) Lots of analyzers are suited to be written as syntax-analyzers. However, the benefit of IOperation over them is twofold:
The downside is that you are working on an abstraction. So if there was something particular to a specific language's syntax, then you wouldn't see that directly in the IOperation tree (though you could use teh SyntaxNode each operation exposes to track back to those pieces of syntax). |
OK, I'll write a few analyzers with it to see how it works better. |
Take a look at https://github.com/dotnet/roslyn/blob/master/src/Features/Core/Portable/PopulateSwitch/PopulateSwitchDiagnosticAnalyzer.cs It's an example of an analyzer that works for VB and C# without having any VB/C# specific code in it. |
Yup, I wrote that one originally, and then you rewrote it. That's where I first learned about IOperation, but school and other projects have kind of interfered with my learning it properly. |
d'oh! I forgot about that :) Note: learning about IOperation is definitely something you can do. But do take into account it's very much in flux. What is checked in now is simply a very rough prototype. And the work to actually produce a real API is going on as we speak. |
We're going to close this out currently as being unactionable. |
Version Used: Latest Release
Steps to Reproduce:
IOperation
.OperationKind
has field-related itemsFieldInitializerInCreation
,FieldInitializerAtDeclaration
, andFieldInitializerInCreation
.Expected Behavior: None of these fire on
bool _foo;
, which is expected given the names. I'd expect there to be aFieldDeclaration
that fires on anyFieldDeclarationSyntax
node.Actual Behavior: There is no
OperationKind
that makes the analyzer run on any field regardless of how it is written.@CyrusNajmabadi: @jmarolf told me to make an issue for this and ping you.
The text was updated successfully, but these errors were encountered: