-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Can this be implemented as Roslyn Analysers? #720
Comments
I haven't had time to check this out yet, but my one worry is that analyzers run on a specific node type. This could be an analyzer on the CompilationUnitSyntax, but I don't know if a file would be re-analyzed when a line inside of a method changes. Even without that it would still work as part of the build, and may even be faster than the current MsBuild package. |
Thanks a lot. I mention this because it's how |
I tried creating an Analyzer in the CSharpier solution, but couldn't get past this error. There is some weirdness already with the source generators needing very specific versions of Microsoft.CodeAnalysis
I tried creating an empty solution for the analyzer, and referencing CSharpier from nuget. When I try to use CSharpier in the analyzer project, I get this error. But CSharpier can be referenced just fine from within a console app.
I'm not sure how to get past either of those errors. |
to use nuget packages inside of source generators it's a bit complicated. |
I brought this up before with them, but didn't get any response: When I pinged the roslyn devs offline, they were against the idea since csharpier does't handle code with syntax errors. |
Source generators can generate new source files to add to the compilation, but very importantly, they cannot modify existing files (at least, last time I checked). As a result, a source generator cannot be used to format the code. From this FAQ on source generators:
Code analyzers lets you analyze the code and produce diagnostics and the associated code fixes. If anything, this can be done as an analyzer, but not as a source generator. |
I totally agree. Code generators are for generated code. Analyzers are for human-written code. |
I ran across this which could help figuring out how to get the required nuget packages into CSharpier as an analyzer https://www.meziantou.net/packaging-a-roslyn-analyzer-with-nuget-dependencies.htm |
I'm very interested in this issue. This would allow integration into This could also lower the burden on the extensions as they would, in theory, not be needed anymore since an analyser + refactoring would just show up in all IDEs. This would resolve issues where some devs don't have the extension installed for example. It would also support sharing the config through analyser globalconfig and not have the line length parameter copied all over the place. |
I'm not opposed to this being avaiable as an analyzer but I don't see it replacing the current CLI. On our large work project, dotnet-format never finishes. It changes some files and eventually hangs. In comparison dotnet csharpier runs in 2s when it has a primed cache, 20s with no cache. I also don't know that "quick fix analyzers on save" is a thing in IDEs. Format on save is incredibly useful and I can't image life without it. I'm not familiar with globalconfig, but it seems like they aren't meant for style options
|
My understanding, and I might be wrong, is that IDEs (or their editorconfig support) won't be fed from the
WIth all this said, I'll take a look if I can come up with something acceptable that would tie it all together without making it too complex for the maintenance of this project. |
If this is possible, we'd get a lot of benefits:
dotnet format
(maybe just need to turn off some built-in analyzers or something)Forgive my ignorance if this is already implemented this way and still doesn't achieve these goals.
The text was updated successfully, but these errors were encountered: