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

Remove diagnostic scaffolding for sending diagnostics events from HostDiagnosticUpdateSource. #72731

Merged
merged 13 commits into from
Mar 28, 2024

Conversation

CyrusNajmabadi
Copy link
Member

No description provided.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 26, 2024

public abstract Workspace Workspace { get; }

public event EventHandler<ImmutableArray<DiagnosticsUpdatedArgs>>? DiagnosticsUpdated;
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 was the member i was removing first. it was only referenced from tests, so it culd be safely removed. this then became a therad that removed more and more.


public event EventHandler<ImmutableArray<DiagnosticsUpdatedArgs>>? DiagnosticsUpdated;

public void RaiseDiagnosticsUpdated(ImmutableArray<DiagnosticsUpdatedArgs> args)
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 was hte method that invoked hte event. no more event, no more method.

using var argsBuilder = TemporaryArray<DiagnosticsUpdatedArgs>.Empty;
var analyzers = analyzerReference.GetAnalyzers(language);
AddArgsToClearAnalyzerDiagnostics(ref argsBuilder.AsRef(), analyzers, projectId);
RaiseDiagnosticsUpdated(argsBuilder.ToImmutableAndClear());
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 was a call to raise hte event. no more event, then no more method. once tehre's no more method, there's no need to do thingsl ike add arguments to builders anymore.

{
var newDiags = existing.Where(d => d.ProjectId != projectId).ToImmutableHashSet();
if (newDiags.Count < existing.Count &&
ImmutableInterlocked.TryUpdate(ref _analyzerHostDiagnosticsMap, analyzer, newDiags, existing))
Copy link
Member Author

Choose a reason for hiding this comment

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

similarly. nothing was ever reading this _analyzerHostDiagnosticsMap. removnig that pulled on more of these therads.

private static readonly object s_analyzerChangedErrorId = new();

private readonly VisualStudioWorkspaceImpl _workspace;
private readonly HostDiagnosticUpdateSource _updateSource;
Copy link
Member Author

Choose a reason for hiding this comment

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

since nothing was listening to the _updateSource anymore, there's no need for the AnalyerFileWatchService to send it any events.

Note: we may need to do work in LSP pull diags to pull on this type in case it has created an diags. If that's the case, then we're already in a broken state. We can see how important that scenario is, and trivially make that work again with LSP pull diags if needed.


lock (_gate)
{
_diagnosticMap.GetOrAdd(projectId, id => new HashSet<object>()).Add(key);
Copy link
Member Author

Choose a reason for hiding this comment

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

similarly, nothing ever read this map. removed and kept pulling the thread.

Dim hostDiagnosticUpdateSource = New HostDiagnosticUpdateSource(lazyWorkspace)

Dim eventHandler = New EventHandlers(file)
AddHandler hostDiagnosticUpdateSource.DiagnosticsUpdated, AddressOf eventHandler.DiagnosticAddedTest
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 was the only location that .DiagnosticsUpdated was referenced. removing this meant all the above code could be removed.

@CyrusNajmabadi CyrusNajmabadi changed the title WIP: Remove update Remove diagnostic scaffolding for sending diagnostics events from HostDiagnosticUpdateSource. Mar 26, 2024
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review March 26, 2024 05:13
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner March 26, 2024 05:13
Cyrus Najmabadi added 2 commits March 25, 2024 22:18
@CyrusNajmabadi
Copy link
Member Author

@mavasani @genlu ptal

private readonly VisualStudioWorkspaceImpl _workspace;
private readonly HostDiagnosticUpdateSource _updateSource;
private readonly IVsFileChangeEx _fileChangeService;
private readonly IVsFileChangeEx _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));
Copy link
Member

Choose a reason for hiding this comment

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

Ouch. This is not valid in a MEF part. Will this be removed soon or should I fix it after this change merges?

Copy link
Member Author

Choose a reason for hiding this comment

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

feel free to fix.

private readonly DiagnosticDescriptor _analyzerChangedRule = new(
id: IDEDiagnosticIds.AnalyzerChangedId,
title: ServicesVSResources.AnalyzerChangedOnDisk,
messageFormat: ServicesVSResources.The_analyzer_assembly_0_has_changed_Diagnostics_may_be_incorrect_until_Visual_Studio_is_restarted,
Copy link
Member

Choose a reason for hiding this comment

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

❓ Do we still get this message displayed in the IDE?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently (even without my PR) it will not. That said, there are two paths (beyond this pr) to move forward on:

  1. make it so that these diagnostics can proffered up so the user can see them.
  2. change analyzers so that reloading is fine. This is something we can support now, and @jasonmalinowski was going to make this work very soon anyways.

@CyrusNajmabadi
Copy link
Member Author

@mavasani ptal :)

using Microsoft.CodeAnalysis.Diagnostics;

namespace Microsoft.CodeAnalysis.Workspaces.ProjectSystem;

// TODO: see if we can get rid of this interface by appropriately rewriting HostDiagnosticUpdateSource to live at the workspaces layer.
internal interface IProjectSystemDiagnosticSource
{
void ClearAllDiagnosticsForProject(ProjectId projectId);
void ClearAnalyzerReferenceDiagnostics(AnalyzerFileReference fileReference, string language, ProjectId projectId);
void ClearDiagnosticsForProject(ProjectId projectId, object key);
DiagnosticData CreateAnalyzerLoadFailureDiagnostic(AnalyzerLoadFailureEventArgs e, string fullPath, ProjectId projectId, string language);
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this can be a utility helper method now and IProjectSystemDiagnosticSource interface can be completely removed.

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. I can work on that next

@CyrusNajmabadi CyrusNajmabadi merged commit 70c1734 into dotnet:main Mar 28, 2024
27 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the removeUpdate branch March 28, 2024 05:22
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Mar 28, 2024
@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants