Skip to content
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

Merged

Conversation

agocke
Copy link
Member

@agocke agocke commented May 17, 2020

No description provided.

@agocke agocke force-pushed the compilationoptions-analyzerconfig branch 4 times, most recently from fcf3b64 to 314275e Compare May 17, 2020 22:31
Copy link
Member

@jasonmalinowski jasonmalinowski left a 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,
Copy link
Member

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.

Copy link
Member Author

@agocke agocke May 19, 2020

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.

public override bool? IsGenerated(SyntaxTree tree)
{
var options = _lazyAnalyzerConfigSet
.GetValue(CancellationToken.None).GetOptionsForSourcePath(tree.FilePath);
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oversight. I'll fix.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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.

@agocke agocke force-pushed the compilationoptions-analyzerconfig branch 2 times, most recently from 1eadb4a to c73239f Compare May 20, 2020 00:14
@agocke agocke marked this pull request as ready for review May 20, 2020 00:15
@agocke agocke requested review from a team as code owners May 20, 2020 00:15
@agocke agocke marked this pull request as draft May 20, 2020 00:15
@agocke agocke closed this May 20, 2020
@agocke agocke reopened this May 20, 2020
@agocke agocke marked this pull request as ready for review May 20, 2020 00:26
@agocke agocke marked this pull request as draft May 20, 2020 00:26
@agocke agocke force-pushed the compilationoptions-analyzerconfig branch from c73239f to 0d1b7bb Compare May 20, 2020 00:27
@agocke agocke changed the title WIP Move C# editorconfig diagnostic support API to CompilationOptions, instead of SyntaxTree Jun 16, 2020
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.
@agocke agocke force-pushed the compilationoptions-analyzerconfig branch from 0d1b7bb to a9899b1 Compare June 16, 2020 22:17
…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.
@333fred
Copy link
Member

333fred commented Jul 24, 2020

Done review pass (commit 23)

@chsienki
Copy link
Contributor

chsienki commented Aug 4, 2020

Any further movement on this?

@333fred
Copy link
Member

333fred commented Aug 5, 2020

@chsienki yes, I have unresolved comments.

@jasonmalinowski
Copy link
Member

@chsienki Yep I'll be picking this back up today. Had some other fun issues that took priority last week.

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 31)

jasonmalinowski added a commit to jasonmalinowski/roslyn that referenced this pull request Aug 7, 2020
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
@jasonmalinowski jasonmalinowski merged commit 45f2aed into dotnet:master Aug 8, 2020
@ghost ghost added this to the Next milestone Aug 8, 2020
@RikkiGibson RikkiGibson modified the milestones: Next, 16.8.P2 Aug 11, 2020
@agocke agocke deleted the compilationoptions-analyzerconfig branch August 25, 2020 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants