Skip to content

Conversation

@CyrusNajmabadi
Copy link
Member

Followup to #78356.

Needed so we can access IDiagAnalyzerService in OOP. Currently one cannot as it attempts to access the Workspace of a document passed into it. We block WOrkspace access like for safety/clarity concerns (we don't want a stateless OOP api call to have access to the mutable workspace API).

This also cleans up some ugly initialization code IDiagAnalyzerService had.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner April 28, 2025 20:35
@ghost ghost added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 28, 2025
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class CSharpCodeCleanupService(ICodeFixService codeFixService, IDiagnosticAnalyzerService diagnosticAnalyzerService) : AbstractCodeCleanupService(codeFixService, diagnosticAnalyzerService)
internal sealed class CSharpCodeCleanupService(ICodeFixService codeFixService)
: AbstractCodeCleanupService(codeFixService)
Copy link
Member Author

Choose a reason for hiding this comment

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

most changes are just not passing the IDiagAnalzyerService along. INstead, code that needs it, requests it as a normal workspace service at the point they actually need it.


// When the workspace changes what context a document is in (when a user picks a different tfm to view the
// document in), kick off a refresh so that diagnostics properly update in the task list and editor.
workspace.RegisterDocumentActiveContextChangedHandler(args => RequestDiagnosticRefresh());
Copy link
Member Author

Choose a reason for hiding this comment

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

moved registration here, which is much cleaner than when we were originally creating the incremetnal analyzers.

=> _diagnosticsRefresher.RequestWorkspaceRefresh();

private DiagnosticIncrementalAnalyzer CreateIncrementalAnalyzer(Workspace workspace)
=> _map.GetValue(workspace, _createIncrementalAnalyzer);
Copy link
Member Author

Choose a reason for hiding this comment

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

move from deleted sibling file (which should be looked at).

private DiagnosticIncrementalAnalyzer CreateIncrementalAnalyzerCallback(Workspace workspace)
{
// subscribe to active context changed event for new workspace
_ = workspace.RegisterDocumentActiveContextChangedHandler(args => RequestDiagnosticRefresh());
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to constructor.

Copy link
Member

@dibarbet dibarbet left a comment

Choose a reason for hiding this comment

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

this seems reasonable. agree that it would be nice if the refresher was a workspace service too, but fine with leaving that out due to the EA restrictions

@CyrusNajmabadi CyrusNajmabadi merged commit b411efa into dotnet:main Apr 28, 2025
24 of 25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the analyzerWorkspaceService branch April 28, 2025 23:18
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 28, 2025
CyrusNajmabadi added a commit to CyrusNajmabadi/roslyn that referenced this pull request May 7, 2025
Followup to dotnet#78356.

Needed so we can access IDiagAnalyzerService in OOP. Currently one
cannot as it attempts to access the Workspace of a document passed into
it. We block WOrkspace access like for safety/clarity concerns (we don't
want a stateless OOP api call to have access to the mutable workspace
API).

This also cleans up some ugly initialization code IDiagAnalyzerService
had.
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead VSCode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants