-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
added ability to clear all diagnostics reproted from a IDiagnosticUpd… #33805
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,37 @@ private void RaiseDiagnosticsUpdated(object sender, DiagnosticsUpdatedArgs args) | |
}).CompletesAsyncOperation(eventToken); | ||
} | ||
|
||
private void RaiseDiagnosticsCleared(object sender) | ||
{ | ||
Contract.ThrowIfNull(sender); | ||
var source = (IDiagnosticUpdateSource)sender; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd move this to the caller and strongly type the parameter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure. |
||
|
||
var ev = _eventMap.GetEventHandlers<EventHandler<DiagnosticsUpdatedArgs>>(DiagnosticsUpdatedEventName); | ||
if (!RequireRunningEventTasks(source, ev)) | ||
{ | ||
return; | ||
} | ||
|
||
var eventToken = _listener.BeginAsyncOperation(DiagnosticsUpdatedEventName); | ||
_eventQueue.ScheduleTask(() => | ||
{ | ||
using (var pooledObject = SharedPools.Default<List<DiagnosticsUpdatedArgs>>().GetPooledObject()) | ||
{ | ||
var removed = pooledObject.Object; | ||
if (!ClearDiagnosticsFromDataMapFor(source, removed)) | ||
{ | ||
// there is no change, nothing to raise events for. | ||
return; | ||
} | ||
|
||
foreach (var args in removed) | ||
{ | ||
ev.RaiseEvent(handler => handler(sender, args)); | ||
} | ||
} | ||
}).CompletesAsyncOperation(eventToken); | ||
} | ||
|
||
private bool RequireRunningEventTasks( | ||
IDiagnosticUpdateSource source, EventMap.EventHandlerSet<EventHandler<DiagnosticsUpdatedArgs>> ev) | ||
{ | ||
|
@@ -150,12 +181,48 @@ private bool UpdateDataMap(IDiagnosticUpdateSource source, DiagnosticsUpdatedArg | |
} | ||
} | ||
|
||
private bool ClearDiagnosticsFromDataMapFor(IDiagnosticUpdateSource source, List<DiagnosticsUpdatedArgs> removed) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Wouldn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure. |
||
{ | ||
// we expect source who uses this ability to have small number of diagnostics. | ||
lock (_gate) | ||
{ | ||
Debug.Assert(_updateSources.Contains(source)); | ||
|
||
// 2 different workspaces (ex, PreviewWorkspaces) can return same Args.Id, we need to | ||
// distinguish them. so we separate diagnostics per workspace map. | ||
if (!_map.TryGetValue(source, out var workspaceMap)) | ||
{ | ||
return false; | ||
} | ||
|
||
foreach (var (workspace, map) in workspaceMap) | ||
{ | ||
foreach (var (id, data) in map) | ||
{ | ||
removed.Add(DiagnosticsUpdatedArgs.DiagnosticsRemoved(id, data.Workspace, solution: null, data.ProjectId, data.DocumentId)); | ||
} | ||
} | ||
|
||
// all diagnostics from the source is cleared | ||
_map.Remove(source); | ||
return true; | ||
} | ||
} | ||
|
||
private void OnDiagnosticsUpdated(object sender, DiagnosticsUpdatedArgs e) | ||
{ | ||
AssertIfNull(e.Diagnostics); | ||
|
||
// all events are serialized by async event handler | ||
RaiseDiagnosticsUpdated(sender, e); | ||
} | ||
|
||
private void OnCleared(object sender, EventArgs e) | ||
{ | ||
// all events are serialized by async event handler | ||
RaiseDiagnosticsCleared(sender); | ||
} | ||
|
||
public IEnumerable<DiagnosticData> GetDiagnostics( | ||
Workspace workspace, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken) | ||
{ | ||
|
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.
set
is an odd name for an event.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.. wait handle then?