-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
XAML warnings/diagnostics support #13447
Conversation
Depends on kekekeks/XamlX#99 |
|
||
namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions; | ||
|
||
internal static class AvaloniaXamlDiagnosticCodes |
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.
Do we need to have unique diagnostic codes per each error? Currently, it's grouped by area and ability to lower severity, i.e. two different selector parse errors will have the same code - AVLN2201 - right now.
&& clrProperty.DeclaringType == context.GetAvaloniaTypes().ResourceDictionary) | ||
{ | ||
var nodeName = on.Type.GetClrType().Name; | ||
context.ReportDiagnostic(new XamlDiagnostic( |
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.
Example of Avalonia-specific XAML warning.
5d7707a
to
d052b91
Compare
0b30812
to
92b3b05
Compare
7e3cc0a
to
dba33dd
Compare
d62961f
to
51680e4
Compare
If anybody has some time to test this PR, it would help. Basically, it should be able to report most XAML errors, while not regressing anything. |
I tested this for a while and can see multiple errors being properly reported and MSBuild error properties being respected. Here's a few things I've noticed: Missing error locationThe file name and position where an error occurs don't seem to be properly reported anymore: Before this PR:
With Rider/VS properly taking me to the error location. After this PR:
Notice the lack of Multiple obsolete diagnosticsAn obsolete usage is reported as two warnings/errors (probably because it's two lines):
In contrast, the C# compiler reports:
Duplicate unexpected errorsNote that while known errors don't have a strack trace anymore, unexpected ones still do, effectively reporting each line as a different error.
However that was already the case before this PR, so it' just a thing to note for later fixing. EditorConfig handlingAs noted in the code, EditorConfig parsing is very basic, using regexes, so specified file globs are ignored. Note that this library targets .NET Standard 1.3, doesn't have any dependency, and is MIT-licensed, so we should be able to ILMerge into Avalonia.Build.Tasks without issues. |
Interesting. Will take a look. It should be reported correctly.
Looks like MSBuild doesn't handle multiline errors as an error with description. Instead it splits it into multiple errors/warnings. Need to research on how to correctly add description to the error/warning.
In general, we can't completely avoid "butterfly effect" of one error producing more errors. But in your example I see something that should be avoided (basically the same parsing error reported multiple time) + AVLN0000 code is wrong there. Will check it.
Yes, I will try to ilmerge it. |
…rs should still be generated
Great work. A feature I would like to have would be the ability to write an analyzer like the Roslyn analyzers, which can be plugged into the compilation pipeline via nuget. Everyone could write their own rules based on company policy. |
@workgroupengineering I don't think we will have plugin/analyzer infrastructure soon. We don't even have an immutable nodes tree that we can safely send to the third-party analyzer. So, for now, the best bet would be to implement these analyzers as a part of the compiler. |
@MrJul I am going to leave EditorConfig improvements out of the scope of this PR for now. Other issues should be solved. |
Tested again, everything works fine (with Let's get back to the EditorConfig issue later, once your PR there is hopefully merged :) |
What does the pull request do?
RuntimeXamlLoaderConfiguration.DiagnosticHandler
API).TreatWarningsAsErrors
,WarningsAsErrors
,WarningsNotAsErrors
,NoWarn
,EditorConfig
files (limited). Or in case of runtime loader - using the sameRuntimeXamlLoaderConfiguration.DiagnosticHandler
. Note, each diagnostic has default and min severity - you can't mark any Error as a Warning, but you can do in the opposite way.What is the current behavior?
Poor.
How was the solution implemented (if it's not obvious)?
There are a couple of important moments:
Checklist
Breaking changes
Different diagnostic codes, but it's hardly a breaking change, as it wasn't really structured.
Fixed issues
Fixes #5842
Fixes #7461
Re-fixes #9612 (as a warning instead of an error)
Partially #4466