Skip to content

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Aug 29, 2025

Will likely take #80141 over this.

This was needed back when we allowed loading Roslyn Feature Analyzers from the SDK. IN that case, we'd have the analyzer from VS and the analyzer from the SDK. Now we've moved to a model where we will always take the VS analyzer to prevent tearing.

Note: option values still always prefer editorconfig, but fallback to VS options if they are not present.

Build: https://devdiv.visualstudio.com/DevDiv/_build?definitionId=8972
PR: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/666447

namespace A
{
using System;
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the correct behavior. The test here is testing " 'usings' should be INSIDE the namespace, and it is an ERROR otherwise". So it was a bug this wasn't moving in in CodeCleanup.

Copy link
Member Author

Choose a reason for hiding this comment

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

Note: this differs from teh tests taht validate that nothing change when the option suggestions the change, but the severity is set to 'hidden'. in that case we do not make any change.

@CyrusNajmabadi CyrusNajmabadi changed the title Remove CompilationPair to see what breaks. Remove CompilationPair Sep 1, 2025
@CyrusNajmabadi CyrusNajmabadi changed the title Remove CompilationPair Remove CompilationPair abstraction in diagnostic analyzer subsystem. Sep 2, 2025
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review September 2, 2025 01:31
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner September 2, 2025 01:31
@CyrusNajmabadi
Copy link
Member Author

Will have to see if the validation is accurate. But this looks promising:

image

@@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis.Diagnostics;
internal sealed partial class DiagnosticAnalyzerService
{
/// <summary>
/// Cached data from a <see cref="ProjectState"/> to the <see cref="CompilationWithAnalyzersPair"/>s
/// Cached data from a <see cref="ProjectState"/> to the <see cref="CompilationWithAnalyzers"/>s
Copy link
Contributor

Choose a reason for hiding this comment

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

CompilationWithAnalyzers

nit: rename file

Copy link
Member Author

Choose a reason for hiding this comment

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

Can do in followup.

CreateCompilationWithAnalyzers(compilation, filteredHostAnalyzers, project.HostAnalyzerOptions, exceptionFilter));
return CreateCompilationWithAnalyzers(
compilation,
filteredHostAnalyzers.Concat(filteredProjectAnalyzers).Distinct(),
Copy link
Contributor

Choose a reason for hiding this comment

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

filteredHostAnalyzers.Concat(filteredProjectAnalyzers).Distinct(),

Trying to work my way through the WhereAsArray mental gymnastics above, and I'm probably wrong, but it seems like all that reduces to this parameter just being

analyzers.Where(a => !a.IsWorkspaceDiagnosticAnalyzer())

and not needing any of those intermediate calculations

Copy link
Member Author

Choose a reason for hiding this comment

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

yup. that seems to be true. Are you ok with that happening in a followup. My plan was to go over all this code and reduce complexity now that we only have one list of analyzers. Thanks! :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Definitely ok with any change related to this to be in a followup PR

projectBuilder.Add(analyzer);
}
}
var builder = ArrayBuilder<DiagnosticAnalyzer>.GetInstance();
Copy link
Contributor

Choose a reason for hiding this comment

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

ArrayBuilder.GetInstance();

nit: consider just using a PooledHashSet directly

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see, maybe that's a bad idea if the order matters

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. That part isn't clear to me. So i don't want to change that right now.

hostAnalyzerBuilder.RemoveRange(projectSuppressors);
hostAnalyzerBuilder.AddRange(projectSuppressors);
// We do not want to run SDK 'features' analyzers. We always defer to what is in VS for that.
if (ShouldRedirectAnalyzers(_project, reference))
Copy link
Contributor

Choose a reason for hiding this comment

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

if (ShouldRedirectAnalyzers(_project, reference))

nit: consider moving before GetAnalyzers call

Copy link
Member Author

Choose a reason for hiding this comment

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

sure. can def do in followup.

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

@CyrusNajmabadi
Copy link
Member Author

Discussing with Jason if this is the way we want to go.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as draft September 8, 2025 12:55
@jasonmalinowski
Copy link
Member

@CyrusNajmabadi I presume at this point we're taking the other one?

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.

4 participants