-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Move C# editorconfig diagnostic support API to CompilationOptions, instead of SyntaxTree #44331
Move C# editorconfig diagnostic support API to CompilationOptions, instead of SyntaxTree #44331
Conversation
fcf3b64
to
314275e
Compare
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.
Was looking to help @agocke understand what to do next for the test failures, and generally reviewed the IDE code carefully just to understand if there was any easy mistake that would explain it. Comments are what I noticed but the code looks solid.
var tree = SyntaxFactory.ParseSyntaxTree( | ||
content, | ||
file.IsScript ? scriptParseOptions : parseOptions, | ||
file.Path, | ||
diagnosticOptions, |
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.
So any existing analyzers out there will just break if they were using the obsolete properties? I'm not terribly worried about it as the users are likely rare (or non-existent) but just wanted to confirm the intent since this will go through API review.
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.
The intended breaking changes are:
If you added options to an analyzer config, they will not get propagated to the syntax trees. You can still access the property on the syntax tree but it is obsolete, and none of the options from the analyzer config files will be present.
If you added options to the trees directly, those will be preserved.
Eventually, we can consider removing the obsolete APIs all together.
src/Compilers/Core/Portable/Compilation/SyntaxTreeOptionsProvider.cs
Outdated
Show resolved
Hide resolved
public override bool? IsGenerated(SyntaxTree tree) | ||
{ | ||
var options = _lazyAnalyzerConfigSet | ||
.GetValue(CancellationToken.None).GetOptionsForSourcePath(tree.FilePath); |
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.
Any reason we shouldn't thread cancellation through the SyntaxTreeOptionsProvider?
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.
Oversight. I'll fix.
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.
Sorry, didn't fully understand the implications here -- now that I think about it, I think it's better not to do so, and the reason is because once you've supplied the provider to the compiler, there are a variety of operations which are simply uncancellable that will request the provider. I think it's best to leave it out because it incorrectly implies that the cancellation token is respected in the compiler when it won't be.
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.
there are a variety of operations which are simply uncancellable that will request the provider
What operations would be uncancellable?
I think it's best to leave it out because it incorrectly implies that the cancellation token is respected in the compiler when it won't be.
Cancellation is always advisory so the compiler is allowed to do so. My concern is if/when this becomes a perf issue then we will have to do more API evilness to deal with that.
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.
I'll address the cancellation concern in a separate pull request.
1eadb4a
to
c73239f
Compare
c73239f
to
0d1b7bb
Compare
src/Compilers/Core/Portable/Compilation/SyntaxTreeOptionsProvider.cs
Outdated
Show resolved
Hide resolved
The diagnostic configurations produced by AnalyzerConfig processing currently go into the SyntaxTree.DiagnosticOptions. This unfortunately has performance problems because any change to the diagnostic options may force all syntax trees to be replaced. This change moves the diagnostic options produced from AnalyzerConfigs to the CompilationOptions, which can be replaced in a Compilation without replacing SyntaxTrees.
0d1b7bb
to
a9899b1
Compare
…reeOptionsProvider
…t changing options If a Workspace has changes to .editorconfig files, that'll also cause changes to CompilationOptions. This excludes the changing SyntaxTreeOptionsProvider from something that the host has to deal with which maintains existing compatibility and also keeps things a bit simpler for callers.
…roviders around Even if we replace the CompilationOptions, we want to replace the SyntaxTreeOptionProvider so things are still consistent.
Testing for both recoverable and non-recoverables doesn't make sense anymore, and also removes a test that was asserting we carried data along if you replaced the root, but that's now entirely moot.
Reloading a project is now triggering work to happen because the CompilationOptions won't be identical after the reload: we'll have a new SyntaxTreeOptionsProvider which although would answer with the same values, won't have object identity in the way the tests would expect. These APIs aren't used in Visual Studio so I don't think it's a big deal.
src/Compilers/CSharp/Portable/Syntax/CSharpSyntaxTree.ParsedSyntaxTree.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs
Outdated
Show resolved
Hide resolved
Done review pass (commit 23) |
src/Compilers/CSharp/Portable/Syntax/CSharpSyntaxTree.ParsedSyntaxTree.cs
Outdated
Show resolved
Hide resolved
Any further movement on this? |
@chsienki yes, I have unresolved comments. |
@chsienki Yep I'll be picking this back up today. Had some other fun issues that took priority last week. |
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.
LGTM (commit 31)
For reasons that aren't entirely clear, when we create a preview of a code fix, we remove and re-add documents that are being changed when we produce the PreviewWorkspace. This process had an bug which meant that the file path of an .editorconfig got dropped, so the resultant .editorconfig document path was null. This later caused a crash if the diagnostic engine, when processing the PreviewWorkspace's new solution, tried asking for a Compilation, since the null path would get passed to AnalyzerConfig.Parse(), and it would throw. This was exposed by dotnet#45076; until then if you had a preview of just an .editorconfig file, nothing would actually be analyzed and so nothing asked for the Compilation. The crash is "fixed" by dotnet#44331 in that asking for a Compilation no longer results in a call to AnalyzerConfig.Parse(); you have to ask for a Compilation and then do something with a semantic model. By luck, that doesn't happen in the common repro, but more obscure things absolutely could still fail. This is being tested by the integration test being added in dotnet#46639. We don't really have a good unit tests here as far as I can tell, but even then a unit test really doesn't validate any of the end-to-end here. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1162464
No description provided.